Skip to content
Browse files

batt: Read absolute current_now, power_now

Some batteries report discharging with a negative value in
'current_now', but we use the 'status' or 'state' file for this.

Others use -1000 to report an error.

Thanks to Stefan Handschuh for reporting and finding this, see
http://sourceforge.net/mailarchive/message.php?msg_id=28935588
  • Loading branch information...
1 parent 035ebe0 commit 93bfb7e94e19780f3185abdc81da32cc27ceb379 Henry Gebhardt committed with brother Mar 10, 2012
Showing with 9 additions and 0 deletions.
  1. +9 −0 src/plugins/batt/batt_sys.c
View
9 src/plugins/batt/batt_sys.c
@@ -153,6 +153,15 @@ void battery_update(battery *b)
b->current_now = get_gint_from_infofile(b, "current_now");
b->power_now = get_gint_from_infofile(b, "power_now");
+ /* FIXME: Some battery drivers report -1000 when the discharge rate is
+ * unavailable. Others use negative values when discharging. Best we can do
+ * is to treat -1 as an error, and take the absolute value otherwise.
+ * Ideally the kernel would not export the sysfs file when the value is not
+ * available. */
+ if (b->current_now < -1)
+ b->current_now = - b->current_now;
+ if (b->power_now < -1)
+ b->power_now = - b->power_now;
b->charge_full = get_gint_from_infofile(b, "charge_full");
b->energy_full = get_gint_from_infofile(b, "energy_full");

0 comments on commit 93bfb7e

Please sign in to comment.
Something went wrong with that request. Please try again.