diff options
author | Diederik de Groot <ddegroot@talon.nl> | 2017-04-19 16:12:17 +0200 |
---|---|---|
committer | Diederik de Groot <ddegroot@talon.nl> | 2017-04-19 16:19:32 +0200 |
commit | b258d6e53eb421651ac3fbe9c99e636f0f8cdfc4 (patch) | |
tree | 6bb60a13ca81815e2c74fbe7f65193949ff54e4b /dragonflybsd/Battery.c | |
parent | 5570748dd27e5b1e8c109b80fb31500fcd8f7fad (diff) |
Initial addition of dragonflybsd (based on FreeBSD)
Diffstat (limited to 'dragonflybsd/Battery.c')
-rw-r--r-- | dragonflybsd/Battery.c | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/dragonflybsd/Battery.c b/dragonflybsd/Battery.c new file mode 100644 index 00000000..f17efb5d --- /dev/null +++ b/dragonflybsd/Battery.c @@ -0,0 +1,26 @@ +/* +htop - dragonflybsd/Battery.c +(C) 2015 Hisham H. Muhammad +(C) 2017 Diederik de Groot +Released under the GNU GPL, see the COPYING file +in the source distribution for its full text. +*/ + +#include "BatteryMeter.h" +#include <sys/sysctl.h> + +void Battery_getData(double* level, ACPresence* isOnAC) { + 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; +} |