Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/arch/macppc/dev - make the charge state sensor actually ...
details: https://anonhg.NetBSD.org/src/rev/eb4dc19ca034
branches: trunk
changeset: 781444:eb4dc19ca034
user: macallan <macallan%NetBSD.org@localhost>
date: Thu Sep 06 13:05:53 2012 +0000
description:
- make the charge state sensor actually do something
- work around a bug in envsys which expects a valid value for sensors with
states that have text descriptions even if the sensor is invalid
diffstat:
sys/arch/macppc/dev/smartbat.c | 35 +++++++++++++++++++++++++++++++----
1 files changed, 31 insertions(+), 4 deletions(-)
diffs (77 lines):
diff -r 263b87108b71 -r eb4dc19ca034 sys/arch/macppc/dev/smartbat.c
--- a/sys/arch/macppc/dev/smartbat.c Thu Sep 06 12:59:00 2012 +0000
+++ b/sys/arch/macppc/dev/smartbat.c Thu Sep 06 13:05:53 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: smartbat.c,v 1.10 2012/09/06 05:03:59 macallan Exp $ */
+/* $NetBSD: smartbat.c,v 1.11 2012/09/06 13:05:53 macallan Exp $ */
/*-
* Copyright (c) 2007 Michael Lorenz
@@ -28,7 +28,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: smartbat.c,v 1.10 2012/09/06 05:03:59 macallan Exp $");
+__KERNEL_RCSID(0, "$NetBSD: smartbat.c,v 1.11 2012/09/06 13:05:53 macallan Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -204,7 +204,8 @@
INITDATA(BAT_FULL, ENVSYS_INDICATOR, "Battery full");
#undef INITDATA
- sc->sc_bat_sensor[BAT_CHARGE_STATE].value_cur = ENVSYS_BATTERY_CAPACITY_NORMAL;
+ sc->sc_bat_sensor[BAT_CHARGE_STATE].value_cur =
+ ENVSYS_BATTERY_CAPACITY_NORMAL;
sc->sc_bat_sensor[BAT_CHARGE_STATE].state = ENVSYS_SVALID;
sc->sc_bat_sensor[BAT_CHARGING].value_cur = TRUE;
sc->sc_bat_sensor[BAT_CHARGING].state = ENVSYS_SVALID;
@@ -266,7 +267,23 @@
edata->value_cur = 0;
break;
case BAT_CHARGE_STATE:
- edata->value_cur = ENVSYS_BATTERY_CAPACITY_NORMAL;
+ {
+ int ch = sc->sc_max_charge * 100 /
+ sc->sc_charge;
+ if (ch < 6) {
+ edata->value_cur =
+ ENVSYS_BATTERY_CAPACITY_CRITICAL;
+ } else if (ch < 11) {
+ edata->value_cur =
+ ENVSYS_BATTERY_CAPACITY_WARNING;
+ } else if (ch < 20) {
+ edata->value_cur =
+ ENVSYS_BATTERY_CAPACITY_LOW;
+ } else {
+ edata->value_cur =
+ ENVSYS_BATTERY_CAPACITY_NORMAL;
+ }
+ }
break;
case BAT_FULL:
edata->value_cur = (sc->sc_flags & PMU_PWR_BATT_FULL);
@@ -280,6 +297,14 @@
edata->value_cur = present;
edata->state = ENVSYS_SVALID;
break;
+ case BAT_CHARGE_STATE:
+ /*
+ * envsys crashes if this isn't a valid value even
+ * when the sensor itself is invalid
+ */
+ edata->value_cur = ENVSYS_BATTERY_CAPACITY_NORMAL;
+ edata->state = ENVSYS_SINVALID;
+ break;
default:
edata->state = ENVSYS_SINVALID;
edata->value_cur = 0;
@@ -299,6 +324,8 @@
edata->value_cur = (sc->sc_flags & PMU_PWR_AC_PRESENT);
edata->state = ENVSYS_SVALID;
break;
+ default:
+ edata->state = ENVSYS_SINVALID;
}
}
Home |
Main Index |
Thread Index |
Old Index