2015-03-16 06:13:42 +00:00
|
|
|
/*
|
|
|
|
htop - freebsd/Battery.c
|
|
|
|
(C) 2015 Hisham H. Muhammad
|
2020-10-05 07:51:32 +00:00
|
|
|
Released under the GNU GPLv2, see the COPYING file
|
2015-03-16 06:13:42 +00:00
|
|
|
in the source distribution for its full text.
|
|
|
|
*/
|
|
|
|
|
2020-09-25 12:03:55 +00:00
|
|
|
#include "Battery.h"
|
|
|
|
|
2020-09-07 09:52:42 +00:00
|
|
|
#include <math.h>
|
2016-02-11 10:23:30 +00:00
|
|
|
#include <sys/sysctl.h>
|
2015-03-16 06:13:42 +00:00
|
|
|
|
|
|
|
void Battery_getData(double* level, ACPresence* isOnAC) {
|
2016-02-11 10:23:30 +00:00
|
|
|
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 {
|
2016-02-11 10:23:30 +00:00
|
|
|
*level = life;
|
2020-11-01 00:09:51 +00:00
|
|
|
}
|
2015-03-16 06:13:42 +00:00
|
|
|
|
2016-02-11 10:23:30 +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) {
|
2016-02-11 10:23:30 +00:00
|
|
|
*isOnAC = AC_ERROR;
|
2020-11-01 00:09:51 +00:00
|
|
|
} else {
|
2016-02-11 10:23:30 +00:00
|
|
|
*isOnAC = acline == 0 ? AC_ABSENT : AC_PRESENT;
|
2020-11-01 00:09:51 +00:00
|
|
|
}
|
2016-02-11 10:23:30 +00:00
|
|
|
}
|