mirror of
https://github.com/xzeldon/htop.git
synced 2024-12-23 22:55:46 +00:00
Parse POWER_SUPPLY_CAPACITY
If POWER_SUPPLY_{CHARGE,ENERGY}_NOW is missing then try to use POWER_SUPPLY_CAPACITY to determine current charge level.
This commit is contained in:
parent
94e32cf1e8
commit
167adc0a2b
@ -230,6 +230,8 @@ static void Battery_getSysData(double* level, ACPresence* isOnAC) {
|
||||
char *line = NULL;
|
||||
bool full = false;
|
||||
bool now = false;
|
||||
int fullSize = 0;
|
||||
double capacityLevel = NAN;
|
||||
while ((line = strsep(&buf, "\n")) != NULL) {
|
||||
#define match(str,prefix) \
|
||||
(String_startsWith(str,prefix) ? (str) + strlen(prefix) : NULL)
|
||||
@ -237,6 +239,10 @@ static void Battery_getSysData(double* level, ACPresence* isOnAC) {
|
||||
if (!ps) {
|
||||
continue;
|
||||
}
|
||||
const char* capacity = match(ps, "CAPACITY=");
|
||||
if (capacity) {
|
||||
capacityLevel = atoi(capacity) / 100.0;
|
||||
}
|
||||
const char* energy = match(ps, "ENERGY_");
|
||||
if (!energy) {
|
||||
energy = match(ps, "CHARGE_");
|
||||
@ -246,7 +252,8 @@ static void Battery_getSysData(double* level, ACPresence* isOnAC) {
|
||||
}
|
||||
const char* value = (!full) ? match(energy, "FULL=") : NULL;
|
||||
if (value) {
|
||||
totalFull += atoi(value);
|
||||
fullSize = atoi(value);
|
||||
totalFull += fullSize;
|
||||
full = true;
|
||||
if (now) break;
|
||||
continue;
|
||||
@ -260,6 +267,9 @@ static void Battery_getSysData(double* level, ACPresence* isOnAC) {
|
||||
}
|
||||
}
|
||||
#undef match
|
||||
if (!now && full && !isnan(capacityLevel)) {
|
||||
totalRemain += (capacityLevel * fullSize);
|
||||
}
|
||||
} else if (entryName[0] == 'A') {
|
||||
if (*isOnAC != AC_ERROR) {
|
||||
continue;
|
||||
|
Loading…
Reference in New Issue
Block a user