Allow 0% battery level (#1755)

This commit is contained in:
sctanf authored and GitHub committed 2026-04-16 08:37:45 +02:00
1 parent c8538b5521
commit 428d16f19a
5 files changed
+26 -10

No files matched your search

@@ -268,9 +268,9 @@ class HIDCommon {
}
// -1: Not known (e.g. not yet calculated after wake up, reusing known value is okay), 0: N/A (e.g. charging)
if (batt != null) {
tracker.batteryLevel = if (batt == 128) 1f else (batt and 127).toFloat()
// Server displays 0% if received 255 or -1, otherwise 0 will hide battery icon
tracker.batteryLevel = if (batt == 128) -1f else (batt and 127).toFloat()
}
// Server still won't display battery at 0% at all
if (batt_v != null) {
tracker.batteryVoltage = (batt_v.toFloat() + 245f) / 100f
}
@@ -485,7 +485,18 @@ class TrackersUDPServer(private val port: Int, name: String, private val tracker
is UDPPacket12BatteryLevel -> connection?.trackers?.values?.forEach {
it.batteryVoltage = packet.voltage
it.batteryLevel = packet.level * 100
// Firmware does not verify the voltage level at all
// Instead guess if a battery is present or not
// Too low or high voltage should mean there is no battery or there is a measurement error
// Some ESP can run at 2.3V, set a limit at 2V
// Below this the tracker is definitely dead if everything is working properly
if (packet.voltage > 2f && packet.voltage < 6f) {
// Assuming floor when converting to int
it.batteryLevel = if (packet.level < 0.01f) -1f else packet.level * 100
} else {
it.batteryLevel = 0f
}
// Server displays 0% if received 255 or -1, otherwise 0 will hide battery icon
}
is UDPPacket13Tap -> {