simplified battery_perc() a lot and removed useless options from config.def.h
This commit is contained in:
parent
60df4f0f05
commit
2d1bbf0d35
2 changed files with 16 additions and 19 deletions
|
@ -3,11 +3,6 @@
|
||||||
/* alsa sound */
|
/* alsa sound */
|
||||||
#define ALSA_CHANNEL "Master"
|
#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) */
|
/* how often to update the statusbar (min value == 1) */
|
||||||
#define UPDATE_INTERVAL 1
|
#define UPDATE_INTERVAL 1
|
||||||
|
|
||||||
|
|
22
slstatus.c
22
slstatus.c
|
@ -98,34 +98,36 @@ smprintf(const char *fmt, ...)
|
||||||
static char *
|
static char *
|
||||||
battery_perc(const char *battery)
|
battery_perc(const char *battery)
|
||||||
{
|
{
|
||||||
int now, full, perc;
|
int now, full;
|
||||||
FILE *fp;
|
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) {
|
||||||
|
ccat(4, "/sys/class/power_supply/", battery, "/charge_now");
|
||||||
fp = fopen(concat, "r");
|
fp = fopen(concat, "r");
|
||||||
if (fp == NULL) {
|
if (fp == NULL) {
|
||||||
warn("Error opening battery file: %s", concat);
|
warn("Error opening battery file: %s", concat);
|
||||||
return smprintf(UNKNOWN_STR);
|
return smprintf(UNKNOWN_STR);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
fscanf(fp, "%i", &now);
|
fscanf(fp, "%i", &now);
|
||||||
fclose(fp);
|
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) {
|
||||||
|
ccat(4, "/sys/class/power_supply/", battery, "/charge_full");
|
||||||
fp = fopen(concat, "r");
|
fp = fopen(concat, "r");
|
||||||
if (fp == NULL) {
|
if (fp == NULL) {
|
||||||
warn("Error opening battery file: %s", concat);
|
warn("Error opening battery file: %s", concat);
|
||||||
return smprintf(UNKNOWN_STR);
|
return smprintf(UNKNOWN_STR);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
fscanf(fp, "%i", &full);
|
fscanf(fp, "%i", &full);
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
|
|
||||||
perc = now / (full / 100);
|
return smprintf("%d%%", now / (full / 100));
|
||||||
|
|
||||||
return smprintf("%d%%", perc);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *
|
static char *
|
||||||
|
|
Loading…
Reference in a new issue