From bacb7b433d27381efd490b6e8bd6a3be4a8e6e92 Mon Sep 17 00:00:00 2001 From: Richard Hughes Date: Thu, 24 Aug 2006 08:03:33 +0100 Subject: 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. --- 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(-) diff --git a/doc/spec/hal-spec-properties.xml b/doc/spec/hal-spec-properties.xml index 18f383b1..72c2b336 100644 --- a/doc/spec/hal-spec-properties.xml +++ b/doc/spec/hal-spec-properties.xml @@ -5045,12 +5045,28 @@ - battery.technology (string) + battery.reporting.technology (string) example: LION No - The technology of the battery. + The technology of the battery as reported by the hardware. + + + + + battery.technology (string) + + + lead-acid, lithium-ion, lithium-polymer, + nickel-metal-hydride, unknown + + No + + 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 battery.reporting.technology. diff --git a/hald/linux/acpi.c b/hald/linux/acpi.c index 4274d77e..eae5c51a 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 char *path) 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 char *path) "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 63e2d603..83c27039 100644 --- a/hald/linux/addons/Makefile.am +++ b/hald/linux/addons/Makefile.am @@ -36,8 +36,8 @@ hald_addon_acpi_LDADD = $(top_builddir)/libhal/libhal.la 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 1361ed6d..64677d8b 100644 --- a/hald/linux/addons/addon-hid-ups.c +++ b/hald/linux/addons/addon-hid-ups.c @@ -46,9 +46,12 @@ #include #include +#include + #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, const char *udi, int fd) 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, const char *udi, int fd) 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 e8554382..a11148f6 100644 --- a/hald/linux/apm.c +++ b/hald/linux/apm.c @@ -138,6 +138,7 @@ battery_refresh (HalDevice *d, APMDevHandler *handler) 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 892fff14..3febe822 100644 --- a/hald/linux/pmu.c +++ b/hald/linux/pmu.c @@ -87,6 +87,7 @@ battery_refresh (HalDevice *d, PMUDevHandler *handler) 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 6b613b1d..0bc62e81 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 92ddef46..977531e9 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); -- cgit v1.2.3