tcalculate remaining battery time on linux - spoon - [fork] customized build of… | |
git clone git://src.adamsgaard.dk/spoon | |
Log | |
Files | |
Refs | |
LICENSE | |
--- | |
commit 7365d31d3c34ce9d6ae191a4e38a9817199cf22c | |
parent 568c3949f6922f2a250c0bf108ae6afedae319a9 | |
Author: Anders Damsgaard <[email protected]> | |
Date: Sat, 2 Apr 2022 16:35:46 +0200 | |
calculate remaining battery time on linux | |
Diffstat: | |
M batt.c | 20 +++++++++++++++++--- | |
M config.h | 2 +- | |
M types.h | 2 ++ | |
3 files changed, 20 insertions(+), 4 deletions(-) | |
--- | |
diff --git a/batt.c b/batt.c | |
t@@ -62,8 +62,7 @@ int | |
battread(void *arg, char *buf, size_t len) | |
{ | |
FILE *fp; | |
- int acon; | |
- int life; | |
+ int acon, life, energy, power; | |
struct battarg *battarg = arg; | |
fp = fopen(battarg->cap, "r"); | |
t@@ -73,6 +72,7 @@ battread(void *arg, char *buf, size_t len) | |
} | |
fscanf(fp, "%d", &life); | |
fclose(fp); | |
+ | |
fp = fopen(battarg->ac, "r"); | |
if (fp == NULL) { | |
warn("fopen %s", battarg->ac); | |
t@@ -80,7 +80,21 @@ battread(void *arg, char *buf, size_t len) | |
} | |
fscanf(fp, "%d", &acon); | |
fclose(fp); | |
- battprint(buf, len, acon, life, 0); | |
+ fp = fopen(battarg->en, "r"); | |
+ if (fp == NULL) { | |
+ warn("fopen %s", battarg->en); | |
+ return -1; | |
+ } | |
+ fscanf(fp, "%d", &energy); | |
+ fclose(fp); | |
+ fp = fopen(battarg->pow, "r"); | |
+ if (fp == NULL) { | |
+ warn("fopen %s", battarg->pow); | |
+ return -1; | |
+ } | |
+ fscanf(fp, "%d", &power); | |
+ fclose(fp); | |
+ battprint(buf, len, acon, life, (float)energy / power * 60.0); | |
return 0; | |
} | |
#endif | |
diff --git a/config.h b/config.h | |
t@@ -15,7 +15,7 @@ struct ent ents[] = { | |
/*{ .fmt = "[%s] ", .read = cpuread, .arg = "/sys/device… | |
{ .fmt = " %s°C", .read = tempread, .arg = "/sys/class/… | |
{ .fmt = " %s "SEP, .read = loadread, .arg = NULL }, | |
- { .fmt = "%s", .read = battread, .arg = &(struct… | |
+ { .fmt = "%s", .read = battread, .arg = &(struct… | |
/*{ .fmt = "%s ", .read = fileread, .arg = "/etc… | |
{ .fmt = " %s "SEP, .read = wifiread, .arg = NUL… | |
{ .fmt = " %s", .read = dateread, .arg = &(struc… | |
diff --git a/types.h b/types.h | |
t@@ -1,6 +1,8 @@ | |
struct battarg { | |
char *cap; | |
char *ac; | |
+ char *en; | |
+ char *pow; | |
}; | |
struct mpdarg { |