Xinqi Bao's Git
1 /* See LICENSE file for copyright and license details. */
9 battery_perc(const char *bat
)
14 snprintf(path
, sizeof(path
), "%s%s%s", "/sys/class/power_supply/", bat
, "/capacity");
15 return (pscanf(path
, "%i", &perc
) == 1) ?
16 bprintf("%d", perc
) : NULL
;
20 battery_power(const char *bat
)
25 snprintf(path
, sizeof(path
), "%s%s%s", "/sys/class/power_supply/", bat
, "/power_now");
26 return (pscanf(path
, "%i", &watts
) == 1) ?
27 bprintf("%d", (watts
+ 500000) / 1000000) : NULL
;
31 battery_state(const char *bat
)
38 { "Discharging", "-" },
43 char path
[PATH_MAX
], state
[12];
45 snprintf(path
, sizeof(path
), "%s%s%s", "/sys/class/power_supply/", bat
, "/status");
46 if (pscanf(path
, "%12s", state
) != 1) {
50 for (i
= 0; i
< LEN(map
); i
++) {
51 if (!strcmp(map
[i
].state
, state
)) {
55 return (i
== LEN(map
)) ? "?" : map
[i
].symbol
;