hal/hald util.c,1.21,1.22
Danny Kukawka
dkukawka at freedesktop.org
Thu Aug 11 00:10:12 PDT 2005
Update of /cvs/hal/hal/hald
In directory gabe:/tmp/cvs-serv32416/hald
Modified Files:
util.c
Log Message:
2005-08-11 Danny Kukawka <danny.kukawka at web.de>
* hald/linux2/acpi.c: (battery_refresh_poll): Check now if computed
remaining percentage and remaining time values are valid. Now we only
add positive values.
* hald/util.c: (util_compute_percentage_charge),
(util_compute_time_remaining): Return -1 instead of 0 if an error occurs
to differentiate between an error and an empty battery. Return now -1 if
parameter chargeRate, chargeLevel or chargeLastFull are negative. Removed
unneeded warning.
Index: util.c
===================================================================
RCS file: /cvs/hal/hal/hald/util.c,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -d -r1.21 -r1.22
--- util.c 29 Jul 2005 20:32:57 -0000 1.21
+++ util.c 11 Aug 2005 07:10:10 -0000 1.22
@@ -66,21 +66,18 @@
int percentage;
/* make sure we have chargelevel */
if (chargeLevel <= 0) {
- HAL_WARNING (("chargeLevel %i, returning 0!", chargeLevel));
- return 0;
+ HAL_WARNING (("chargeLevel %i, returning -1!", chargeLevel));
+ return -1;
}
/* make sure not division by zero */
if (chargeLastFull > 0)
percentage = ((double) chargeLevel / (double) chargeLastFull) * 100;
else {
- HAL_WARNING (("chargeLastFull %i, percentage returning 0!", chargeLastFull));
- return 0;
+ HAL_WARNING (("chargeLastFull %i, percentage returning -1!", chargeLastFull));
+ return -1;
}
/* make sure results are sensible */
- if (percentage < 0) {
- HAL_WARNING (("Percentage %i, returning 0!", percentage));
- return 0;
- } else if (percentage > 100) {
+ if (percentage > 100) {
HAL_WARNING (("Percentage %i, returning 100!", percentage));
return 100;
}
@@ -108,12 +105,19 @@
gboolean isCharging)
{
- if (chargeRate <= 0)
- return 0;
+ if ((chargeRate <= 0) || (chargeLevel < 0) || (chargeLastFull < 0)) {
+ HAL_WARNING (("chargeRate, chargeLevel or chargeLastFull unknown, returning -1"));
+ return -1;
+ }
if (isDischarging)
return ((double) chargeLevel / (double) chargeRate) * 60 * 60;
- if (isCharging)
+ if (isCharging) {
+ if(chargeLevel > chargeLastFull ) {
+ HAL_WARNING (("chargeLevel > chargeLastFull, returning -1"));
+ return -1;
+ }
return ((double) (chargeLastFull - chargeLevel) / (double) chargeRate) * 60 * 60;
+ }
return 0;
}
More information about the hal-commit
mailing list