hal/hald/linux2 acpi.c,1.30,1.31

Danny Kukawka dkukawka at freedesktop.org
Thu Aug 11 00:10:12 PDT 2005


Update of /cvs/hal/hal/hald/linux2
In directory gabe:/tmp/cvs-serv32416/hald/linux2

Modified Files:
	acpi.c 
Log Message:
2005-08-11  Danny Kukawka <danny.kukawka at web.de>

        * hald/linux2/acpi.c: (battery_refresh_poll): Check now if computed
        remaining percentage and remaining time values are valid. Now we only
        add positive values.

        * hald/util.c: (util_compute_percentage_charge),
        (util_compute_time_remaining): Return -1 instead of 0 if an error occurs
        to differentiate between an error and an empty battery. Return now -1 if
        parameter chargeRate, chargeLevel or chargeLastFull are negative. Removed
        unneeded warning.



Index: acpi.c
===================================================================
RCS file: /cvs/hal/hal/hald/linux2/acpi.c,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -d -r1.30 -r1.31
--- acpi.c	11 Aug 2005 07:01:50 -0000	1.30
+++ acpi.c	11 Aug 2005 07:10:10 -0000	1.31
@@ -3,6 +3,7 @@
  *
  * Copyright (C) 2005 Richard Hughes <richard at hughsie.com>
  * Copyright (C) 2005 David Zeuthen, Red Hat Inc., <davidz at redhat.com>
+ * Copyright (C) 2005 Danny Kukawka, <danny.kukawka at web.de>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -79,6 +80,8 @@
 	int mwh_rate;
 	int voltage_current;
 	int voltage_design;
+	int remaining_time;
+	int remaining_percentage;
 
 	path = hal_device_property_get_string (d, "linux.acpi_path");
 	if (path == NULL)
@@ -143,26 +146,25 @@
 	}
 
 	/*
-	* Set these new mWh only keys. 
+	* Set these new mWh only keys. Only add valid keys!
 	*/
-	hal_device_property_set_int (d, "battery.charge_level.current", mwh_current);
-	hal_device_property_set_int (d, "battery.charge_level.last_full", mwh_lastfull);
-	hal_device_property_set_int (d, "battery.charge_level.rate", mwh_rate);
+	if (mwh_current >= 0) 
+		hal_device_property_set_int (d, "battery.charge_level.current", mwh_current);
+	if (mwh_lastfull >= 0)
+		hal_device_property_set_int (d, "battery.charge_level.last_full", mwh_lastfull);
+	if (mwh_rate >= 0)
+		hal_device_property_set_int (d, "battery.charge_level.rate", mwh_rate);
 
-	hal_device_property_set_int (d, "battery.remaining_time", 
-				     util_compute_time_remaining (
-					     d->udi,
-					     mwh_rate,
-					     mwh_current,
-					     mwh_lastfull,
-					     hal_device_property_get_bool (d, "battery.rechargeable.is_discharging"),
-					     hal_device_property_get_bool (d, "battery.rechargeable.is_charging")));
+	remaining_time = util_compute_time_remaining ( d->udi, mwh_rate, mwh_current, mwh_lastfull,
+					     	       hal_device_property_get_bool (d, "battery.rechargeable.is_discharging"),
+						       hal_device_property_get_bool (d, "battery.rechargeable.is_charging"));
+	remaining_percentage = util_compute_percentage_charge ( d->udi, mwh_current, mwh_lastfull);
+	
+	if (remaining_time >= 0) 
+		hal_device_property_set_int (d, "battery.remaining_time", remaining_time);
+	if (remaining_percentage >= 0)
+		hal_device_property_set_int (d, "battery.charge_level.percentage", remaining_percentage);
 
-	hal_device_property_set_int (d, "battery.charge_level.percentage", 
-				     util_compute_percentage_charge (
-					     d->udi,
-					     mwh_current,
-					     mwh_lastfull));
 out:
 	;
 }




More information about the hal-commit mailing list