From 2af7a6e091bb62faff9cdda5bb7e3fb5dcc8d15a Mon Sep 17 00:00:00 2001 From: Richard Hughes Date: Mon, 27 Dec 2010 19:22:11 +0000 Subject: 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. --- src/linux/up-device-supply.c | 24 ++++++++++++++---------- 1 file 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 */ -- cgit v1.2.3