summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOtto Moerbeek <otto@cvs.openbsd.org>2010-02-28 09:40:07 +0000
committerOtto Moerbeek <otto@cvs.openbsd.org>2010-02-28 09:40:07 +0000
commit4072769f702c39c334ae5d52234800df144939a0 (patch)
tree2292a0e44b62672c990026f5394ba40b8f0b8f86
parent81c1c0f5953f4ecf37dae7a7b8f7dc4fa82bb4ae (diff)
Bring battery life estimate when charging in line with most other apm(4)
devices. Original code was inspired by/copied/stolen from the macppc apm(4), which has different semantics for battery life while charging.
-rw-r--r--sys/arch/loongson/dev/kb3310.c52
1 files changed, 24 insertions, 28 deletions
diff --git a/sys/arch/loongson/dev/kb3310.c b/sys/arch/loongson/dev/kb3310.c
index 38d1842dbbb..a3b78386cfc 100644
--- a/sys/arch/loongson/dev/kb3310.c
+++ b/sys/arch/loongson/dev/kb3310.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kb3310.c,v 1.5 2010/02/28 08:30:27 otto Exp $ */
+/* $OpenBSD: kb3310.c,v 1.6 2010/02/28 09:40:06 otto Exp $ */
/*
* Copyright (c) 2010 Otto Moerbeek <otto@drijf.net>
*
@@ -306,35 +306,31 @@ ykbec_refresh(void *arg)
ykbec_apmdata.minutes_left = 0;
ykbec_apmdata.battery_life = 0;
} else {
- /* if charging, return the minutes until full */
- if (bat_state & BAT_STATE_CHARGING) {
+ if (bat_state & BAT_STATE_CHARGING)
ykbec_apmdata.battery_state = APM_BATT_CHARGING;
- if (current > 0) {
- fullcap = (100 - cap_pct) * 60 * fullcap / 100;
- ykbec_apmdata.minutes_left = fullcap / current;
- } else
- ykbec_apmdata.minutes_left = 0;
- } else {
- /* arbitrary */
- if (cap_pct > 60)
- ykbec_apmdata.battery_state = APM_BATT_HIGH;
- else if (cap_pct < 10)
- ykbec_apmdata.battery_state = APM_BATT_CRITICAL;
- else
- ykbec_apmdata.battery_state = APM_BATT_LOW;
-
+ /* XXX arbitrary */
+ else if (cap_pct > 60)
+ ykbec_apmdata.battery_state = APM_BATT_HIGH;
+ else if (cap_pct < 10)
+ ykbec_apmdata.battery_state = APM_BATT_CRITICAL;
+ else
+ ykbec_apmdata.battery_state = APM_BATT_LOW;
+
+ /* if charging, current is positive */
+ if (bat_state & BAT_STATE_CHARGING)
+ current = 0;
+ else
current = -current;
- /* Yeeloong draw is about 1A */
- if (current <= 0)
- current = 1000;
- /* at 5?%, the Yeeloong shuts down */
- if (cap_pct <= 5)
- cap_pct = 0;
- else
- cap_pct -= 5;
- fullcap = cap_pct * 60 * fullcap / 100;
- ykbec_apmdata.minutes_left = fullcap / current;
- }
+ /* XXX Yeeloong draw is about 1A */
+ if (current <= 0)
+ current = 1000;
+ /* XXX at 5?%, the Yeeloong shuts down */
+ if (cap_pct <= 5)
+ cap_pct = 0;
+ else
+ cap_pct -= 5;
+ fullcap = cap_pct * 60 * fullcap / 100;
+ ykbec_apmdata.minutes_left = fullcap / current;
}
if (old.ac_state != ykbec_apmdata.ac_state)