hal: Branch 'master'

Richard Hughes hughsient at kemper.freedesktop.org
Thu Aug 24 00:03:42 PDT 2006


 doc/spec/hal-spec-properties.xml  |   20 ++++++++++++++++++--
 hald/linux/acpi.c                 |   15 +++++++++++++--
 hald/linux/addons/Makefile.am     |    4 ++--
 hald/linux/addons/addon-hid-ups.c |   10 +++++++++-
 hald/linux/apm.c                  |    1 +
 hald/linux/pmu.c                  |    1 +
 hald/util_pm.c                    |   33 +++++++++++++++++++++++++++++++++
 hald/util_pm.h                    |    2 ++
 8 files changed, 79 insertions(+), 7 deletions(-)

New commits:
diff-tree bacb7b433d27381efd490b6e8bd6a3be4a8e6e92 (from 39024923e8920736221f28bb01d8ade84a0afd2e)
Author: Richard Hughes <richard at hughsie.com>
Date:   Thu Aug 24 08:03:33 2006 +0100

    modify battery.technology to one of a few present values
    
    API is compatible, as the key battery.technology is now the sanitised
    key, and battery.reporting.technology is the key that is the reported
    key for the hardware, similar to what we do with the charge level.

diff --git a/doc/spec/hal-spec-properties.xml b/doc/spec/hal-spec-properties.xml
index 18f383b..72c2b33 100644
--- a/doc/spec/hal-spec-properties.xml
+++ b/doc/spec/hal-spec-properties.xml
@@ -5045,12 +5045,28 @@
             </row>
             <row>
               <entry>
-                <literal>battery.technology</literal> (string)
+                <literal>battery.reporting.technology</literal> (string)
               </entry>
               <entry>example: LION</entry>
               <entry>No</entry>
               <entry>
-                The technology of the battery.
+                The technology of the battery as reported by the hardware.
+              </entry>
+            </row>
+            <row>
+              <entry>
+                <literal>battery.technology</literal> (string)
+              </entry>
+              <entry>
+                lead-acid, lithium-ion, lithium-polymer,
+                nickel-metal-hydride, unknown
+              </entry>
+              <entry>No</entry>
+              <entry>
+                The technology of the battery processed to a few standard types.
+                This key is needed as the hardware often does not specify the
+                description text for a battery, and so we have to calculate it
+                from the output of <literal>battery.reporting.technology</literal>.
               </entry>
             </row>
             <row>
diff --git a/hald/linux/acpi.c b/hald/linux/acpi.c
index 4274d77..eae5c51 100644
--- a/hald/linux/acpi.c
+++ b/hald/linux/acpi.c
@@ -408,6 +408,7 @@ battery_refresh_remove (HalDevice *d)
 	hal_device_property_remove (d, "battery.vendor");
 	hal_device_property_remove (d, "battery.model");
 	hal_device_property_remove (d, "battery.serial");
+	hal_device_property_remove (d, "battery.reporting.technology");
 	hal_device_property_remove (d, "battery.technology");
 	hal_device_property_remove (d, "battery.vendor");
 	hal_device_property_remove (d, "battery.charge_level.unit");
