#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;
};
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;
}
}
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);