On 22 December 2010 18:27, Florian Eitel <fei...@indeedgeek.de> wrote:
> In upower checks the current_now sysfs attribute. Linux Kernel
> 2.6.36 removes this attribute[1]. As far as I know the new power_now
> attribute ist added in 2.6.30 so in my opinion no distinction between
> the old current_now and the new power_now is necessary.

Sorry for the delay. I've been dealing with a family death and then
Christmas got in the way. I think the attached patch is better, as it
supports the fallback to old kernels and also deals with mAh reporting
systems. Can you please test this. Thanks.

Richard.
From fb3ef0c116c3626c0df807807db2cab85ce5018c Mon Sep 17 00:00:00 2001
From: Richard Hughes <rich...@hughsie.com>
Date: Mon, 27 Dec 2010 19:22:11 +0000
Subject: [PATCH] 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 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 */
-- 
1.7.3.4

_______________________________________________
devkit-devel mailing list
devkit-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/devkit-devel

Reply via email to