add FreeBSD battery support

This commit is contained in:
Greg V 2016-02-11 13:23:30 +03:00
parent 5c593fae42
commit f1d1d6e0d6
1 changed files with 14 additions and 4 deletions

View File

@ -6,10 +6,20 @@ in the source distribution for its full text.
*/ */
#include "BatteryMeter.h" #include "BatteryMeter.h"
#include <sys/sysctl.h>
void Battery_getData(double* level, ACPresence* isOnAC) { void Battery_getData(double* level, ACPresence* isOnAC) {
// TODO int life;
size_t life_len = sizeof(life);
if (sysctlbyname("hw.acpi.battery.life", &life, &life_len, NULL, 0) == -1)
*level = -1; *level = -1;
*isOnAC = AC_ERROR; 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;
}