hal: Branch 'master'

Danny Kukawka dkukawka at kemper.freedesktop.org
Mon Mar 17 10:01:16 PDT 2008


 hald/device_pm.c |   27 ++++++++++++++++++++++++++-
 1 file changed, 26 insertions(+), 1 deletion(-)

New commits:
commit 5b75d2936aa5fff5754a72f9a39e0878cda903c6
Author: Danny Kukawka <danny.kukawka at web.de>
Date:   Mon Mar 17 18:01:03 2008 +0100

    autofix primary (ACPI) batteries which charge with a rate > 50 W
    
    This patch try to detect automatically broken batteries which tell that they
    charge a primary (Laptop) battery with a chargerate higher than 50 W
    (50.000 mW), which is IMO in 100% of the cases wrong for Laptop batteries.
    Maybe we can also assume a much lower level as criterion.
    
    To get valid remaining time values this patch set in such cases
    battery.remaining_time.calculate_per_time=true and calculate the remaining
    time based on time and the chargelevel.

diff --git a/hald/device_pm.c b/hald/device_pm.c
index 63e36d9..0d41d7b 100644
--- a/hald/device_pm.c
+++ b/hald/device_pm.c
@@ -254,6 +254,31 @@ void
 device_pm_calculate_time (HalDevice *d)
 {
 	int time;
+	gboolean calculate_per_time;
+
+	calculate_per_time = hal_device_property_get_bool (d, "battery.remaining_time.calculate_per_time");
+	
+	/* check if we may need to calculate the remaining time because of special cases */
+	if (!calculate_per_time && hal_device_property_get_bool(d, "battery.rechargeable.is_charging")) {
+		const char *type;
+		const char *unit;
+
+		type = hal_device_property_get_string(d, "battery.type");
+		if ((type != NULL) && (strcmp(type, "primary") == 0)) {
+			unit = hal_device_property_get_string(d, "battery.charge_level.unit");
+			/* check if the unit is mWh */
+			if ((unit != NULL) && (strcmp(unit, "mWh") == 0)) {
+				/* check if the rate is higher than 50 Watt, this should be wrong
+				   better calculate the time based on time */
+				if (hal_device_property_get_int (d, "battery.charge_level.rate") > 50000) {
+					HAL_WARNING(("battery.charge_level.rate (%d) was > 50000 mWh, assume thats wrong, calculate from now based on time.", 
+						     hal_device_property_get_int (d, "battery.charge_level.rate")));
+					hal_device_property_set_bool (d, "battery.remaining_time.calculate_per_time", TRUE); 
+					calculate_per_time = TRUE;
+				} 
+			}
+		} 
+	}
 
 	time = util_compute_time_remaining (
 		hal_device_get_udi (d), 
@@ -262,7 +287,7 @@ device_pm_calculate_time (HalDevice *d)
 		hal_device_property_get_int (d, "battery.charge_level.last_full"),
 		hal_device_property_get_bool (d, "battery.rechargeable.is_discharging"),
 		hal_device_property_get_bool (d, "battery.rechargeable.is_charging"),
-		hal_device_property_get_bool (d, "battery.remaining_time.calculate_per_time"));
+		calculate_per_time);
 
 	/* zero time is unknown */
 	if (time > 0)


More information about the hal-commit mailing list