battery: implement "path" option for batteries with non-standard paths
This commit is contained in:
parent
40012ed7c6
commit
3471ff39f8
@ -209,6 +209,7 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
cfg_opt_t battery_opts[] = {
|
||||
CFG_STR("format", "%status %percentage %remaining", CFGF_NONE),
|
||||
CFG_STR("path", "/sys/class/power_supply/BAT%d/uevent", CFGF_NONE),
|
||||
CFG_BOOL("last_full_capacity", false, CFGF_NONE),
|
||||
CFG_END()
|
||||
};
|
||||
@ -371,7 +372,7 @@ int main(int argc, char *argv[]) {
|
||||
print_eth_info(title, cfg_getstr(sec, "format_up"), cfg_getstr(sec, "format_down"));
|
||||
|
||||
CASE_SEC_TITLE("battery")
|
||||
print_battery_info(atoi(title), cfg_getstr(sec, "format"), cfg_getbool(sec, "last_full_capacity"));
|
||||
print_battery_info(atoi(title), cfg_getstr(sec, "path"), cfg_getstr(sec, "format"), cfg_getbool(sec, "last_full_capacity"));
|
||||
|
||||
CASE_SEC_TITLE("run_watch")
|
||||
print_run_watch(title, cfg_getstr(sec, "pidfile"), cfg_getstr(sec, "format"));
|
||||
|
@ -64,7 +64,7 @@ char *auto_detect_format();
|
||||
|
||||
void print_ipv6_info(const char *format_up, const char *format_down);
|
||||
void print_disk_info(const char *path, const char *format);
|
||||
void print_battery_info(int number, const char *format, bool last_full_capacity);
|
||||
void print_battery_info(int number, const char *path, const char *format, bool last_full_capacity);
|
||||
void print_time(const char *format, struct tm *current_tm);
|
||||
void print_ddate(const char *format, struct tm *current_tm);
|
||||
const char *get_ip_addr();
|
||||
|
@ -75,6 +75,7 @@ ethernet eth0 {
|
||||
|
||||
battery 0 {
|
||||
format = "%status %percentage %remaining"
|
||||
path = "/sys/class/power_supply/BAT%d/uevent"
|
||||
}
|
||||
|
||||
run_watch DHCP {
|
||||
@ -193,6 +194,10 @@ your battery is at 23% when fully charged because it’s old. In general, I
|
||||
want to see it this way, because it tells me how worn off my battery is.),
|
||||
just specify +last_full_capacity = true+.
|
||||
|
||||
If your battery is represented in a non-standard path in /sys, be sure to
|
||||
modify the "path" property accordingly. The first occurence of %d gets replaced
|
||||
with the battery number, but you can just hard-code a path as well.
|
||||
|
||||
*Example order*: +battery 0+
|
||||
|
||||
*Example format*: +%status %remaining+
|
||||
|
@ -17,7 +17,7 @@
|
||||
* worn off your battery is.
|
||||
*
|
||||
*/
|
||||
void print_battery_info(int number, const char *format, bool last_full_capacity) {
|
||||
void print_battery_info(int number, const char *path, const char *format, bool last_full_capacity) {
|
||||
time_t empty_time;
|
||||
struct tm *empty_tm;
|
||||
char buf[1024];
|
||||
@ -38,7 +38,7 @@ void print_battery_info(int number, const char *format, bool last_full_capacity)
|
||||
|
||||
#if defined(LINUX)
|
||||
static char batpath[512];
|
||||
sprintf(batpath, "/sys/class/power_supply/BAT%d/uevent", number);
|
||||
sprintf(batpath, path, number);
|
||||
if (!slurp(batpath, buf, sizeof(buf))) {
|
||||
printf("No battery");
|
||||
return;
|
||||
|
Loading…
Reference in New Issue
Block a user