-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

Am Mon, 27 Dec 2010 19:23:44 +0000
schrieb Richard Hughes <hughsi...@gmail.com>:
> 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.

Fist of all: Your patch works for me as well.

But something I doesn't understand. I missunderstood my links to kernel
commits. In my opinion current_now is removed completely. But you are
right: power_now replaces current_now only if the value is reported in
uWh. So since 2.6.30 either current_now (reporting uWh) or power_now
(reporting uVh) exists. Both files must be handled and my patch is
incorrect.

But however I doesn't understand your patch fully. In my opinion it
should be:

(voltage = present voltage calculated line 580)
energy_rate = (power_now exists) ? power_now : (current_now * voltage)
energy      = voltage * ((charge_now exists)? charge_now : charge_avg)

But you uses voltage_design instead of voltage mixed up energy and
energy_rate. "energy_rate *= voltage_design" should be independent of
charge_{now,avg} and not mixed in if conditions.

Sorry, I doesn't tried to understand the whole function so if I'm wrong
please ignore me ;-). As far as I can test it, it works for me. But my
battery uses energy_battery_props.

Thanks,
Florian
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.16 (GNU/Linux)

iQIcBAEBCAAGBQJNGTRhAAoJEDG1ZAdA+6K+i5QQAMhRsV1rbUouYPbAk4toizn6
Rk15ivwckjmiXGt4fzb1t43kqiuSi4VrXInJ7EtX5dwt9QbWgxeMlZbpeY7ZWbS5
YdIeX8pSZTQWwfD2LDZCU/PjTgadgZOwAKhdECGNUnryKxUvDF9Kg+AZSnRsXi9N
UnBIm8MuhpY7ESQQxBkBY13LWJIYX2DfBQG2gUXgqb2Pt0zWRu7i5uE0SJUDBiJi
VaJI+RLapC/Ud07/sHdtCxmGa1qHs6TMFRrO9ZMWKFB38Rs+CJzk3FV2m23U3dBO
0X0yYwG553pCz7QeKk3bQq8/Fr/oY+vgtWJN+3IZSeIIUD0pQIGsnMF/oUoaqdFA
QDvlIW9rQhYyveqIR94xuOuzN3q36droZPWFp1MlsYEL0gld/XES5+SOj2qR7MF0
o2ID38Gier2lE14X4Kd33bjbE8TIXHTH/7AENRGZtVDTDKG54djOyr+3vGK2haUE
OsR8Y4xhchk2NVORk7WQ8ahEnmZfoKCvEn3hFlQul47TxFqSrTnsDYlPv1a6rJxa
NU+nm4+Sd3sQXdTvCE7RQOzhmruzXUj9nx7fZ4TY5wZTKZagacl6rBikOLpKX1WE
FxMmH7JJm+8dA4wPnOZlpo06rFELa9bvBFc7CHj4X+NNTNBziDPu2d395jRGkOiy
o6w9R7rBXFys8ZhMeDCC
=v49F
-----END PGP SIGNATURE-----
From 5bb6d676f87900e79cf398dac5cb9a159519e10f Mon Sep 17 00:00:00 2001
From: Florian Eitel <fei...@indeedgeek.de>
Date: Tue, 28 Dec 2010 01:31:53 +0100
Subject: [PATCH] [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. Instead power_now provides uWh
and old current_now provides uVh 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
---
 src/linux/up-device-supply.c |   22 +++++++++++++---------
 1 files changed, 13 insertions(+), 9 deletions(-)

diff --git a/src/linux/up-device-supply.c b/src/linux/up-device-supply.c
index 341f5df..636e89f 100644
--- a/src/linux/up-device-supply.c
+++ b/src/linux/up-device-supply.c
@@ -554,16 +554,25 @@ up_device_supply_refresh_battery (UpDeviceSupply *supply)
 		supply->priv->unknown_retries = 0;
 	}
 
+	/* present voltage */
+	voltage = sysfs_get_double (native_path, "voltage_now") / 1000000.0;
+	if (voltage == 0)
+		voltage = sysfs_get_double (native_path, "voltage_avg") / 1000000.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);
+	/* 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; which is either in uVh */
+		energy_rate = fabs (sysfs_get_double (native_path, "current_now") / 1000000.0);
+		energy_rate *= voltage;
+	}
 
 	/* 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;
+		energy *= voltage;
 	}
 
 	/* some batteries don't update last_full attribute */
@@ -572,11 +581,6 @@ up_device_supply_refresh_battery (UpDeviceSupply *supply)
 		energy_full = energy;
 	}
 
-	/* present voltage */
-	voltage = sysfs_get_double (native_path, "voltage_now") / 1000000.0;
-	if (voltage == 0)
-		voltage = sysfs_get_double (native_path, "voltage_avg") / 1000000.0;
-
 	/* ACPI gives out the special 'Ones' value for rate when it's unable
 	 * to calculate the true rate. We should set the rate zero, and wait
 	 * for the BIOS to stabilise. */
-- 
1.7.2.5

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

Reply via email to