From 428d16f19abc4e566df9100e8e90d599cbec9d3a Mon Sep 17 00:00:00 2001 From: sctanf <36978460+sctanf@users.noreply.github.com> Date: Thu, 16 Apr 2026 01:37:45 -0500 Subject: [PATCH] Allow 0% battery level (#1755) --- gui/src/components/commons/icon/BatteryIcon.tsx | 6 +++--- gui/src/components/tracker/TrackerBattery.tsx | 10 +++++++--- gui/src/hooks/firmware-update.ts | 3 ++- .../dev/slimevr/tracking/trackers/hid/HIDCommon.kt | 4 ++-- .../tracking/trackers/udp/TrackersUDPServer.kt | 13 ++++++++++++- 5 files changed, 26 insertions(+), 10 deletions(-) diff --git a/gui/src/components/commons/icon/BatteryIcon.tsx b/gui/src/components/commons/icon/BatteryIcon.tsx index 77311347c..150034d5c 100644 --- a/gui/src/components/commons/icon/BatteryIcon.tsx +++ b/gui/src/components/commons/icon/BatteryIcon.tsx @@ -60,15 +60,15 @@ export function BatteryIcon({ /> - + 2 ? 0 : value * 18} height="9" /> - {charging && value <= 1 && ( + {charging && (value <= 1 || value > 2) && ( )} - {charging && value > 1 && ( + {charging && value > 1 && value <= 2 && ( 1 indicate fully charged + * Values <0 or >2 (Byte was cast to UByte, so -1 -> 255) also indicate 0% */ value: number; voltage?: number | null; @@ -36,11 +38,13 @@ export function TrackerBattery({ const debug = config?.debug || config?.devSettings.moreInfo; const showVoltage = moreInfo && voltage && debug; + const pct = value > 2 ? 0 : Math.min(Math.max(value, 0), 1); + return ( {percentFormatter.format(value)} + content={percentFormatter.format(pct)} >
@@ -61,7 +65,7 @@ export function TrackerBattery({ )} {!charging && (!runtime || debug) && ( - {percentFormatter.format(value)} + {percentFormatter.format(pct)} )} {showVoltage && ( diff --git a/gui/src/hooks/firmware-update.ts b/gui/src/hooks/firmware-update.ts index 515a6a168..06c71afc1 100644 --- a/gui/src/hooks/firmware-update.ts +++ b/gui/src/hooks/firmware-update.ts @@ -152,7 +152,8 @@ export function checkForUpdate( if ( canUpdate && device.hardwareStatus?.batteryPctEstimate != null && - device.hardwareStatus.batteryPctEstimate < 50 + (device.hardwareStatus.batteryPctEstimate < 50 || + device.hardwareStatus.batteryPctEstimate > 200) ) { return 'low-battery'; } diff --git a/server/core/src/main/java/dev/slimevr/tracking/trackers/hid/HIDCommon.kt b/server/core/src/main/java/dev/slimevr/tracking/trackers/hid/HIDCommon.kt index b1be8d133..2367aea24 100644 --- a/server/core/src/main/java/dev/slimevr/tracking/trackers/hid/HIDCommon.kt +++ b/server/core/src/main/java/dev/slimevr/tracking/trackers/hid/HIDCommon.kt @@ -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 } diff --git a/server/core/src/main/java/dev/slimevr/tracking/trackers/udp/TrackersUDPServer.kt b/server/core/src/main/java/dev/slimevr/tracking/trackers/udp/TrackersUDPServer.kt index ea5c6d5ba..5bbf83174 100644 --- a/server/core/src/main/java/dev/slimevr/tracking/trackers/udp/TrackersUDPServer.kt +++ b/server/core/src/main/java/dev/slimevr/tracking/trackers/udp/TrackersUDPServer.kt @@ -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 -> {