htop/freebsd/Battery.c

26 lines
659 B
C
Raw Permalink Normal View History

/*
htop - freebsd/Battery.c
(C) 2015 Hisham H. Muhammad
Released under the GNU GPL, see the COPYING file
in the source distribution for its full text.
*/
#include "BatteryMeter.h"
2016-02-11 10:23:30 +00:00
#include <sys/sysctl.h>
void Battery_getData(double* level, ACPresence* isOnAC) {
2016-02-11 10:23:30 +00:00
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;
2016-02-11 10:23:30 +00:00
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;
}