@@ -454,6 +455,7 @@ battery_refresh_add (HalDevice *d, const
 	int voltage_design;
 
 	const char *reporting_unit;
+	const char *technology;
 
 	hal_util_set_string_elem_from_file (d, "battery.vendor", path, "info",
 					    "OEM info", 0, TRUE);
@@ -461,11 +463,20 @@ battery_refresh_add (HalDevice *d, const
 					    "model number", 0, TRUE);
 	hal_util_set_string_elem_from_file (d, "battery.serial", path, "info",
 					    "serial number", 0, TRUE);
-	hal_util_set_string_elem_from_file (d, "battery.technology", path, "info",
-					    "battery type", 0, TRUE);
 	hal_util_set_string_elem_from_file (d, "battery.vendor", path, "info",
 					    "OEM info", 0, TRUE);
 
+	/* This is needed as ACPI does not specify the description text for a
+	 *  battery, and so we have to calculate it from the hardware output */
+	technology = hal_util_grep_string_elem_from_file (path, "info",
+							  "battery type", 0, TRUE);
+	if (technology != NULL) {
+		hal_device_property_set_string (d, "battery.reporting.technology",
+						technology);
+		hal_device_property_set_string (d, "battery.technology",
+						util_get_battery_technology (technology));
+	}
+
 	/*
 	 * we'll use the .reporting prefix as we don't know
 	 * if this data is energy (mWh) or unit enery (mAh)
diff --git a/hald/linux/addons/Makefile.am b/hald/linux/addons/Makefile.am
index 63e2d60..83c2703 100644
--- a/hald/linux/addons/Makefile.am
+++ b/hald/linux/addons/Makefile.am
@@ -36,8 +36,8 @@ hald_addon_acpi_LDADD = $(top_builddir)/
 hald_addon_acpi_buttons_toshiba_SOURCES = addon-acpi-buttons-toshiba.c ../../logger.c ../../util_helper.c
 hald_addon_acpi_buttons_toshiba_LDADD = $(top_builddir)/libhal/libhal.la @GLIB_LIBS@
 
-hald_addon_hid_ups_SOURCES = addon-hid-ups.c ../../logger.c ../../util_helper.c
-hald_addon_hid_ups_LDADD = $(top_builddir)/libhal/libhal.la 
+hald_addon_hid_ups_SOURCES = addon-hid-ups.c ../../logger.c ../../util_helper.c ../../util_pm.c
+hald_addon_hid_ups_LDADD = $(top_builddir)/libhal/libhal.la @GLIB_LIBS@
 
 hald_addon_keyboard_SOURCES = addon-keyboard.c ../../logger.c ../../util_helper.c
 hald_addon_keyboard_LDADD = $(top_builddir)/libhal/libhal.la 
diff --git a/hald/linux/addons/addon-hid-ups.c b/hald/linux/addons/addon-hid-ups.c
index 1361ed6..64677d8 100644
--- a/hald/linux/addons/addon-hid-ups.c
+++ b/hald/linux/addons/addon-hid-ups.c
@@ -46,9 +46,12 @@
 #include <sys/ioctl.h>
 #include <unistd.h>
 
+#include <glib.h>
+
 #include "libhal/libhal.h"
 
 #include "../../util_helper.h"
+#include "../../util_pm.h"
 #include "../../logger.h"
 
 #define UPS_USAGE		0x840000
@@ -125,6 +128,7 @@ ups_get_static (LibHalContext *ctx, cons
 	struct hiddev_usage_ref uref;
 	int rtype;
 	unsigned int i, j;
+	char *type;
 	DBusError error;
 
 	/* set to failure */
@@ -200,9 +204,13 @@ ups_get_static (LibHalContext *ctx, cons
 						break;
 
 					case UPS_CHEMISTRY:
+						type = ups_get_string (fd, uref.value);
+						libhal_device_set_property_string (
+							ctx, udi, "battery.reporting.technology", 
+							type, &error);
 						libhal_device_set_property_string (
 							ctx, udi, "battery.technology", 
-							ups_get_string (fd, uref.value), &error);
+							util_get_battery_technology (type), &error);
 						break;
 
 					case UPS_RECHARGEABLE:
diff --git a/hald/linux/apm.c b/hald/linux/apm.c
index e855438..a11148f 100644
--- a/hald/linux/apm.c
+++ b/hald/linux/apm.c
@@ -138,6 +138,7 @@ battery_refresh (HalDevice *d, APMDevHan
 
 	hal_device_property_set_string (d, "info.product", "Battery Bay");
 	hal_device_property_set_string (d, "battery.type", "primary");
+	hal_device_property_set_string (d, "battery.technology", "unknown");
 	hal_device_property_set_string (d, "info.category", "battery");
 	hal_device_add_capability (d, "battery");
 
diff --git a/hald/linux/pmu.c b/hald/linux/pmu.c
index 892fff1..3febe82 100644
--- a/hald/linux/pmu.c
+++ b/hald/linux/pmu.c
@@ -87,6 +87,7 @@ battery_refresh (HalDevice *d, PMUDevHan
 
 	hal_device_property_set_string (d, "info.product", "Battery Bay");
 	hal_device_property_set_string (d, "battery.type", "primary");
+	hal_device_property_set_string (d, "battery.technology", "unknown");
 	hal_device_property_set_string (d, "info.category", "battery");
 	hal_device_add_capability (d, "battery");
 
diff --git a/hald/util_pm.c b/hald/util_pm.c
index 6b613b1..0bc62e8 100644
--- a/hald/util_pm.c
+++ b/hald/util_pm.c
@@ -44,6 +44,39 @@ typedef struct {
 
 GHashTable *saved_battery_info = NULL;
 
+/** Convert the hardware reported value into a few sane choices
+ *
+ *  This is needed as ACPI does not specify the description text for a
+ *  battery, and so we have to calculate it from the hardware output
+ *
+ *  @param  type                The battery type recieved from the hardware
+ *  @return                     The battery technology which is one of:
+ *                              unknown, lithium-ion or lead-acid
+ */
+const char *
+util_get_battery_technology (const char *type)
+{
+	if (type == NULL) {
+		return "unknown";
+	}
+	/* every case combination of Li-Ion is commonly used.. */
+	if (strcasecmp (type, "li-ion") == 0 ||
+	    strcasecmp (type, "lion") == 0) {
+		return "lithium-ion";
+	}
+	if (strcasecmp (type, "pb") == 0 ||
+	    strcasecmp (type, "pbac") == 0) {
+		return "lead-acid";
+	}
+	if (strcasecmp (type, "lip") == 0) {
+		return "lithium-polymer";
+	}
+	if (strcasecmp (type, "nimh") == 0) {
+		return "nickel-metal-hydride";
+	}
+	return "unknown";
+}
+
 /** Given all the required parameters, this function will return the percentage
  *  charge remaining. There are lots of checks here as ACPI is often broken.
  *
diff --git a/hald/util_pm.h b/hald/util_pm.h
index 92ddef4..977531e 100644
--- a/hald/util_pm.h
+++ b/hald/util_pm.h
@@ -27,6 +27,8 @@
 #ifndef UTIL_PM_H
 #define UTIL_PM_H
 
+const char *util_get_battery_technology (const char *type);
+
 int util_compute_time_remaining (const char *id, int chargeRate, int chargeLevel, int chargeLastFull, 
 				 gboolean isDischarging, gboolean isCharging, gboolean guessChargeRate);
 



More information about the hal-commit mailing list