hal: Branch 'master'
Danny Kukawka
dkukawka at kemper.freedesktop.org
Tue Jan 29 10:12:03 PST 2008
hald/linux/device.c | 29 +++++++++++++++--------------
1 file changed, 15 insertions(+), 14 deletions(-)
New commits:
commit 0de960db93ab36c862182bf6ed2536b9fe5afa41
Author: Danny Kukawka <danny.kukawka at web.de>
Date: Tue Jan 29 19:11:02 2008 +0100
fixed refresh_battery_fast() for power_supply devices
Fixed refresh_battery_fast() for power_supply devices:
- reworked logic to get the reporting unit for the device and
prevent set battery.reporting.unit again, if not needed because
it is already set
- removed battery.charge_level.rate again, they get set somewhere
else.
diff --git a/hald/linux/device.c b/hald/linux/device.c
index 270ef5a..b490b6f 100644
--- a/hald/linux/device.c
+++ b/hald/linux/device.c
@@ -3013,8 +3013,7 @@ refresh_battery_fast (HalDevice *d)
gint value_last_full = 0;
gint value_full_design = 0;
gboolean present = FALSE;
- gboolean could_be_mah = TRUE;
- gboolean could_be_mwh = TRUE;
+ gboolean unknown_unit = TRUE;
gboolean is_mah = FALSE;
gboolean is_mwh = FALSE;
gboolean is_charging = FALSE;
@@ -3059,11 +3058,9 @@ refresh_battery_fast (HalDevice *d)
/* CURRENT: we prefer the average if it exists, although present is still pretty good */
if (!hal_util_get_int_from_file (path, "current_avg", ¤t, 10)) {
- hal_device_property_set_int (d, "battery.reporting.rate", current);
- hal_device_property_set_int (d, "battery.charge_level.rate", current / 1000);
+ hal_device_property_set_int (d, "battery.reporting.rate", current / 1000);
} else if (hal_util_get_int_from_file (path, "current_now", ¤t, 10)) {
- hal_device_property_set_int (d, "battery.reporting.rate", current);
- hal_device_property_set_int (d, "battery.charge_level.rate", current / 1000);
+ hal_device_property_set_int (d, "battery.reporting.rate", current / 1000);
}
/* STATUS: Convert to charging/discharging state */
@@ -3097,14 +3094,16 @@ refresh_battery_fast (HalDevice *d)
reporting_unit = hal_device_property_get_string (d, "battery.reporting.unit");
if (reporting_unit != NULL) {
if (strcasecmp (reporting_unit, "mah") == 0) {
- could_be_mwh = FALSE;
+ is_mah = TRUE;
+ unknown_unit = FALSE;
} else if (strcasecmp (reporting_unit, "mwh") == 0) {
- could_be_mah = FALSE;
+ is_mah = TRUE;
+ unknown_unit = FALSE;
}
}
/* ENERGY (reported in uWh, so need to convert to mWh) */
- if (could_be_mwh) {
+ if (unknown_unit || is_mwh) {
if (hal_util_get_int_from_file (path, "energy_avg", &value_now, 10)) {
hal_device_property_set_int (d, "battery.reporting.current", value_now / 1000);
is_mwh = TRUE;
@@ -3123,7 +3122,7 @@ refresh_battery_fast (HalDevice *d)
}
/* CHARGE (reported in uAh, so need to convert to mAh) */
- if (could_be_mah) {
+ if ((unknown_unit && !is_mwh) || is_mah) {
if (hal_util_get_int_from_file (path, "charge_avg", &value_now, 10)) {
hal_device_property_set_int (d, "battery.reporting.current", value_now / 1000);
is_mah = TRUE;
@@ -3142,10 +3141,12 @@ refresh_battery_fast (HalDevice *d)
}
/* record these for future savings */
- if (is_mwh == TRUE) {
- hal_device_property_set_string (d, "battery.reporting.unit", "mWh");
- } else if (is_mah == TRUE) {
- hal_device_property_set_string (d, "battery.reporting.unit", "mAh");
+ if (unknown_unit) {
+ if (is_mwh == TRUE) {
+ hal_device_property_set_string (d, "battery.reporting.unit", "mWh");
+ } else if (is_mah == TRUE) {
+ hal_device_property_set_string (d, "battery.reporting.unit", "mAh");
+ }
}
/* we've now got the 'reporting' keys, now we need to populate the
More information about the hal-commit
mailing list