mirror of
https://github.com/SlimeVR/SlimeVR-Server.git
synced 2026-04-06 02:01:58 +02:00
Allow 0% battery level
This commit is contained in:
@@ -13,7 +13,9 @@ export function TrackerBattery({
|
||||
textColor = 'primary',
|
||||
}: {
|
||||
/**
|
||||
* a [0, 1] value range is expected
|
||||
* Normally [0, 1] value range
|
||||
* Values >1 indicate fully charged
|
||||
* Values <0 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 = Math.min(Math.max(value, 0), 1);
|
||||
|
||||
return (
|
||||
<Tooltip
|
||||
disabled={charging || !runtime || debug}
|
||||
preferedDirection="left"
|
||||
content=<Typography>{percentFormatter.format(value)}</Typography>
|
||||
content=<Typography>{percentFormatter.format(pct)}</Typography>
|
||||
>
|
||||
<div className="flex gap-2">
|
||||
<div className="flex flex-col justify-around">
|
||||
@@ -61,7 +65,7 @@ export function TrackerBattery({
|
||||
)}
|
||||
{!charging && (!runtime || debug) && (
|
||||
<Typography color={textColor}>
|
||||
{percentFormatter.format(value)}
|
||||
{percentFormatter.format(pct)}
|
||||
</Typography>
|
||||
)}
|
||||
{showVoltage && (
|
||||
|
||||
@@ -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()
|
||||
tracker.batteryLevel = if (batt == 128) -1f else (batt and 127).toFloat()
|
||||
}
|
||||
// Server still won't display battery at 0% at all
|
||||
// Server displays 0% if received 255 or -1, otherwise 0 will hide battery icon
|
||||
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 (it.batteryVoltage > 2f && it.batteryVoltage < 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 -> {
|
||||
|
||||
Reference in New Issue
Block a user