]> git.scottworley.com Git - batteryviewer/blob - batteryviewer.c
Call collect_data() regularly
[batteryviewer] / batteryviewer.c
1 #include "chart.h"
2 #include <gtk/gtk.h>
3
4 struct State {
5 BVChart *voltage;
6 BVChart *current;
7 };
8
9 static gboolean collect_data(struct State *state __attribute__((unused))) {
10 return TRUE;
11 }
12
13 static void activate(GtkApplication *app, gpointer user_data) {
14
15 GtkWidget *window = gtk_application_window_new(app);
16 gtk_window_set_title(GTK_WINDOW(window), "BatteryViewer");
17 gtk_window_set_default_size(GTK_WINDOW(window), 200, 200);
18
19 GtkWidget *box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 1);
20 gtk_container_add(GTK_CONTAINER(window), box);
21
22 struct State *state = (struct State *)user_data;
23 state->voltage = BV_CHART(bv_chart_new());
24 bv_chart_add_point(state->voltage, 0.0, 0.0);
25 bv_chart_add_point(state->voltage, 1.0, 1.0);
26 bv_chart_add_point(state->voltage, 3.0, 2.0);
27 gboolean expand = TRUE;
28 gboolean fill = TRUE;
29 guint padding = 0;
30 gtk_box_pack_start(GTK_BOX(box), GTK_WIDGET(state->voltage), expand, fill,
31 padding);
32
33 state->current = BV_CHART(bv_chart_new());
34 bv_chart_add_point(state->current, 0.0, 1.0);
35 bv_chart_add_point(state->current, 1.0, 0.0);
36 gtk_box_pack_end(GTK_BOX(box), GTK_WIDGET(state->current), expand, fill,
37 padding);
38
39 gtk_widget_show_all(window);
40
41 g_timeout_add_seconds(1, (GSourceFunc)collect_data, user_data);
42 }
43
44 int main(int argc, char **argv) {
45 struct State state;
46
47 GtkApplication *app = gtk_application_new("com.scottworley.batteryviewer",
48 G_APPLICATION_DEFAULT_FLAGS);
49 g_signal_connect(app, "activate", G_CALLBACK(activate), &state);
50 int status = g_application_run(G_APPLICATION(app), argc, argv);
51 g_object_unref(app);
52
53 return status;
54 }