xbattmon

simple battery monitor for X
git clone git://git.2f30.org/xbattmon
Log | Files | Refs | README | LICENSE

commit 639e3d95d0f9dfe8b102d8d9d2de40d893eeab1a
parent 7714223ae7452e386f82af0312c6ba415ea73a40
Author: sin <sin@2f30.org>
Date:   Sat,  8 Jul 2017 09:45:42 +0100

Add support for multiple batteries

Diffstat:
Mconfig.linux.mk | 5++++-
Mxbattmon.c | 22+++++++++++++++++++++-
2 files changed, 25 insertions(+), 2 deletions(-)

diff --git a/config.linux.mk b/config.linux.mk @@ -1,6 +1,9 @@ PREFIX = /usr/local MANPREFIX = $(PREFIX)/share/man -CPPFLAGS = -DVERSION=\"${VERSION}\" -DPATH_BAT0_CAP=\"/sys/class/power_supply/BAT0/capacity\" \ +# If you have a second battery, specify PATH_BAT1_CAP too. +CPPFLAGS = \ + -DVERSION=\"${VERSION}\" \ + -DPATH_BAT0_CAP=\"/sys/class/power_supply/BAT0/capacity\" \ -DPATH_AC_ONLINE=\"/sys/class/power_supply/AC/online\" LDLIBS = -lX11 diff --git a/xbattmon.c b/xbattmon.c @@ -269,14 +269,34 @@ void pollbat(void) { FILE *fp; + int bat0cap, bat1cap = -1; /* secondary battery is optional */ int acon; fp = fopen(PATH_BAT0_CAP, "r"); if (!fp) err(1, "fopen %s", PATH_BAT0_CAP); - fscanf(fp, "%d", &batcap); + fscanf(fp, "%d", &bat0cap); fclose(fp); + if (bat0cap > 100) + bat0cap = 100; + +#ifdef PATH_BAT1_CAP + fp = fopen(PATH_BAT1_CAP, "r"); + if (!fp) + err(1, "fopen %s", PATH_BAT1_CAP); + fscanf(fp, "%d", &bat1cap); + fclose(fp); + + if (bat1cap > 100) + bat1cap = 100; +#endif + + if (bat1cap != -1) + batcap = 100 * (bat0cap + bat1cap) / 200; + else + batcap = bat0cap; + if (batcap > maxcap) batcap = maxcap;