diff options
author | Nathan Scott <nathans@redhat.com> | 2020-11-17 18:12:38 +1100 |
---|---|---|
committer | Nathan Scott <nathans@redhat.com> | 2020-11-18 10:17:33 +1100 |
commit | ea9622b8c9444d92007f24fc54597f83c498f11d (patch) | |
tree | 13cb45909d2c873b7b09ec59580d6a8db4676b0b /freebsd/Platform.c | |
parent | e3af8d0d0851dd6ce25446a7f9a99e2127795a78 (diff) |
Merge individual Battery.[ch] files into Platform.[ch]
Consistent with everything else involving platform-specific
calls from core htop code.
Diffstat (limited to 'freebsd/Platform.c')
-rw-r--r-- | freebsd/Platform.c | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/freebsd/Platform.c b/freebsd/Platform.c index 2fc9ccc9..8efa4e68 100644 --- a/freebsd/Platform.c +++ b/freebsd/Platform.c @@ -338,3 +338,19 @@ bool Platform_getNetworkIO(unsigned long int* bytesReceived, *packetsTransmitted = packetsTransmittedSum; return true; } + +void Platform_getBattery(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 = NAN; + 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; +} |