--- a/status-bat/bat.c Thu Oct 23 19:32:57 2014 +0400
+++ b/status-bat/bat.c Thu Oct 23 20:49:34 2014 +0400
@@ -111,16 +111,19 @@
fds[0].fd = mon_fd;
fds[0].events = POLLIN;
#endif
+ char filename[PATH_MAX+1];
+ snprintf(filename,PATH_MAX,"/sys/class/power_supply/%s/energy_now",argv[1]);
+ struct stat st;
+ int energy = 0==stat(filename, &st);
while (1) {
- char filename[PATH_MAX+1];
- snprintf(filename,PATH_MAX,"/sys/class/power_supply/%s/charge_now",argv[1]);
+ snprintf(filename,PATH_MAX,"/sys/class/power_supply/%s/%s_now",argv[1], energy ? "energy" : "charge");
int charge_now = catint(filename);
- snprintf(filename,PATH_MAX,"/sys/class/power_supply/%s/current_now",argv[1]);
+ snprintf(filename,PATH_MAX,"/sys/class/power_supply/%s/%s_now",argv[1], energy ? "power" : "current");
int current_now = catint(filename);
- snprintf(filename,PATH_MAX,"/sys/class/power_supply/%s/charge_full",argv[1]);
+ snprintf(filename,PATH_MAX,"/sys/class/power_supply/%s/%s_full",argv[1], energy ? "energy" : "charge");
int charge_full = catint(filename);
snprintf(filename,PATH_MAX,"/sys/class/power_supply/%s/status",argv[1]);
@@ -133,13 +136,13 @@
remtimes_color = color_none;
if (!strcmp(status,"Charging")) {
if (current_now != 0)
- remtime = ((charge_full-charge_now) * 60) / current_now;
+ remtime = (charge_full-charge_now) / (current_now/60);
arrow = "↑";
arrow_color = color_orange;
}
else if (!strcmp(status,"Discharging")) {
if (current_now != 0)
- remtime = (charge_now * 60) / current_now;
+ remtime = charge_now / (current_now/60);
arrow = "↓";
arrow_color = color_none;
remtimes_color = color(20,120,0,remtime);
@@ -153,7 +156,7 @@
// eights[charge_now*8/charge_full], charge_now*100/charge_full,status,remtimes);
- int percent = charge_now*100/charge_full;
+ int percent = charge_now/(charge_full/100);
eights_color = percent_color = color(15,40,0,percent);
printf("%s%s%s ",eights_color,eights[charge_now*8/charge_full],color_stop);
printf("%s%d%%%s ",percent_color,percent,color_stop);