simplified battery_perc() a lot and removed useless options from config.def.h
authorAaron Marcher <info@nulltime.net>
Tue, 13 Sep 2016 18:54:45 +0000 (20:54 +0200)
committerAaron Marcher (drkhsh) <info@nulltime.net>
Tue, 13 Sep 2016 18:54:45 +0000 (20:54 +0200)
config.def.h
slstatus.c

index b10586912e5347a07b9d12139e1ed9d482a5c850..8cf8e56a88905fb6777ec902b8b37b2fab3323c5 100644 (file)
@@ -3,11 +3,6 @@
 /* alsa sound */
 #define ALSA_CHANNEL    "Master"
 
-/* battery */
-#define BATTERY_PATH    "/sys/class/power_supply/"
-#define BATTERY_NOW     "energy_now"
-#define BATTERY_FULL    "energy_full_design"
-
 /* how often to update the statusbar (min value == 1) */
 #define UPDATE_INTERVAL 1
 
index 991334af02900cd503cb2d345344b98c16f55e7a..bf3c82685974d32090154ccdd707dcf782c2bc6f 100644 (file)
@@ -98,34 +98,36 @@ smprintf(const char *fmt, ...)
 static char *
 battery_perc(const char *battery)
 {
-       int now, full, perc;
+       int now, full;
        FILE *fp;
 
-       ccat(4, BATTERY_PATH, battery, "/", BATTERY_NOW);
-
+       ccat(3, "/sys/class/power_supply/", battery, "/energy_now");
        fp = fopen(concat, "r");
        if (fp == NULL) {
-               warn("Error opening battery file: %s", concat);
-               return smprintf(UNKNOWN_STR);
+               ccat(4, "/sys/class/power_supply/", battery, "/charge_now");
+               fp = fopen(concat, "r");
+               if (fp == NULL) {
+                       warn("Error opening battery file: %s", concat);
+                       return smprintf(UNKNOWN_STR);
+               }
        }
-
        fscanf(fp, "%i", &now);
        fclose(fp);
 
-       ccat(4, BATTERY_PATH, battery, "/", BATTERY_FULL);
-
+       ccat(3, "/sys/class/power_supply/", battery, "/energy_full");
        fp = fopen(concat, "r");
        if (fp == NULL) {
-               warn("Error opening battery file: %s", concat);
-               return smprintf(UNKNOWN_STR);
+               ccat(4, "/sys/class/power_supply/", battery, "/charge_full");
+               fp = fopen(concat, "r");
+               if (fp == NULL) {
+                       warn("Error opening battery file: %s", concat);
+                       return smprintf(UNKNOWN_STR);
+               }
        }
-
        fscanf(fp, "%i", &full);
        fclose(fp);
 
-       perc = now / (full / 100);
-
-       return smprintf("%d%%", perc);
+       return smprintf("%d%%", now / (full / 100));
 }
 
 static char *