]> git.scottworley.com Git - batteryviewer/commitdiff
Put filenames in State
authorScott Worley <scottworley@scottworley.com>
Fri, 24 Feb 2023 02:33:46 +0000 (18:33 -0800)
committerScott Worley <scottworley@scottworley.com>
Fri, 24 Feb 2023 02:33:46 +0000 (18:33 -0800)
batteryviewer.c

index 1c38b3cca8527a36052023be1d85a54c5863c453..540db8e7c21c024ab0dabde05d6e5236eaa16c20 100644 (file)
@@ -6,10 +6,9 @@
 #include <stdio.h>
 #include <stdlib.h>
 
 #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 {
 struct State {
+  char *voltage_filename;
+  char *current_filename;
   BVChart *voltage;
   BVChart *current;
 };
   BVChart *voltage;
   BVChart *current;
 };
@@ -42,9 +41,9 @@ static float fatof(const char *filename) {
   return val;
 }
 
   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;
 }
 
   return TRUE;
 }
 
@@ -80,7 +79,10 @@ static void activate(GtkApplication *app, gpointer user_data) {
 }
 
 int main(int argc, char **argv) {
 }
 
 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);
 
   GtkApplication *app = gtk_application_new("com.scottworley.batteryviewer",
                                             G_APPLICATION_DEFAULT_FLAGS);