]> git.gag.com Git - fw/altos/blob - ao-tools/ao-view/aoview_label.c
altoslib: Flush settings restoration commands after accel cal
[fw/altos] / ao-tools / ao-view / aoview_label.c
1 /*
2  * Copyright © 2009 Keith Packard <keithp@keithp.com>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program; if not, write to the Free Software Foundation, Inc.,
16  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
17  */
18
19 #include "aoview.h"
20
21 static struct {
22         char            *name;
23         char            *initial_value;
24         GtkLabel        *widget;
25 } label_widgets[] = {
26         { "height_label", "Height (m)", NULL },
27         { "state_label", "State", NULL },
28         { "rssi_label", "RSSI (dBm)", NULL },
29         { "speed_label", "Speed (m/s)", NULL },
30         { "height_value", "0", NULL },
31         { "state_value", "pad", NULL },
32         { "rssi_value", "-50", NULL },
33         { "speed_value", "0", NULL },
34 };
35
36 static void
37 aoview_label_assign(GtkLabel *widget, char *value)
38 {
39         char    *markup;
40
41         markup = g_markup_printf_escaped("<span font_weight=\"bold\" size=\"xx-large\">%s</span>", value);
42         gtk_label_set_markup(widget, markup);
43         g_free(markup);
44 }
45
46 void
47 aoview_label_show(struct aostate *state)
48 {
49         char    line[1024];
50         sprintf(line, "%d", state->height);
51         aoview_label_assign(label_widgets[4].widget, line);
52
53         aoview_label_assign(label_widgets[5].widget, state->data.state);
54
55         sprintf(line, "%d", state->data.rssi);
56         aoview_label_assign(label_widgets[6].widget, line);
57
58         if (state->ascent)
59                 sprintf(line, "%6.0f", fabs(state->speed));
60         else
61                 sprintf(line, "%6.0f", fabs(state->baro_speed));
62         aoview_label_assign(label_widgets[7].widget, line);
63 }
64
65 void
66 aoview_label_init(GladeXML *xml)
67 {
68         int i;
69         for (i = 0; i < sizeof(label_widgets)/sizeof(label_widgets[0]); i++) {
70                 label_widgets[i].widget = GTK_LABEL(glade_xml_get_widget(xml, label_widgets[i].name));
71                 aoview_label_assign(label_widgets[i].widget, label_widgets[i].initial_value);
72                 assert(label_widgets[i].widget);
73         }
74 }