diff options
author | Hisham <hisham@gobolinux.org> | 2016-02-11 15:24:49 -0200 |
---|---|---|
committer | Hisham <hisham@gobolinux.org> | 2016-02-11 15:24:49 -0200 |
commit | e46488463d9c2ced9cf8fe8e0c98ad5de56db62c (patch) | |
tree | 8e7a127e45fe2eabb4a37fc290f71b720858dbb5 | |
parent | 563d5d3ab93e9e2d005123b29037345619ee2e5a (diff) | |
parent | b6f927bffa97564f2e1d0988e93db5876ba4e376 (diff) |
Merge branch 'master' of https://github.com/hishamhm/htop
-rw-r--r-- | freebsd/Battery.c | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/freebsd/Battery.c b/freebsd/Battery.c index ab63aa10..b8c5e312 100644 --- a/freebsd/Battery.c +++ b/freebsd/Battery.c @@ -6,10 +6,20 @@ in the source distribution for its full text. */ #include "BatteryMeter.h" +#include <sys/sysctl.h> void Battery_getData(double* level, ACPresence* isOnAC) { - // TODO - *level = -1; - *isOnAC = AC_ERROR; -} + int life; + size_t life_len = sizeof(life); + if (sysctlbyname("hw.acpi.battery.life", &life, &life_len, NULL, 0) == -1) + *level = -1; + else + *level = life; + int acline; + size_t acline_len = sizeof(acline); + if (sysctlbyname("hw.acpi.acline", &acline, &acline_len, NULL, 0) == -1) + *isOnAC = AC_ERROR; + else + *isOnAC = acline == 0 ? AC_ABSENT : AC_PRESENT; +} |