X-Git-Url: https://git.xinqibao.xyz/slstatus.git/blobdiff_plain/f170028527bdccead9a99797b45011d5e76100f1..74891945d897530b30c2c29844808d63bff625b7:/components/battery.c diff --git a/components/battery.c b/components/battery.c index c7c402a..90e8590 100644 --- a/components/battery.c +++ b/components/battery.c @@ -16,13 +16,13 @@ snprintf(path, sizeof(path), "%s%s%s", "/sys/class/power_supply/", bat, "/capacity"); - return (pscanf(path, "%i", &perc) == 1) ? bprintf("%d", perc) : NULL; + return (pscanf(path, "%d", &perc) == 1) ? bprintf("%d", perc) : NULL; } const char * battery_state(const char *bat) { - struct { + static struct { char *state; char *symbol; } map[] = { @@ -62,12 +62,12 @@ if (!strcmp(state, "Discharging")) { snprintf(path, sizeof(path), "%s%s%s", "/sys/class/power_supply/", bat, "/charge_now"); - if (pscanf(path, "%i", &charge_now) != 1) { + if (pscanf(path, "%d", &charge_now) != 1) { return NULL; } snprintf(path, sizeof(path), "%s%s%s", "/sys/class/power_supply/", bat, "/current_now"); - if (pscanf(path, "%i", ¤t_now) != 1) { + if (pscanf(path, "%d", ¤t_now) != 1) { return NULL; } @@ -121,8 +121,6 @@ const char * battery_state(const char *unused) { - struct apm_power_info apm_info; - size_t i; struct { unsigned int state; char *symbol; @@ -130,6 +128,8 @@ { APM_AC_ON, "+" }, { APM_AC_OFF, "-" }, }; + struct apm_power_info apm_info; + size_t i; if (load_apm_power_info(&apm_info)) { for (i = 0; i < LEN(map); i++) {