diff options
author | Greg V <greg@unrelenting.technology> | 2016-02-11 13:23:30 +0300 |
---|---|---|
committer | Greg V <greg@unrelenting.technology> | 2016-02-11 13:42:37 +0300 |
commit | f1d1d6e0d655171974a41474b5627baa57e281d4 (patch) | |
tree | 37533751a4526f27ed27b713157c4e709ade7e19 /freebsd | |
parent | 5c593fae4227651075cfc9445f17dad6ae0a0b47 (diff) |
add FreeBSD battery support
Diffstat (limited to 'freebsd')
-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; +} |