summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron Marcher <info@nulltime.net>2016-09-13 20:54:45 +0200
committerAaron Marcher (drkhsh) <info@nulltime.net>2016-09-13 20:54:45 +0200
commit2d1bbf0d35f096803a96afbc8ae89a057e646d9f (patch)
treed26b2328aa576611182a08458c8dadb8f6f4d276
parent60df4f0f05e261d2787b9512cea262248ebaf166 (diff)
simplified battery_perc() a lot and removed useless options from config.def.h
-rw-r--r--config.def.h5
-rw-r--r--slstatus.c30
2 files changed, 16 insertions, 19 deletions
diff --git a/config.def.h b/config.def.h
index b105869..8cf8e56 100644
--- a/config.def.h
+++ b/config.def.h
@@ -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
diff --git a/slstatus.c b/slstatus.c
index 991334a..bf3c826 100644
--- a/slstatus.c
+++ b/slstatus.c
@@ -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 *