hal: Branch 'master'

Danny Kukawka dkukawka at kemper.freedesktop.org
Tue Jan 15 04:52:55 PST 2008


 hald/device_pm.c |   18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)

New commits:
commit 9d81388dfa7cfa67da6e236f7912901290e4927b
Author: Danny Kukawka <danny.kukawka at web.de>
Date:   Tue Jan 15 13:51:29 2008 +0100

    fix percentage for empty batteries
    
    With commit d7144f2aa1b59f9a0acfa0daada69e2a4ffd54d8 the handling of empty
    batteries changed, which cause massive problems with multi battery machines.
    
    In the past the battery.charge_level.percentage key was removed if there where
    any problems with calculate the remaining percentage of a battery. This
    include the case where the current charge level was 0, which was/is IMO also
    wrong, since 0 is a correct value for a percentage.
    
    With the current HAL the battery get set in such cases to 100% which cause
    e.g. KPowersave to assume the battery is full and not empty, which also lead
    to wrong overall remaining percentage calculation (never reach critical
    battery levels, always over 50%) in multi battery systems, which can lead
    to crash the complete system if both batteries get empty!
    
    This patch change the code to remove the key again on problems. IMO we
    should think about change the behavior if the current charge level is really
    0 to set the percentage also to 0. The userspace tools should be able to
    handle this!

diff --git a/hald/device_pm.c b/hald/device_pm.c
index c4fee3b..1c7fe9d 100644
--- a/hald/device_pm.c
+++ b/hald/device_pm.c
@@ -205,19 +205,19 @@ device_pm_calculate_percentage (HalDevice *d)
 	int current;
 	int lastfull;
 
-	/* default to fully charge to avoid triggering low power warnings on
-	 * really broken batteries */
-	percentage = 100;
+	percentage = -1;
 
 	/* use the charge level compared to the last full amount */
 	current = hal_device_property_get_int (d, "battery.charge_level.current");
 	lastfull = hal_device_property_get_int (d, "battery.charge_level.last_full");
 
 	/* make sure we have current */
-	if (current <= 0) {
-		HAL_WARNING (("battery.charge_level.current %i, returning -1!", current));
+	if (current < 0) {
+		HAL_WARNING (("battery.charge_level.current %i, delete battery.charge_level.percentage", current));
+	} else if (current == 0) {
+		percentage = 0; /* battery is empty */
 	} else if (lastfull <= 0) {
-		HAL_WARNING (("battery.charge_level.lastfull %i, percentage returning -1!", lastfull));
+		HAL_WARNING (("battery.charge_level.lastfull %i, delete battery.charge_level.percentage", lastfull));
 	} else {
 		percentage = ((double) current / (double) lastfull) * 100;
 		/* Some bios's will report this out of range of 0..100, limit it here */
@@ -226,7 +226,11 @@ device_pm_calculate_percentage (HalDevice *d)
 		else if (percentage < 0)
 			percentage = 1;
 	}
-	hal_device_property_set_int (d, "battery.charge_level.percentage", percentage);
+
+	if (percentage < 0)
+		hal_device_property_remove (d, "battery.charge_level.percentage");
+	else 
+		hal_device_property_set_int (d, "battery.charge_level.percentage", percentage);
 }
 
 /** 


More information about the hal-commit mailing list