mirror of
https://github.com/9fans/plan9port.git
synced 2025-01-27 11:52:03 +00:00
auxstats: replace /proc ACPI calls with /sys ones (#245)
According to <https://askubuntu.com/a/309146>, use of `/proc/acpi` to get battery usage is deprecated. This commit replaces the two files from this API with the single file `/sys/class/power_supply/BAT0/capacity`, simultaneously removing the need to calculate battery percentage.
This commit is contained in:
parent
e995a0c101
commit
7d827b5cca
1 changed files with 8 additions and 22 deletions
|
@ -26,36 +26,22 @@ void (*statfn[])(int) =
|
||||||
void
|
void
|
||||||
xapm(int first)
|
xapm(int first)
|
||||||
{
|
{
|
||||||
static int fd = -1, fdb = -1;
|
static int fd = -1;
|
||||||
int i, last = -1, curr = -1;
|
int curr = -1;
|
||||||
|
|
||||||
if(first){
|
if(first){
|
||||||
fd = open("/proc/acpi/battery/BAT0/info", OREAD);
|
fd = open("/sys/class/power_supply/BAT0/capacity", OREAD);
|
||||||
fdb = open("/proc/acpi/battery/BAT0/state", OREAD);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(fd == -1 || fdb == -1)
|
if(fd == -1)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
readfile(fd);
|
readfile(fd);
|
||||||
for(i=0; i<nline; i++){
|
tokens(0);
|
||||||
tokens(i);
|
curr = atoi(tok[0]);
|
||||||
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)
|
if(curr != -1)
|
||||||
Bprint(&bout, "battery =%d 100\n", (int)(((float)curr/(float)last)*100.0));
|
Bprint(&bout, "battery =%d 100\n", curr);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue