lol, battery_perc() is even simpler, fuck this shit :D
This commit is contained in:
parent
2d1bbf0d35
commit
74b6e340f2
29
slstatus.c
29
slstatus.c
|
@ -98,36 +98,19 @@ smprintf(const char *fmt, ...)
|
||||||
static char *
|
static char *
|
||||||
battery_perc(const char *battery)
|
battery_perc(const char *battery)
|
||||||
{
|
{
|
||||||
int now, full;
|
int perc;
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
|
|
||||||
ccat(3, "/sys/class/power_supply/", battery, "/energy_now");
|
ccat(3, "/sys/class/power_supply/", battery, "/capacity");
|
||||||
fp = fopen(concat, "r");
|
fp = fopen(concat, "r");
|
||||||
if (fp == NULL) {
|
if (fp == NULL) {
|
||||||
ccat(4, "/sys/class/power_supply/", battery, "/charge_now");
|
warn("Error opening battery file: %s", concat);
|
||||||
fp = fopen(concat, "r");
|
return smprintf(UNKNOWN_STR);
|
||||||
if (fp == NULL) {
|
|
||||||
warn("Error opening battery file: %s", concat);
|
|
||||||
return smprintf(UNKNOWN_STR);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
fscanf(fp, "%i", &now);
|
fscanf(fp, "%i", &perc);
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
|
|
||||||
ccat(3, "/sys/class/power_supply/", battery, "/energy_full");
|
return smprintf("%d%%", perc);
|
||||||
fp = fopen(concat, "r");
|
|
||||||
if (fp == NULL) {
|
|
||||||
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);
|
|
||||||
|
|
||||||
return smprintf("%d%%", now / (full / 100));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *
|
static char *
|
||||||
|
|
Loading…
Reference in New Issue