]> git.sur5r.net Git - i3/i3status/commitdiff
Fix battery indicator on systems without POWER_SUPPLY_VOLTAGE_NOW.
authorKlemen Košir <klemen913@gmail.com>
Mon, 25 Aug 2014 17:03:11 +0000 (19:03 +0200)
committerMichael Stapelberg <michael@stapelberg.de>
Mon, 25 Aug 2014 17:36:02 +0000 (19:36 +0200)
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.

src/print_battery_info.c

index 102522b154d0c7a25dab4ddda8397c61bfc36cd7..6b39c12cedeef866ac2e01581792ee0366d9f9a4 100644 (file)
@@ -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)) {