diff options
author | David Zeuthen <david@fubar.dk> | 2005-05-11 17:46:32 +0000 |
---|---|---|
committer | David Zeuthen <david@fubar.dk> | 2005-05-11 17:46:32 +0000 |
commit | 019a7dff6ecff26ac255b4b08b7c6eef2bf7d085 (patch) | |
tree | a5d9aa38f8912fb9b213070ca58190fad16ed378 /hald | |
parent | 2d4fd707c9ac9aff76621e4abcf4b072d2afaad9 (diff) |
Also use the util_compute_time_remaining here
Patch from Richard Hughes <richard@hughsie.com>
New function used to calculate the time remaining for ACPI laptops as the
information is not provided.
Add code to refresh "battery.remaining_time" using the new function
util_compute_time_remaining.
Diffstat (limited to 'hald')
-rw-r--r-- | hald/linux2/acpi.c | 9 | ||||
-rw-r--r-- | hald/linux2/pmu.c | 10 | ||||
-rw-r--r-- | hald/util.c | 30 | ||||
-rw-r--r-- | hald/util.h | 2 |
4 files changed, 51 insertions, 0 deletions
diff --git a/hald/linux2/acpi.c b/hald/linux2/acpi.c index ab1fe33b..5d1fe4f4 100644 --- a/hald/linux2/acpi.c +++ b/hald/linux2/acpi.c @@ -73,6 +73,15 @@ battery_refresh_poll (HalDevice *d) "state", "remaining capacity", 0, 10, TRUE); hal_util_set_int_elem_from_file (d, "battery.charge_level.rate", path, "state", "present rate", 0, 10, TRUE); + + hal_device_property_set_int (d, "battery.remaining_time", + util_compute_time_remaining ( + d->udi, + hal_device_property_get_int (d, "battery.charge_level.rate"), + hal_device_property_get_int (d, "battery.charge_level.current"), + 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"))); } static gboolean diff --git a/hald/linux2/pmu.c b/hald/linux2/pmu.c index 97667765..64512d37 100644 --- a/hald/linux2/pmu.c +++ b/hald/linux2/pmu.c @@ -113,6 +113,16 @@ battery_refresh (HalDevice *d, PMUDevHandler *handler) else hal_device_property_set_int (d, "battery.charge_level.rate", -current); + /* TODO: could read some pmu file? */ + hal_device_property_set_int (d, "battery.remaining_time", + util_compute_time_remaining ( + d->udi, + hal_device_property_get_int (d, "battery.charge_level.rate"), + hal_device_property_get_int (d, "battery.charge_level.current"), + 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"))); + device_property_atomic_update_end (); } else { device_property_atomic_update_begin (); diff --git a/hald/util.c b/hald/util.c index 4731458b..d7292188 100644 --- a/hald/util.c +++ b/hald/util.c @@ -50,6 +50,36 @@ #include "util.h" +/** Given all the required parameters, this function will return the number + * of seconds until the battery is charged (if charging) or the number + * of seconds until empty (if discharging) + * + * @param id Optional ID given to this battery. Unused at present. + * @param chargeRate The "rate" (typically mW) + * @param chargeLevel The current charge level of the battery (typically mWh) + * @param chargeLastFull The last "full" charge of the battery (typically mWh) + * @param isDischarging If battery is discharging + * @param isCharging If battery is charging + * @return Number of seconds, or zero if n/a + */ +int +util_compute_time_remaining (const char *id, + int chargeRate, + int chargeLevel, + int chargeLastFull, + gboolean isDischarging, + gboolean isCharging) +{ + + if (chargeRate <= 0) + return 0; + if (isDischarging) + return ((double) chargeLevel / (double) chargeRate) * 60 * 60; + if (isCharging) + return ((double) (chargeLastFull - chargeLevel) / (double) chargeRate) * 60 * 60; + return 0; +} + gboolean hal_util_remove_trailing_slash (gchar *path) { diff --git a/hald/util.h b/hald/util.h index 9cb91911..21892418 100644 --- a/hald/util.h +++ b/hald/util.h @@ -29,6 +29,8 @@ #include "device.h" #include "device_store.h" +int util_compute_time_remaining (const char *id, int chargeRate, int chargeLevel, int chargeLastFull, gboolean isDischarging, gboolean isCharging); + gboolean hal_util_remove_trailing_slash (gchar *path); gboolean hal_util_get_fs_mnt_path (const gchar *fs_type, gchar *mnt_path, gsize len); |