]> git.scottworley.com Git - batteryviewer/blobdiff - batteryviewer.c
Put filenames in State
[batteryviewer] / batteryviewer.c
index 1c38b3cca8527a36052023be1d85a54c5863c453..540db8e7c21c024ab0dabde05d6e5236eaa16c20 100644 (file)
@@ -6,10 +6,9 @@
 #include <stdio.h>
 #include <stdlib.h>
 
-const char voltage_filename[] = "/sys/class/power_supply/BAT0/voltage_now";
-const char current_filename[] = "/sys/class/power_supply/BAT0/current_now";
-
 struct State {
+  char *voltage_filename;
+  char *current_filename;
   BVChart *voltage;
   BVChart *current;
 };
@@ -42,9 +41,9 @@ static float fatof(const char *filename) {
   return val;
 }
 
-static gboolean collect_data(struct State *state __attribute__((unused))) {
-  fprintf(stderr, "Voltage: %f, current: %f\n", fatof(voltage_filename),
-          fatof(current_filename));
+static gboolean collect_data(struct State *state) {
+  fprintf(stderr, "Voltage: %f, current: %f\n", fatof(state->voltage_filename),
+          fatof(state->current_filename));
   return TRUE;
 }
 
@@ -80,7 +79,10 @@ static void activate(GtkApplication *app, gpointer user_data) {
 }
 
 int main(int argc, char **argv) {
-  struct State state;
+  struct State state = {
+      .voltage_filename = "/sys/class/power_supply/BAT0/voltage_now",
+      .current_filename = "/sys/class/power_supply/BAT0/current_now",
+  };
 
   GtkApplication *app = gtk_application_new("com.scottworley.batteryviewer",
                                             G_APPLICATION_DEFAULT_FLAGS);