mirror of https://github.com/xzeldon/htop.git
Unify naming of first argument of Platform_getBattery
Use percent throughout
This commit is contained in:
parent
a3221f3677
commit
601ad61e7d
|
@ -355,10 +355,10 @@ bool Platform_getNetworkIO(unsigned long int* bytesReceived,
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Platform_getBattery(double* level, ACPresence* isOnAC) {
|
void Platform_getBattery(double* percent, ACPresence* isOnAC) {
|
||||||
CFTypeRef power_sources = IOPSCopyPowerSourcesInfo();
|
CFTypeRef power_sources = IOPSCopyPowerSourcesInfo();
|
||||||
|
|
||||||
*level = NAN;
|
*percent = NAN;
|
||||||
*isOnAC = AC_ERROR;
|
*isOnAC = AC_ERROR;
|
||||||
|
|
||||||
if (NULL == power_sources)
|
if (NULL == power_sources)
|
||||||
|
@ -410,7 +410,7 @@ void Platform_getBattery(double* level, ACPresence* isOnAC) {
|
||||||
CFNumberGetValue(CFDictionaryGetValue(battery, CFSTR(kIOPSMaxCapacityKey)),
|
CFNumberGetValue(CFDictionaryGetValue(battery, CFSTR(kIOPSMaxCapacityKey)),
|
||||||
kCFNumberDoubleType, &max);
|
kCFNumberDoubleType, &max);
|
||||||
|
|
||||||
*level = (current * 100.0) / max;
|
*percent = (current * 100.0) / max;
|
||||||
|
|
||||||
CFRelease(battery);
|
CFRelease(battery);
|
||||||
}
|
}
|
||||||
|
|
|
@ -244,13 +244,13 @@ bool Platform_getNetworkIO(unsigned long int* bytesReceived,
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Platform_getBattery(double* level, ACPresence* isOnAC) {
|
void Platform_getBattery(double* percent, ACPresence* isOnAC) {
|
||||||
int life;
|
int life;
|
||||||
size_t life_len = sizeof(life);
|
size_t life_len = sizeof(life);
|
||||||
if (sysctlbyname("hw.acpi.battery.life", &life, &life_len, NULL, 0) == -1)
|
if (sysctlbyname("hw.acpi.battery.life", &life, &life_len, NULL, 0) == -1)
|
||||||
*level = NAN;
|
*percent = NAN;
|
||||||
else
|
else
|
||||||
*level = life;
|
*percent = life;
|
||||||
|
|
||||||
int acline;
|
int acline;
|
||||||
size_t acline_len = sizeof(acline);
|
size_t acline_len = sizeof(acline);
|
||||||
|
|
|
@ -60,6 +60,6 @@ bool Platform_getNetworkIO(unsigned long int* bytesReceived,
|
||||||
unsigned long int* bytesTransmitted,
|
unsigned long int* bytesTransmitted,
|
||||||
unsigned long int* packetsTransmitted);
|
unsigned long int* packetsTransmitted);
|
||||||
|
|
||||||
void Platform_getBattery(double* level, ACPresence* isOnAC);
|
void Platform_getBattery(double* percent, ACPresence* isOnAC);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -357,13 +357,13 @@ bool Platform_getNetworkIO(unsigned long int* bytesReceived,
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Platform_getBattery(double* level, ACPresence* isOnAC) {
|
void Platform_getBattery(double* percent, ACPresence* isOnAC) {
|
||||||
int life;
|
int life;
|
||||||
size_t life_len = sizeof(life);
|
size_t life_len = sizeof(life);
|
||||||
if (sysctlbyname("hw.acpi.battery.life", &life, &life_len, NULL, 0) == -1)
|
if (sysctlbyname("hw.acpi.battery.life", &life, &life_len, NULL, 0) == -1)
|
||||||
*level = NAN;
|
*percent = NAN;
|
||||||
else
|
else
|
||||||
*level = life;
|
*percent = life;
|
||||||
|
|
||||||
int acline;
|
int acline;
|
||||||
size_t acline_len = sizeof(acline);
|
size_t acline_len = sizeof(acline);
|
||||||
|
|
|
@ -66,6 +66,6 @@ bool Platform_getNetworkIO(unsigned long int* bytesReceived,
|
||||||
unsigned long int* bytesTransmitted,
|
unsigned long int* bytesTransmitted,
|
||||||
unsigned long int* packetsTransmitted);
|
unsigned long int* packetsTransmitted);
|
||||||
|
|
||||||
void Platform_getBattery(double* level, ACPresence* isOnAC);
|
void Platform_getBattery(double* percent, ACPresence* isOnAC);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -110,7 +110,7 @@ const unsigned int Platform_numberOfSignals = ARRAYSIZE(Platform_signals);
|
||||||
|
|
||||||
static enum { BAT_PROC, BAT_SYS, BAT_ERR } Platform_Battery_method = BAT_PROC;
|
static enum { BAT_PROC, BAT_SYS, BAT_ERR } Platform_Battery_method = BAT_PROC;
|
||||||
static time_t Platform_Battery_cacheTime;
|
static time_t Platform_Battery_cacheTime;
|
||||||
static double Platform_Battery_cacheLevel = NAN;
|
static double Platform_Battery_cachePercent = NAN;
|
||||||
static ACPresence Platform_Battery_cacheIsOnAC;
|
static ACPresence Platform_Battery_cacheIsOnAC;
|
||||||
|
|
||||||
void Platform_init(void) {
|
void Platform_init(void) {
|
||||||
|
@ -708,9 +708,9 @@ static double Platform_Battery_getProcBatInfo(void) {
|
||||||
return totalRemain * 100.0 / (double) totalFull;
|
return totalRemain * 100.0 / (double) totalFull;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void Platform_Battery_getProcData(double* level, ACPresence* isOnAC) {
|
static void Platform_Battery_getProcData(double* percent, ACPresence* isOnAC) {
|
||||||
*isOnAC = procAcpiCheck();
|
*isOnAC = procAcpiCheck();
|
||||||
*level = AC_ERROR != *isOnAC ? Platform_Battery_getProcBatInfo() : NAN;
|
*percent = AC_ERROR != *isOnAC ? Platform_Battery_getProcBatInfo() : NAN;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------
|
// ----------------------------------------
|
||||||
|
@ -739,9 +739,9 @@ static inline ssize_t xread(int fd, void* buf, size_t count) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void Platform_Battery_getSysData(double* level, ACPresence* isOnAC) {
|
static void Platform_Battery_getSysData(double* percent, ACPresence* isOnAC) {
|
||||||
|
|
||||||
*level = NAN;
|
*percent = NAN;
|
||||||
*isOnAC = AC_ERROR;
|
*isOnAC = AC_ERROR;
|
||||||
|
|
||||||
DIR* dir = opendir(SYS_POWERSUPPLY_DIR);
|
DIR* dir = opendir(SYS_POWERSUPPLY_DIR);
|
||||||
|
@ -857,35 +857,35 @@ static void Platform_Battery_getSysData(double* level, ACPresence* isOnAC) {
|
||||||
}
|
}
|
||||||
closedir(dir);
|
closedir(dir);
|
||||||
|
|
||||||
*level = totalFull > 0 ? ((double) totalRemain * 100.0) / (double) totalFull : NAN;
|
*percent = totalFull > 0 ? ((double) totalRemain * 100.0) / (double) totalFull : NAN;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Platform_getBattery(double* level, ACPresence* isOnAC) {
|
void Platform_getBattery(double* percent, ACPresence* isOnAC) {
|
||||||
time_t now = time(NULL);
|
time_t now = time(NULL);
|
||||||
// update battery reading is slow. Update it each 10 seconds only.
|
// update battery reading is slow. Update it each 10 seconds only.
|
||||||
if (now < Platform_Battery_cacheTime + 10) {
|
if (now < Platform_Battery_cacheTime + 10) {
|
||||||
*level = Platform_Battery_cacheLevel;
|
*percent = Platform_Battery_cachePercent;
|
||||||
*isOnAC = Platform_Battery_cacheIsOnAC;
|
*isOnAC = Platform_Battery_cacheIsOnAC;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Platform_Battery_method == BAT_PROC) {
|
if (Platform_Battery_method == BAT_PROC) {
|
||||||
Platform_Battery_getProcData(level, isOnAC);
|
Platform_Battery_getProcData(percent, isOnAC);
|
||||||
if (isnan(*level))
|
if (isnan(*percent))
|
||||||
Platform_Battery_method = BAT_SYS;
|
Platform_Battery_method = BAT_SYS;
|
||||||
}
|
}
|
||||||
if (Platform_Battery_method == BAT_SYS) {
|
if (Platform_Battery_method == BAT_SYS) {
|
||||||
Platform_Battery_getSysData(level, isOnAC);
|
Platform_Battery_getSysData(percent, isOnAC);
|
||||||
if (isnan(*level))
|
if (isnan(*percent))
|
||||||
Platform_Battery_method = BAT_ERR;
|
Platform_Battery_method = BAT_ERR;
|
||||||
}
|
}
|
||||||
if (Platform_Battery_method == BAT_ERR) {
|
if (Platform_Battery_method == BAT_ERR) {
|
||||||
*level = NAN;
|
*percent = NAN;
|
||||||
*isOnAC = AC_ERROR;
|
*isOnAC = AC_ERROR;
|
||||||
} else {
|
} else {
|
||||||
*level = CLAMP(*level, 0.0, 100.0);
|
*percent = CLAMP(*percent, 0.0, 100.0);
|
||||||
}
|
}
|
||||||
Platform_Battery_cacheLevel = *level;
|
Platform_Battery_cachePercent = *percent;
|
||||||
Platform_Battery_cacheIsOnAC = *isOnAC;
|
Platform_Battery_cacheIsOnAC = *isOnAC;
|
||||||
Platform_Battery_cacheTime = now;
|
Platform_Battery_cacheTime = now;
|
||||||
}
|
}
|
||||||
|
|
|
@ -349,7 +349,7 @@ static bool findDevice(const char* name, int* mib, struct sensordev* snsrdev, si
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Platform_getBattery(double* level, ACPresence* isOnAC) {
|
void Platform_getBattery(double* percent, ACPresence* isOnAC) {
|
||||||
static int mib[] = {CTL_HW, HW_SENSORS, 0, 0, 0};
|
static int mib[] = {CTL_HW, HW_SENSORS, 0, 0, 0};
|
||||||
struct sensor s;
|
struct sensor s;
|
||||||
size_t slen = sizeof(struct sensor);
|
size_t slen = sizeof(struct sensor);
|
||||||
|
@ -358,7 +358,7 @@ void Platform_getBattery(double* level, ACPresence* isOnAC) {
|
||||||
|
|
||||||
bool found = findDevice("acpibat0", mib, &snsrdev, &sdlen);
|
bool found = findDevice("acpibat0", mib, &snsrdev, &sdlen);
|
||||||
|
|
||||||
*level = NAN;
|
*percent = NAN;
|
||||||
if (found) {
|
if (found) {
|
||||||
/* last full capacity */
|
/* last full capacity */
|
||||||
mib[3] = 7;
|
mib[3] = 7;
|
||||||
|
@ -372,9 +372,9 @@ void Platform_getBattery(double* level, ACPresence* isOnAC) {
|
||||||
mib[4] = 3;
|
mib[4] = 3;
|
||||||
if (sysctl(mib, 5, &s, &slen, NULL, 0) != -1) {
|
if (sysctl(mib, 5, &s, &slen, NULL, 0) != -1) {
|
||||||
double charge = s.value;
|
double charge = s.value;
|
||||||
*level = 100 * (charge / last_full_capacity);
|
*percent = 100 * (charge / last_full_capacity);
|
||||||
if (charge >= last_full_capacity) {
|
if (charge >= last_full_capacity) {
|
||||||
*level = 100;
|
*percent = 100;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,6 +61,6 @@ bool Platform_getNetworkIO(unsigned long int* bytesReceived,
|
||||||
unsigned long int* bytesTransmitted,
|
unsigned long int* bytesTransmitted,
|
||||||
unsigned long int* packetsTransmitted);
|
unsigned long int* packetsTransmitted);
|
||||||
|
|
||||||
void Platform_getBattery(double* level, ACPresence* isOnAC);
|
void Platform_getBattery(double* percent, ACPresence* isOnAC);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -309,7 +309,7 @@ bool Platform_getNetworkIO(unsigned long int* bytesReceived,
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Platform_getBattery(double* level, ACPresence* isOnAC) {
|
void Platform_getBattery(double* percent, ACPresence* isOnAC) {
|
||||||
*level = NAN;
|
*percent = NAN;
|
||||||
*isOnAC = AC_ERROR;
|
*isOnAC = AC_ERROR;
|
||||||
}
|
}
|
||||||
|
|
|
@ -84,6 +84,6 @@ bool Platform_getNetworkIO(unsigned long int* bytesReceived,
|
||||||
unsigned long int* bytesTransmitted,
|
unsigned long int* bytesTransmitted,
|
||||||
unsigned long int* packetsTransmitted);
|
unsigned long int* packetsTransmitted);
|
||||||
|
|
||||||
void Platform_getBattery(double* level, ACPresence* isOnAC);
|
void Platform_getBattery(double* percent, ACPresence* isOnAC);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -176,7 +176,7 @@ bool Platform_getNetworkIO(unsigned long int* bytesReceived,
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Platform_getBattery(double* level, ACPresence* isOnAC) {
|
void Platform_getBattery(double* percent, ACPresence* isOnAC) {
|
||||||
*level = NAN;
|
*percent = NAN;
|
||||||
*isOnAC = AC_ERROR;
|
*isOnAC = AC_ERROR;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue