From 9b907fdec4b3550efe93cccb32afe7ab60f815e2 Mon Sep 17 00:00:00 2001 From: Tim Gromeyer <58736434+tim-gromeyer@users.noreply.github.com> Date: Thu, 5 Jun 2025 09:16:04 +0200 Subject: [PATCH] [Linux] Fix battery sometimes showing 127% (#143) --- linux/battery.hpp | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/linux/battery.hpp b/linux/battery.hpp index 64395fd..ba57107 100644 --- a/linux/battery.hpp +++ b/linux/battery.hpp @@ -4,6 +4,7 @@ #include #include #include +#include #include "airpods_packets.h" @@ -152,20 +153,17 @@ public: auto [isRightCharging, rawRightBattery] = formatBattery(rawRightBatteryByte); auto [isCaseCharging, rawCaseBattery] = formatBattery(rawCaseBatteryByte); - // If raw byte is 0xFF or (0x7F and charging), use the last known level - if (rawLeftBatteryByte == 0xFF || (rawLeftBatteryByte == 0x7F && isLeftCharging)) { - rawLeftBatteryByte = states.value(Component::Left).level; // Use last valid level + if (rawLeftBattery == CHAR_MAX) { + rawLeftBattery = states.value(Component::Left).level; // Use last valid level isLeftCharging = states.value(Component::Left).status == BatteryStatus::Charging; } - // If raw byte is 0xFF or (0x7F and charging), use the last known level - if (rawRightBatteryByte == 0xFF || (rawRightBatteryByte == 0x7F && isRightCharging)) { + if (rawRightBattery == CHAR_MAX) { rawRightBattery = states.value(Component::Right).level; // Use last valid level isRightCharging = states.value(Component::Right).status == BatteryStatus::Charging; } - // If raw byte is 0xFF or (0x7F and charging), use the last known level - if (rawCaseBatteryByte == 0xFF || (rawCaseBatteryByte == 0x7F && isCaseCharging)) { + if (rawCaseBattery == CHAR_MAX) { rawCaseBattery = states.value(Component::Case).level; // Use last valid level isCaseCharging = states.value(Component::Case).status == BatteryStatus::Charging; }