mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge.git
synced 2026-07-31 07:44:24 +02:00
oppo: Reset missing battery states to UNKNOWN for UI
This commit is contained in:
+20
@@ -240,6 +240,10 @@ public class OppoHeadphonesProtocol extends GBDeviceProtocol {
|
||||
}
|
||||
|
||||
final int batteryLevel = payload[i + 1] & 0x7f;
|
||||
if (batteryIndex == 2 && batteryLevel == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
final BatteryState batteryState = (payload[i + 1] & 0x80) != 0 ? BatteryState.BATTERY_CHARGING : BatteryState.BATTERY_NORMAL;
|
||||
|
||||
LOG.debug("Got battery {}: {}%, {}", batteryIndex, batteryLevel, batteryState);
|
||||
@@ -251,6 +255,22 @@ public class OppoHeadphonesProtocol extends GBDeviceProtocol {
|
||||
events.add(eventBatteryInfo);
|
||||
}
|
||||
|
||||
List<Integer> processedBatteries = events.stream()
|
||||
.map(event -> ((GBDeviceEventBatteryInfo) event).batteryIndex)
|
||||
.toList();
|
||||
|
||||
for (int i = 0; i < 2; i++) {
|
||||
if (processedBatteries.contains(i)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
final GBDeviceEventBatteryInfo eventBatteryInfo = new GBDeviceEventBatteryInfo();
|
||||
eventBatteryInfo.batteryIndex = i;
|
||||
eventBatteryInfo.level = -1;
|
||||
eventBatteryInfo.state = BatteryState.UNKNOWN;
|
||||
events.add(eventBatteryInfo);
|
||||
}
|
||||
|
||||
return events;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user