aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDanny Kukawka <danny.kukawka@web.de>2008-03-17 18:01:03 +0100
committerDanny Kukawka <danny.kukawka@web.de>2008-03-17 18:01:03 +0100
commit5b75d2936aa5fff5754a72f9a39e0878cda903c6 (patch)
tree2abc40e26283bfe68bf35b1b9ce58d15c7a0fa70
parentfix for the acl-list patch change (diff)
downloadgentoo-hal-5b75d2936aa5fff5754a72f9a39e0878cda903c6.tar.gz
gentoo-hal-5b75d2936aa5fff5754a72f9a39e0878cda903c6.tar.bz2
gentoo-hal-5b75d2936aa5fff5754a72f9a39e0878cda903c6.zip
autofix primary (ACPI) batteries which charge with a rate > 50 W
This patch try to detect automatically broken batteries which tell that they charge a primary (Laptop) battery with a chargerate higher than 50 W (50.000 mW), which is IMO in 100% of the cases wrong for Laptop batteries. Maybe we can also assume a much lower level as criterion. To get valid remaining time values this patch set in such cases battery.remaining_time.calculate_per_time=true and calculate the remaining time based on time and the chargelevel.
-rw-r--r--hald/device_pm.c27
1 files changed, 26 insertions, 1 deletions
diff --git a/hald/device_pm.c b/hald/device_pm.c
index 63e36d9c..0d41d7bf 100644
--- a/hald/device_pm.c
+++ b/hald/device_pm.c
@@ -254,6 +254,31 @@ void
device_pm_calculate_time (HalDevice *d)
{
int time;
+ gboolean calculate_per_time;
+
+ calculate_per_time = hal_device_property_get_bool (d, "battery.remaining_time.calculate_per_time");
+
+ /* check if we may need to calculate the remaining time because of special cases */
+ if (!calculate_per_time && hal_device_property_get_bool(d, "battery.rechargeable.is_charging")) {
+ const char *type;
+ const char *unit;
+
+ type = hal_device_property_get_string(d, "battery.type");
+ if ((type != NULL) && (strcmp(type, "primary") == 0)) {
+ unit = hal_device_property_get_string(d, "battery.charge_level.unit");
+ /* check if the unit is mWh */
+ if ((unit != NULL) && (strcmp(unit, "mWh") == 0)) {
+ /* check if the rate is higher than 50 Watt, this should be wrong
+ better calculate the time based on time */
+ if (hal_device_property_get_int (d, "battery.charge_level.rate") > 50000) {
+ HAL_WARNING(("battery.charge_level.rate (%d) was > 50000 mWh, assume thats wrong, calculate from now based on time.",
+ hal_device_property_get_int (d, "battery.charge_level.rate")));
+ hal_device_property_set_bool (d, "battery.remaining_time.calculate_per_time", TRUE);
+ calculate_per_time = TRUE;
+ }
+ }
+ }
+ }
time = util_compute_time_remaining (
hal_device_get_udi (d),
@@ -262,7 +287,7 @@ device_pm_calculate_time (HalDevice *d)
hal_device_property_get_int (d, "battery.charge_level.last_full"),
hal_device_property_get_bool (d, "battery.rechargeable.is_discharging"),
hal_device_property_get_bool (d, "battery.rechargeable.is_charging"),
- hal_device_property_get_bool (d, "battery.remaining_time.calculate_per_time"));
+ calculate_per_time);
/* zero time is unknown */
if (time > 0)