diff options
author | Robert Nagy <robert@cvs.openbsd.org> | 2022-02-04 08:06:49 +0000 |
---|---|---|
committer | Robert Nagy <robert@cvs.openbsd.org> | 2022-02-04 08:06:49 +0000 |
commit | 5594be7219ee5ec12c5f9a6d20718ac62fd9066e (patch) | |
tree | ce958fa7c76c410147eb8cc307cea00a4615a5e0 /sys/dev/acpi | |
parent | 07f2dbc757cbf946e2a9c12191488e2909ca996f (diff) |
set the APM_BATT_CHARGING state if the battery is being charged and try
to calculate the remaining time to be fully charged
ok jca@
Diffstat (limited to 'sys/dev/acpi')
-rw-r--r-- | sys/dev/acpi/acpi.c | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/sys/dev/acpi/acpi.c b/sys/dev/acpi/acpi.c index 6644c52464a..57885205ae2 100644 --- a/sys/dev/acpi/acpi.c +++ b/sys/dev/acpi/acpi.c @@ -1,4 +1,4 @@ -/* $OpenBSD: acpi.c,v 1.408 2022/02/02 04:05:16 deraadt Exp $ */ +/* $OpenBSD: acpi.c,v 1.409 2022/02/04 08:06:48 robert Exp $ */ /* * Copyright (c) 2005 Thorsten Lockert <tholo@sigmasoft.com> * Copyright (c) 2005 Jordan Hargrave <jordan@openbsd.org> @@ -3580,6 +3580,9 @@ acpiioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p) remaining += min(bat->aba_softc->sc_bst.bst_capacity, bat->aba_softc->sc_bix.bix_last_capacity); + if (bat->aba_softc->sc_bst.bst_state & BST_CHARGE) + pi->battery_state = APM_BATT_CHARGING; + if (bat->aba_softc->sc_bst.bst_rate == BST_UNKNOWN) continue; else if (bat->aba_softc->sc_bst.bst_rate > 1) @@ -3615,13 +3618,19 @@ acpiioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p) break; } - if (pi->ac_state == APM_AC_ON || rate == 0) + if (rate == 0) pi->minutes_left = (unsigned int)-1; + else if (pi->battery_state == APM_BATT_CHARGING) + pi->minutes_left = 60 * (capacity - remaining) / rate; else pi->minutes_left = 60 * minutes / rate; - /* running on battery */ pi->battery_life = remaining * 100 / capacity; + + if (pi->battery_state == APM_BATT_CHARGING) + break; + + /* running on battery */ if (pi->battery_life > 50) pi->battery_state = APM_BATT_HIGH; else if (pi->battery_life > 25) |