mirror of
https://github.com/xzeldon/htop.git
synced 2025-07-10 03:04:36 +03:00
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:
@ -1,30 +0,0 @@
|
||||
/*
|
||||
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"
|
||||
|
||||
#include <math.h>
|
||||
#include <sys/sysctl.h>
|
||||
|
||||
void Battery_getData(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;
|
||||
}
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
#ifndef HEADER_Battery
|
||||
#define HEADER_Battery
|
||||
/*
|
||||
htop - dragonflybsd/Battery.h
|
||||
(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 "BatteryMeter.h"
|
||||
|
||||
void Battery_getData(double* level, ACPresence* isOnAC);
|
||||
|
||||
#endif
|
@ -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;
|
||||
}
|
||||
|
@ -56,4 +56,6 @@ bool Platform_getNetworkIO(unsigned long int* bytesReceived,
|
||||
unsigned long int* bytesTransmitted,
|
||||
unsigned long int* packetsTransmitted);
|
||||
|
||||
void Platform_getBattery(double* level, ACPresence* isOnAC);
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user