PowerStatus: add state "Not charging"

some laptops decide to not charge a fast full battery to not consume a cycle.
In this discharging state, the current rate is zero, thus no time left can be computed.
We add a state "Not charging" to clearly differentiate and avoid user confusion.
PowerStatus was triggering low battery notifications, this is also fixed.

Change-Id: I4745c78eb0863ab01fe34cb065707d068cff0f0e
Reviewed-on: https://review.haiku-os.org/c/haiku/+/7300
Reviewed-by: Fredrik Holmqvist <fredrik.holmqvist@gmail.com>
Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org>
This commit is contained in:
Jérôme Duval 2024-01-08 21:53:58 +01:00 committed by waddlesplash
parent bb09458028
commit 96bad7685b
4 changed files with 7 additions and 0 deletions

View File

@ -30,6 +30,7 @@ const uint32 kMagicACPIBatteryID = 17822;
#define BATTERY_DISCHARGING 0x01
#define BATTERY_CHARGING 0x02
#define BATTERY_CRITICAL_STATE 0x04
#define BATTERY_NOT_CHARGING 0x08
#define BATTERY_MAX_STRING_LENGTH 32

View File

@ -106,6 +106,8 @@ ReadBatteryStatus(battery_driver_cookie* cookie,
if (batteryStatus->state == UINT32_MAX)
batteryStatus->state = BATTERY_CRITICAL_STATE;
batteryStatus->current_rate = GetUint32(pointer++);
if (batteryStatus->state == BATTERY_DISCHARGING && batteryStatus->current_rate == 0)
batteryStatus->state = BATTERY_NOT_CHARGING;
batteryStatus->capacity = GetUint32(pointer++);
batteryStatus->voltage = GetUint32(pointer++);

View File

@ -102,6 +102,8 @@ BatteryInfoView::_GetTextForLine(size_t line)
string = B_TRANSLATE("Battery charging");
else if ((fBatteryInfo.state & BATTERY_DISCHARGING) != 0)
string = B_TRANSLATE("Battery discharging");
else if ((fBatteryInfo.state & BATTERY_NOT_CHARGING) != 0)
string = B_TRANSLATE("Battery not charging");
else if ((fBatteryInfo.state & BATTERY_CRITICAL_STATE) != 0
&& fBatteryExtendedInfo.model_number[0] == '\0'
&& fBatteryExtendedInfo.serial_number[0] == '\0'

View File

@ -466,6 +466,8 @@ PowerStatusView::Update(bool force, bool notify)
state = B_TRANSLATE("charging");
else if ((fBatteryInfo.state & BATTERY_DISCHARGING) != 0)
state = B_TRANSLATE("discharging");
else if ((fBatteryInfo.state & BATTERY_NOT_CHARGING) != 0)
state = B_TRANSLATE("not charging");
if (state != NULL) {
snprintf(text + length, sizeof(text) - length, "\n%s",