From b4c1455d39ac6e4e99ce68320fa0ee930d91624b Mon Sep 17 00:00:00 2001 From: robert Date: Sun, 6 Feb 2022 09:07:42 +0000 Subject: [PATCH] now that APM_BATT_CHARGING is also set in acpi and on some m1 devices enable support for displaying an estimate recharge time in apm(d) e.g: Battery state: charging, 95% remaining, 11 minutes recharge time estimate Battery state: charging, 97% remaining, 8 minutes recharge time estimate Battery state: charging, 98% remaining, 6 minutes recharge time estimate Battery state: charging, 99% remaining, 3 minutes recharge time estimate Battery state: charging, 99% remaining, 1 minutes recharge time estimate Battery state: charging, 99% remaining, 0 minutes recharge time estimate ok jca@ --- usr.sbin/apm/apm.c | 6 +----- usr.sbin/apmd/apmd.c | 21 ++++++--------------- 2 files changed, 7 insertions(+), 20 deletions(-) diff --git a/usr.sbin/apm/apm.c b/usr.sbin/apm/apm.c index 918a164944e..eb66acdc246 100644 --- a/usr.sbin/apm/apm.c +++ b/usr.sbin/apm/apm.c @@ -1,4 +1,4 @@ -/* $OpenBSD: apm.c,v 1.39 2022/01/12 13:09:29 robert Exp $ */ +/* $OpenBSD: apm.c,v 1.40 2022/02/06 09:07:42 robert Exp $ */ /* * Copyright (c) 1996 John T. Kohl @@ -354,7 +354,6 @@ balony: printf("\n"); if (domin && !dobstate && !dopct) { -#ifdef __powerpc__ if (reply.batterystate.battery_state == APM_BATT_CHARGING) printf("Remaining battery recharge " @@ -365,7 +364,6 @@ balony: printf("Battery life estimate: " "not available\n"); else -#endif { printf("Battery life estimate: "); if (reply.batterystate.minutes_left == @@ -376,7 +374,6 @@ balony: reply.batterystate.minutes_left); } } else if (domin) { -#ifdef __powerpc__ if (reply.batterystate.battery_state == APM_BATT_CHARGING) printf(", %d minutes recharge time estimate\n", @@ -385,7 +382,6 @@ balony: reply.batterystate.battery_life > 10) printf(", unknown life estimate\n"); else -#endif { if (reply.batterystate.minutes_left == (u_int)-1) diff --git a/usr.sbin/apmd/apmd.c b/usr.sbin/apmd/apmd.c index aaaf6b941b1..4735c6d52cb 100644 --- a/usr.sbin/apmd/apmd.c +++ b/usr.sbin/apmd/apmd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: apmd.c,v 1.106 2021/07/12 15:09:20 beck Exp $ */ +/* $OpenBSD: apmd.c,v 1.107 2022/02/06 09:07:42 robert Exp $ */ /* * Copyright (c) 1995, 1996 John T. Kohl @@ -165,26 +165,17 @@ power_status(int fd, int force, struct apm_power_info *pinfo) bstate.battery_state != last.battery_state || (bstate.minutes_left && bstate.minutes_left < 15) || abs(bstate.battery_life - last.battery_life) >= 10) { -#ifdef __powerpc__ - /* - * When the battery is charging, the estimated life - * time is in fact the estimated remaining charge time - * on Apple machines, so lie in the stats. - * We still want an useful message if the battery or - * ac status changes, however. - */ - if (bstate.minutes_left != 0 && - bstate.battery_state != APM_BATT_CHARGING) -#else if ((int)bstate.minutes_left > 0) -#endif logmsg(priority, "battery status: %s. " "external power status: %s. " - "estimated battery life %d%% (%u minutes)", + "estimated battery life %d%% " + "(%u minutes %s time estimate)", battstate(bstate.battery_state), ac_state(bstate.ac_state), bstate.battery_life, - bstate.minutes_left); + bstate.minutes_left, + (bstate.battery_state == APM_BATT_CHARGING) + ? "recharge" : "life"); else logmsg(priority, "battery status: %s. " "external power status: %s. " -- 2.20.1