summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Hughes <richard@hughsie.com>2010-12-27 19:22:11 +0000
committerRichard Hughes <richard@hughsie.com>2011-01-04 09:30:22 +0000
commit2af7a6e091bb62faff9cdda5bb7e3fb5dcc8d15a (patch)
treed17c70c4d39ad30a93b739bebe050182c841440c
parent2dcde5a1c8e86d8cc09a0fe9c1eda1a08efdaee9 (diff)
Support the power_now sysfs attribute to get time remaining on new kernels
The kernel has removed the insanity of providing current_now in either (and unspecified) units of uVh or uWh and instead provides power_now for the power rate value. Related commits: http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commitdiff;h=b137b9942a07843c64a934cfdb7d43155e507e13 http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commitdiff;h=7faa144a518c456e2057918f030f50100144ccc6 Thanks to Florian Eitel for the initial patch.
-rw-r--r--src/linux/up-device-supply.c24
1 files changed, 14 insertions, 10 deletions
diff --git a/src/linux/up-device-supply.c b/src/linux/up-device-supply.c
index 341f5df..95f186c 100644
--- a/src/linux/up-device-supply.c
+++ b/src/linux/up-device-supply.c
@@ -554,16 +554,20 @@ up_device_supply_refresh_battery (UpDeviceSupply *supply)
supply->priv->unknown_retries = 0;
}
- /* get rate; it seems odd as it's either in uVh or uWh */
- energy_rate = fabs (sysfs_get_double (native_path, "current_now") / 1000000.0);
-
- /* convert charge to energy */
- if (energy == 0) {
- energy = sysfs_get_double (native_path, "charge_now") / 1000000.0;
- if (energy == 0)
- energy = sysfs_get_double (native_path, "charge_avg") / 1000000.0;
- energy *= voltage_design;
- energy_rate *= voltage_design;
+ /* this is the new value in mWh */
+ energy_rate = fabs (sysfs_get_double (native_path, "power_now") / 1000000.0);
+ if (energy_rate == 0) {
+ /* get the old rate, rate; which is either in uVh or uWh */
+ energy_rate = fabs (sysfs_get_double (native_path, "current_now") / 1000000.0);
+
+ /* convert charge to energy */
+ if (energy == 0) {
+ energy = sysfs_get_double (native_path, "charge_now") / 1000000.0;
+ if (energy == 0)
+ energy = sysfs_get_double (native_path, "charge_avg") / 1000000.0;
+ energy *= voltage_design;
+ energy_rate *= voltage_design;
+ }
}
/* some batteries don't update last_full attribute */