aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/auxstats
diff options
context:
space:
mode:
authorRuss Cox <rsc@swtch.com>2007-09-15 19:06:48 -0400
committerRuss Cox <rsc@swtch.com>2007-09-15 19:06:48 -0400
commit7be768e78cf98b051616d4404d75d1fbb3f39890 (patch)
treebbc4c75db1749d4e092fca18d10c9d852701e4b7 /src/cmd/auxstats
parentd96dce4d873583ce58bd04107fdbded838049306 (diff)
downloadplan9port-7be768e78cf98b051616d4404d75d1fbb3f39890.tar.gz
plan9port-7be768e78cf98b051616d4404d75d1fbb3f39890.tar.bz2
plan9port-7be768e78cf98b051616d4404d75d1fbb3f39890.zip
auxstats: use acpi to find battery info on Linux (Andrey Mirtchovski)
Diffstat (limited to 'src/cmd/auxstats')
-rw-r--r--src/cmd/auxstats/Linux.c31
1 files changed, 26 insertions, 5 deletions
diff --git a/src/cmd/auxstats/Linux.c b/src/cmd/auxstats/Linux.c
index afd88407..2592bc4e 100644
--- a/src/cmd/auxstats/Linux.c
+++ b/src/cmd/auxstats/Linux.c
@@ -22,16 +22,37 @@ void (*statfn[])(int) =
void
xapm(int first)
{
- static int fd = -1;
+ static int fd = -1, fdb = -1;
+ int i, last = -1, curr = -1;
if(first){
- fd = open("/proc/apm", OREAD);
+ fd = open("/proc/acpi/battery/BAT0/info", OREAD);
+ fdb = open("/proc/acpi/battery/BAT0/state", OREAD);
return;
}
+ if(fd == -1 || fdb == -1)
+ return;
+
readfile(fd);
- tokens(0);
- if(ntok >= 7 && atoi(tok[6]) != -1)
- Bprint(&bout, "battery =%d 100\n", atoi(tok[6]));
+ for(i=0; i<nline; i++){
+ tokens(i);
+ if(ntok < 3)
+ continue;
+ if(strcmp(tok[0], "last") == 0 && strcmp(tok[1], "full") == 0)
+ last = atoi(tok[3]);
+ }
+ readfile(fdb);
+ for(i = 0; i < nline; i++) {
+ tokens(i);
+ if(ntok < 3)
+ continue;
+ if(strcmp(tok[0], "remaining") == 0 && strcmp(tok[1], "capacity:") == 0)
+ curr = atoi(tok[2]);
+ }
+
+ if(curr != -1 && last != -1)
+ Bprint(&bout, "battery =%d 100\n", (int)(((float)curr/(float)last)*100.0));
+
}
void