diff options
| author | Michael Stapelberg <michael@stapelberg.de> | 2015-05-20 19:17:23 +0200 | 
|---|---|---|
| committer | Michael Stapelberg <michael@stapelberg.de> | 2015-05-20 19:17:23 +0200 | 
| commit | d1aa135d2801d361f2eccc5efab08a6385ecb440 (patch) | |
| tree | b18b7a8ecd2817a4ce046302abc8fceb1f2b6b9e | |
| parent | f8c11c31b2f8b98d8b879c446da0c7860e703beb (diff) | |
Clamp the percentage at 100% when last_full_capacity is enabled.
| -rw-r--r-- | src/print_battery_info.c | 8 | 
1 files changed, 8 insertions, 0 deletions
diff --git a/src/print_battery_info.c b/src/print_battery_info.c index 85b0a75..0853e18 100644 --- a/src/print_battery_info.c +++ b/src/print_battery_info.c @@ -137,6 +137,14 @@ void print_battery_info(yajl_gen json_gen, char *buffer, int number, const char      (void)snprintf(statusbuf, sizeof(statusbuf), "%s", BATT_STATUS_NAME(status));      float percentage_remaining = (((float)remaining / (float)full_design) * 100); +    /* Some batteries report POWER_SUPPLY_CHARGE_NOW=<full_design> when fully +     * charged, even though that’s plainly wrong. For people who chose to see +     * the percentage calculated based on the last full capacity, we clamp the +     * value to 100%, as that makes more sense. +     * See http://bugs.debian.org/785398 */ +    if (last_full_capacity && percentage_remaining > 100) { +        percentage_remaining = 100; +    }      if (integer_battery_capacity) {          (void)snprintf(percentagebuf, sizeof(percentagebuf), "%.00f%%", percentage_remaining);      } else {  | 
