Skip to content

Commit 9b907fd

Browse files
authored
[Linux] Fix battery sometimes showing 127% (#143)
1 parent 43d7034 commit 9b907fd

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

linux/battery.hpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <QMap>
55
#include <QString>
66
#include <QObject>
7+
#include <climits>
78

89
#include "airpods_packets.h"
910

@@ -152,20 +153,17 @@ class Battery : public QObject
152153
auto [isRightCharging, rawRightBattery] = formatBattery(rawRightBatteryByte);
153154
auto [isCaseCharging, rawCaseBattery] = formatBattery(rawCaseBatteryByte);
154155

155-
// If raw byte is 0xFF or (0x7F and charging), use the last known level
156-
if (rawLeftBatteryByte == 0xFF || (rawLeftBatteryByte == 0x7F && isLeftCharging)) {
157-
rawLeftBatteryByte = states.value(Component::Left).level; // Use last valid level
156+
if (rawLeftBattery == CHAR_MAX) {
157+
rawLeftBattery = states.value(Component::Left).level; // Use last valid level
158158
isLeftCharging = states.value(Component::Left).status == BatteryStatus::Charging;
159159
}
160160

161-
// If raw byte is 0xFF or (0x7F and charging), use the last known level
162-
if (rawRightBatteryByte == 0xFF || (rawRightBatteryByte == 0x7F && isRightCharging)) {
161+
if (rawRightBattery == CHAR_MAX) {
163162
rawRightBattery = states.value(Component::Right).level; // Use last valid level
164163
isRightCharging = states.value(Component::Right).status == BatteryStatus::Charging;
165164
}
166165

167-
// If raw byte is 0xFF or (0x7F and charging), use the last known level
168-
if (rawCaseBatteryByte == 0xFF || (rawCaseBatteryByte == 0x7F && isCaseCharging)) {
166+
if (rawCaseBattery == CHAR_MAX) {
169167
rawCaseBattery = states.value(Component::Case).level; // Use last valid level
170168
isCaseCharging = states.value(Component::Case).status == BatteryStatus::Charging;
171169
}

0 commit comments

Comments
 (0)