sites

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit 4a6a951fa439e6439b44810af9f67a4098c07037
parent 92bc1594419868484bfcd46a8b925630001068bb
Author: Christoph Lohmann <20h@r-36.net>
Date:   Fri, 21 Oct 2011 09:46:27 +0200

Adding support for the rolling API in Linux. :(
Diffstat:
Adwm.suckless.org/dwmstatus/even-newer-acpi-battery.c | 55+++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mdwm.suckless.org/dwmstatus/index.md | 3++-
2 files changed, 57 insertions(+), 1 deletion(-)

diff --git a/dwm.suckless.org/dwmstatus/even-newer-acpi-battery.c b/dwm.suckless.org/dwmstatus/even-newer-acpi-battery.c @@ -0,0 +1,55 @@ +char * +readfile(char *base, char *file) +{ + char *path, line[513]; + FILE *fd; + + memset(line, 0, sizeof(line)); + + path = smprintf("%s/%s", base, file); + fd = fopen(path, "r"); + if (fd == NULL) { + perror("fopen"); + exit(1); + } + free(path); + + if (fgets(line, sizeof(line)-1, fd) == NULL) { + perror("fgets"); + exit(1); + } + fclose(fd); + + return smprintf("%s", line); +} + +char * +getbattery(char *base) +{ + char *co; + int descap, remcap; + + descap = -1; + remcap = -1; + + co = readfile(base, "present"); + if (co[0] != '1') { + free(co); + return smprintf("not present"); + } + free(co); + + co = readfile(base, "energy_full_design"); + sscanf(co, "%d", &descap); + free(co); + + co = readfile(base, "energy_now"); + sscanf(co, "%d", &remcap); + free(co); + + if (remcap < 0 || descap < 0) + return smprintf("invalid"); + + return smprintf("%.0f", ((float)remcap / (float)descap) * 100); +} + diff --git a/dwm.suckless.org/dwmstatus/index.md b/dwm.suckless.org/dwmstatus/index.md @@ -20,5 +20,6 @@ Helper functions If you have simple C functions for gathering system information, please add them here as file or as code example. -* [Support for the new battery ACPI code in Linux](new-acpi-battery.c) +* [Support for ACPI battery status Linux < 3.0](new-acpi-battery.c) +* [Support for ACPI battery status Linux >= 3](even-newer-acpi-battery.c)