Fix tracker battery display when UDP tracker only sends level (#1850)

This commit is contained in:
Sapphire authored and loucass003 committed 2026-05-19 19:10:54 +02:00
1 parent 1006b32e83
commit 81a46c2ea5
2 files changed
+12 -9

No files matched your search

@@ -490,11 +490,15 @@ class TrackersUDPServer(private val port: Int, name: String, private val tracker
// 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
if (packet.voltage != null) {
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
}
} else {
it.batteryLevel = 0f
it.batteryLevel = packet.level * 100
}
// Server displays 0% if received 255 or -1, otherwise 0 will hide battery icon
}
@@ -186,17 +186,16 @@ data class UDPPacket11Serial(var serial: String = "") : UDPPacket(11) {
}
data class UDPPacket12BatteryLevel(
var voltage: Float = 0.0f,
var voltage: Float? = null,
var level: Float = 0.0f,
) : UDPPacket(12) {
override fun readData(buf: ByteBuffer) {
voltage = UDPUtils.getSafeBufferFloat(buf)
if (buf.remaining() > 3) {
if (buf.remaining() >= 8) {
voltage = UDPUtils.getSafeBufferFloat(buf)
level = UDPUtils.getSafeBufferFloat(buf)
} else {
level = voltage
voltage = 0.0f
level = UDPUtils.getSafeBufferFloat(buf)
}
}
}