hal/hald util.c,1.15,1.16 util.h,1.8,1.9
David Zeuthen
david at freedesktop.org
Wed May 11 10:46:34 PDT 2005
Update of /cvs/hal/hal/hald
In directory gabe:/tmp/cvs-serv14166/hald
Modified Files:
util.c util.h
Log Message:
2005-05-11 David Zeuthen <davidz at redhat.com>
* hald/linux2/pmu.c (battery_refresh): Also use the
util_compute_time_remaining here
2005-05-11 David Zeuthen <davidz at redhat.com>
Patch from Richard Hughes <richard at hughsie.com>
* hald/util.c (util_compute_time_remaining): New function
used to calculate the time remaining for ACPI laptops as the
information is not provided.
* hald/linux2/acpi.c (battery_refresh_poll): Add code to
refresh "battery.remaining_time" using the new function
util_compute_time_remaining.
Index: util.c
===================================================================
RCS file: /cvs/hal/hal/hald/util.c,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -d -r1.15 -r1.16
--- util.c 9 May 2005 03:43:26 -0000 1.15
+++ util.c 11 May 2005 17:46:32 -0000 1.16
@@ -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)
{
Index: util.h
===================================================================
RCS file: /cvs/hal/hal/hald/util.h,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- util.h 7 Mar 2005 19:08:41 -0000 1.8
+++ util.h 11 May 2005 17:46:32 -0000 1.9
@@ -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);
More information about the hal-commit
mailing list