mirror of
https://github.com/xzeldon/htop.git
synced 2024-12-23 22:55:46 +00:00
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;
|
||||
}
|
||||
|
||||
void Platform_getBattery(double* level, ACPresence* isOnAC) {
|
||||
void Platform_getBattery(double* percent, ACPresence* isOnAC) {
|
||||
CFTypeRef power_sources = IOPSCopyPowerSourcesInfo();
|
||||
|
||||
*level = NAN;
|
||||
*percent = NAN;
|
||||
*isOnAC = AC_ERROR;
|
||||
|
||||
if (NULL == power_sources)
|
||||
@ -410,7 +410,7 @@ void Platform_getBattery(double* level, ACPresence* isOnAC) {
|
||||
CFNumberGetValue(CFDictionaryGetValue(battery, CFSTR(kIOPSMaxCapacityKey)),
|
||||
kCFNumberDoubleType, &max);
|
||||
|
||||
*level = (current * 100.0) / max;
|
||||
*percent = (current * 100.0) / max;
|
||||
|
||||
CFRelease(battery);
|
||||
}
|
||||
|
@ -244,13 +244,13 @@ bool Platform_getNetworkIO(unsigned long int* bytesReceived,
|
||||
return false;
|
||||
}
|
||||
|
||||
void Platform_getBattery(double* level, ACPresence* isOnAC) {
|
||||
void Platform_getBattery(double* percent, ACPresence* isOnAC) {
|
||||
int life;
|
||||
size_t life_len = sizeof(life);
|
||||
if (sysctlbyname("hw.acpi.battery.life", &life, &life_len, NULL, 0) == -1)
|
||||
*level = NAN;
|
||||
*percent = NAN;
|
||||
else
|
||||
*level = life;
|
||||
*percent = life;
|
||||
|
||||
int 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* packetsTransmitted);
|
||||
|
||||
void Platform_getBattery(double* level, ACPresence* isOnAC);
|
||||
void Platform_getBattery(double* percent, ACPresence* isOnAC);
|
||||
|
||||
#endif
|
||||
|
@ -357,13 +357,13 @@ bool Platform_getNetworkIO(unsigned long int* bytesReceived,
|
||||
return true;
|
||||
}
|
||||
|
||||
void Platform_getBattery(double* level, ACPresence* isOnAC) {
|
||||
void Platform_getBattery(double* percent, ACPresence* isOnAC) {
|
||||
int life;
|
||||
size_t life_len = sizeof(life);
|
||||
if (sysctlbyname("hw.acpi.battery.life", &life, &life_len, NULL, 0) == -1)
|
||||
*level = NAN;
|
||||
*percent = NAN;
|
||||
else
|
||||
*level = life;
|
||||
*percent = life;
|
||||
|
||||
int 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* packetsTransmitted);
|
||||
|
||||
void Platform_getBattery(double* level, ACPresence* isOnAC);
|
||||
void Platform_getBattery(double* percent, ACPresence* isOnAC);
|
||||
|
||||
#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 time_t Platform_Battery_cacheTime;
|
||||
static double Platform_Battery_cacheLevel = NAN;
|
||||
static double Platform_Battery_cachePercent = NAN;
|
||||
static ACPresence Platform_Battery_cacheIsOnAC;
|
||||
|
||||
void Platform_init(void) {
|
||||
@ -708,9 +708,9 @@ static double Platform_Battery_getProcBatInfo(void) {
|
||||
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();
|
||||
*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;
|
||||
|
||||
DIR* dir = opendir(SYS_POWERSUPPLY_DIR);
|
||||
@ -857,35 +857,35 @@ static void Platform_Battery_getSysData(double* level, ACPresence* isOnAC) {
|
||||
}
|
||||
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);
|
||||
// update battery reading is slow. Update it each 10 seconds only.
|
||||
if (now < Platform_Battery_cacheTime + 10) {
|
||||
*level = Platform_Battery_cacheLevel;
|
||||
*percent = Platform_Battery_cachePercent;
|
||||
*isOnAC = Platform_Battery_cacheIsOnAC;
|
||||
return;
|
||||
}
|
||||
|
||||
if (Platform_Battery_method == BAT_PROC) {
|
||||
Platform_Battery_getProcData(level, isOnAC);
|
||||
if (isnan(*level))
|
||||
Platform_Battery_getProcData(percent, isOnAC);
|
||||
if (isnan(*percent))
|
||||
Platform_Battery_method = BAT_SYS;
|
||||
}
|
||||
if (Platform_Battery_method == BAT_SYS) {
|
||||
Platform_Battery_getSysData(level, isOnAC);
|
||||
if (isnan(*level))
|
||||
Platform_Battery_getSysData(percent, isOnAC);
|
||||
if (isnan(*percent))
|
||||
Platform_Battery_method = BAT_ERR;
|
||||
}
|
||||
if (Platform_Battery_method == BAT_ERR) {
|
||||
*level = NAN;
|
||||
*percent = NAN;
|
||||
*isOnAC = AC_ERROR;
|
||||
} 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_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};
|
||||
struct sensor s;
|
||||
size_t slen = sizeof(struct sensor);
|
||||
@ -358,7 +358,7 @@ void Platform_getBattery(double* level, ACPresence* isOnAC) {
|
||||
|
||||
bool found = findDevice("acpibat0", mib, &snsrdev, &sdlen);
|
||||
|
||||
*level = NAN;
|
||||
*percent = NAN;
|
||||
if (found) {
|
||||
/* last full capacity */
|
||||
mib[3] = 7;
|
||||
@ -372,9 +372,9 @@ void Platform_getBattery(double* level, ACPresence* isOnAC) {
|
||||
mib[4] = 3;
|
||||
if (sysctl(mib, 5, &s, &slen, NULL, 0) != -1) {
|
||||
double charge = s.value;
|
||||
*level = 100 * (charge / last_full_capacity);
|
||||
*percent = 100 * (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* packetsTransmitted);
|
||||
|
||||
void Platform_getBattery(double* level, ACPresence* isOnAC);
|
||||
void Platform_getBattery(double* percent, ACPresence* isOnAC);
|
||||
|
||||
#endif
|
||||
|
@ -309,7 +309,7 @@ bool Platform_getNetworkIO(unsigned long int* bytesReceived,
|
||||
return false;
|
||||
}
|
||||
|
||||
void Platform_getBattery(double* level, ACPresence* isOnAC) {
|
||||
*level = NAN;
|
||||
void Platform_getBattery(double* percent, ACPresence* isOnAC) {
|
||||
*percent = NAN;
|
||||
*isOnAC = AC_ERROR;
|
||||
}
|
||||
|
@ -84,6 +84,6 @@ bool Platform_getNetworkIO(unsigned long int* bytesReceived,
|
||||
unsigned long int* bytesTransmitted,
|
||||
unsigned long int* packetsTransmitted);
|
||||
|
||||
void Platform_getBattery(double* level, ACPresence* isOnAC);
|
||||
void Platform_getBattery(double* percent, ACPresence* isOnAC);
|
||||
|
||||
#endif
|
||||
|
@ -176,7 +176,7 @@ bool Platform_getNetworkIO(unsigned long int* bytesReceived,
|
||||
return false;
|
||||
}
|
||||
|
||||
void Platform_getBattery(double* level, ACPresence* isOnAC) {
|
||||
*level = NAN;
|
||||
void Platform_getBattery(double* percent, ACPresence* isOnAC) {
|
||||
*percent = NAN;
|
||||
*isOnAC = AC_ERROR;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user