diff options
author | Klemen Košir <klemen913@gmail.com> | 2014-08-25 19:03:11 +0200 |
---|---|---|
committer | Michael Stapelberg <michael@stapelberg.de> | 2014-08-25 19:36:02 +0200 |
commit | fcd95c24085c985f365d8d5283bccd003084f39d (patch) | |
tree | 272e1507f92ddc818378d9b55a95028b98345c51 /src | |
parent | d73ca2fa829c722e1ee2a7a0a05a43f4622d6879 (diff) |
Fix battery indicator on systems without POWER_SUPPLY_VOLTAGE_NOW.
In my case, the voltage variable would stay initialized as -1,
which caused the calculation of battery charge percentage to be
incorrect (I would get the message that there is no battery present
or even -0% charge).
I have no idea how this would affect other systems, since I don't
have a chance to test this.
Diffstat (limited to 'src')
-rw-r--r-- | src/print_battery_info.c | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/src/print_battery_info.c b/src/print_battery_info.c index 102522b..6b39c12 100644 --- a/src/print_battery_info.c +++ b/src/print_battery_info.c @@ -124,8 +124,11 @@ void print_battery_info(yajl_gen json_gen, char *buffer, int number, const char * ampere to watt */ if (!watt_as_unit) { present_rate = (((float)voltage / 1000.0) * ((float)present_rate / 1000.0)); - remaining = (((float)voltage / 1000.0) * ((float)remaining / 1000.0)); - full_design = (((float)voltage / 1000.0) * ((float)full_design / 1000.0)); + + if (voltage != -1) { + remaining = (((float)voltage / 1000.0) * ((float)remaining / 1000.0)); + full_design = (((float)voltage / 1000.0) * ((float)full_design / 1000.0)); + } } if ((full_design == -1) || (remaining == -1)) { |