X-Git-Url: https://git.xinqibao.xyz/slstatus.git/blobdiff_plain/41deabf2ec1ad5f10851421cfbaf17023e7de05f..fc8b6f81a54810faa844ea21d08ef47f95b8f4e0:/components/battery.c diff --git a/components/battery.c b/components/battery.c index 327d576..4c6b4f5 100644 --- a/components/battery.c +++ b/components/battery.c @@ -16,20 +16,7 @@ snprintf(path, sizeof(path), "%s%s%s", "/sys/class/power_supply/", bat, "/capacity"); - return (pscanf(path, "%i", &perc) == 1) ? - bprintf("%d", perc) : NULL; - } - - const char * - battery_power(const char *bat) - { - int watts; - char path[PATH_MAX]; - - snprintf(path, sizeof(path), "%s%s%s", "/sys/class/power_supply/", - bat, "/power_now"); - return (pscanf(path, "%i", &watts) == 1) ? - bprintf("%d", (watts + 500000) / 1000000) : NULL; + return (pscanf(path, "%i", &perc) == 1) ? bprintf("%d", perc) : NULL; } const char * @@ -41,8 +28,6 @@ } map[] = { { "Charging", "+" }, { "Discharging", "-" }, - { "Full", "=" }, - { "Unknown", "/" }, }; size_t i; char path[PATH_MAX], state[12]; @@ -67,11 +52,13 @@ #include const char * - battery_perc(const char *null) + battery_perc(const char *bat) { struct apm_power_info apm_info; int fd; + UNUSED(bat); /* no way to specify battery on OpenBSD */ + fd = open("/dev/apm", O_RDONLY); if (fd < 0) { fprintf(stderr, "open '/dev/apm': %s\n", strerror(errno)); @@ -101,9 +88,10 @@ } map[] = { { APM_AC_ON, "+" }, { APM_AC_OFF, "-" }, - { APM_AC_UNKNOWN, "/" }, }; + UNUSED(bat); /* no way to specify battery on OpenBSD */ + fd = open("/dev/apm", O_RDONLY); if (fd < 0) { fprintf(stderr, "open '/dev/apm': %s\n", strerror(errno));