htop/dragonflybsd/Battery.c

31 lines
730 B
C
Raw Normal View History

/*
htop - dragonflybsd/Battery.c
(C) 2015 Hisham H. Muhammad
(C) 2017 Diederik de Groot
Released under the GNU GPLv2, see the COPYING file
in the source distribution for its full text.
*/
#include "Battery.h"
2020-09-07 09:52:42 +00:00
#include <math.h>
#include <sys/sysctl.h>
void Battery_getData(double* level, ACPresence* isOnAC) {
int life;
size_t life_len = sizeof(life);
2020-11-01 00:09:51 +00:00
if (sysctlbyname("hw.acpi.battery.life", &life, &life_len, NULL, 0) == -1) {
2020-09-07 09:52:42 +00:00
*level = NAN;
2020-11-01 00:09:51 +00:00
} else {
*level = life;
2020-11-01 00:09:51 +00:00
}
int acline;
size_t acline_len = sizeof(acline);
2020-11-01 00:09:51 +00:00
if (sysctlbyname("hw.acpi.acline", &acline, &acline_len, NULL, 0) == -1) {
*isOnAC = AC_ERROR;
2020-11-01 00:09:51 +00:00
} else {
*isOnAC = acline == 0 ? AC_ABSENT : AC_PRESENT;
2020-11-01 00:09:51 +00:00
}
}