Merge individual Battery.[ch] files into Platform.[ch]

Consistent with everything else involving platform-specific
calls from core htop code.
This commit is contained in:
Nathan Scott
2020-11-17 18:12:38 +11:00
parent e3af8d0d08
commit ea9622b8c9
29 changed files with 515 additions and 693 deletions

View File

@ -234,3 +234,19 @@ bool Platform_getNetworkIO(unsigned long int* bytesReceived,
*packetsTransmitted = 0;
return false;
}
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;
}