hal/hald/linux2 apm.c,1.11,1.12

Richard Hughes hughsient at freedesktop.org
Fri Aug 19 12:32:22 PDT 2005


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

Modified Files:
	apm.c 
Log Message:
Add calculation of the key "battery.charge_level.percentage" so that it matches acpi.

Index: apm.c
===================================================================
RCS file: /cvs/hal/hal/hald/linux2/apm.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- apm.c	29 Jul 2005 20:32:57 -0000	1.11
+++ apm.c	19 Aug 2005 19:32:20 -0000	1.12
@@ -125,6 +125,10 @@
 battery_refresh (HalDevice *d, APMDevHandler *handler)
 {
 	const char *path;
+	int remaining_percentage;
+	int remaining_time;
+	gboolean is_charging;
+	gboolean is_discharging;
 	APMInfo i;
 
 	path = hal_device_property_get_string (d, "linux.apm_path");
@@ -167,14 +171,34 @@
 		 * instead..
 		 */
 		if (i.battery_status == BATTERY_CHARGING) {
-			hal_device_property_set_bool (d, "battery.rechargeable.is_charging", TRUE);
-			hal_device_property_set_bool (d, "battery.rechargeable.is_discharging", FALSE);
-		}
-		else {
-			hal_device_property_set_bool (d, "battery.rechargeable.is_charging", FALSE);
-			hal_device_property_set_bool (d, "battery.rechargeable.is_discharging", i.ac_line_status == FALSE);
+			is_charging = TRUE;
+			is_discharging = FALSE;
+			remaining_time = 0; /* apm doesn't give info */
+		} else {
+			is_charging = FALSE;
+			is_discharging = (i.ac_line_status == FALSE);
+			/* apm returns time in minutes, not seconds */
+			remaining_time = i.using_minutes * 60;
+			if (remaining_time < 0)
+				remaining_time = 0; 
 		}
 
+		/* set the time to discharge, or 0 for charging */
+		hal_device_property_set_int (d, "battery.remaining_time", remaining_time);
+
+		/* set the correct charge states */
+		hal_device_property_set_bool (d, "battery.rechargeable.is_charging", is_charging);
+		hal_device_property_set_bool (d, "battery.rechargeable.is_discharging", is_discharging);
+
+		/* set the percentage charge, easy. */
+		remaining_percentage = util_compute_percentage_charge (d->udi, i.battery_percentage, 100);
+	
+		/* Only set keys if no error (signified with negative return value) */
+		if (remaining_percentage > 0)
+			hal_device_property_set_int (d, "battery.charge_level.percentage", remaining_percentage);
+		else
+			hal_device_property_remove (d, "battery.charge_level.percentage");
+
 		device_property_atomic_update_end ();
 	}
 




More information about the hal-commit mailing list