summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien Nocera <hadess@hadess.net>2018-06-18 17:27:05 +0200
committerBastien Nocera <hadess@hadess.net>2019-10-23 16:29:04 +0200
commit8947c4619baede38e040fc6b6630e2d703652eeb (patch)
tree1d8b8fae02971d8397a34a24113ef4f17b1fa65f
parenta1a437d7b1e0a9ea46bf72c390c3aeaf6d61c07d (diff)
downloadupower-wip/hadess/allow-zero-power-now.tar.gz
linux: Allow batteries to report 0 as power_nowwip/hadess/allow-zero-power-now
Which can happen for dual battery machines. Closes: #44
-rw-r--r--src/linux/up-device-supply.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/src/linux/up-device-supply.c b/src/linux/up-device-supply.c
index d7e4423..1ad35e5 100644
--- a/src/linux/up-device-supply.c
+++ b/src/linux/up-device-supply.c
@@ -672,8 +672,7 @@ up_device_supply_refresh_battery (UpDeviceSupply *supply,
state = up_device_supply_get_state (native_path);
/* this is the new value in uW */
- energy_rate = fabs (sysfs_get_double (native_path, "power_now") / 1000000.0);
- if (energy_rate < 0.01) {
+ if (!sysfs_get_double_with_error (native_path, "power_now", &energy_rate)) {
gdouble charge_full;
/* convert charge to energy */
@@ -694,6 +693,8 @@ up_device_supply_refresh_battery (UpDeviceSupply *supply,
energy_rate = fabs (sysfs_get_double (native_path, "current_now") / 1000000.0);
if (charge_full != 0)
energy_rate *= voltage_design;
+ } else {
+ energy_rate = fabs (energy_rate / 1000000.0);
}
/* some batteries don't update last_full attribute */