Xinqi Bao's Git
1 /* See LICENSE file for copyright and license details. */
8 #include "../../util.h"
11 battery_perc(const char *bat
)
16 snprintf(path
, sizeof(path
), "%s%s%s", "/sys/class/power_supply/", bat
, "/capacity");
17 return (pscanf(path
, "%i", &perc
) == 1) ?
18 bprintf("%d", perc
) : NULL
;
22 battery_power(const char *bat
)
27 snprintf(path
, sizeof(path
), "%s%s%s", "/sys/class/power_supply/", bat
, "/power_now");
28 return (pscanf(path
, "%i", &watts
) == 1) ?
29 bprintf("%d", (watts
+ 500000) / 1000000) : NULL
;
33 battery_state(const char *bat
)
40 { "Discharging", "-" },
45 char path
[PATH_MAX
], state
[12];
47 snprintf(path
, sizeof(path
), "%s%s%s", "/sys/class/power_supply/", bat
, "/status");
48 if (pscanf(path
, "%12s", state
) != 1) {
52 for (i
= 0; i
< LEN(map
); i
++) {
53 if (!strcmp(map
[i
].state
, state
)) {
57 return (i
== LEN(map
)) ? "?" : map
[i
].symbol
;