Xinqi Bao's Git
1 /* See LICENSE file for copyright and license details. */
10 battery_perc(const char *bat
)
15 snprintf(path
, sizeof(path
), "%s%s%s", "/sys/class/power_supply/", bat
, "/capacity");
16 return (pscanf(path
, "%i", &perc
) == 1) ?
17 bprintf("%d", perc
) : NULL
;
21 battery_power(const char *bat
)
26 snprintf(path
, sizeof(path
), "%s%s%s", "/sys/class/power_supply/", bat
, "/power_now");
27 return (pscanf(path
, "%i", &watts
) == 1) ?
28 bprintf("%d", (watts
+ 500000) / 1000000) : NULL
;
32 battery_state(const char *bat
)
39 { "Discharging", "-" },
44 char path
[PATH_MAX
], state
[12];
46 snprintf(path
, sizeof(path
), "%s%s%s", "/sys/class/power_supply/", bat
, "/status");
47 if (pscanf(path
, "%12s", state
) != 1) {
51 for (i
= 0; i
< LEN(map
); i
++) {
52 if (!strcmp(map
[i
].state
, state
)) {
56 return (i
== LEN(map
)) ? "?" : map
[i
].symbol
;