Compare commits

...

6 Commits

Author SHA1 Message Date
sctanf
6823cd6b48 Make 0% battery check consistent 2026-04-03 01:55:30 -05:00
sctanf
6125a4b989 Check for >200 (0%) where batteryPctEstimate is used 2026-04-02 21:43:16 -05:00
sctanf
ff35a844c1 Move comment 2026-02-26 14:12:44 -06:00
sctanf
24df308933 Account for cast to UByte 2026-02-26 14:12:43 -06:00
sctanf
7c284e1e85 Fix compilation 2026-02-26 14:12:41 -06:00
sctanf
232985b793 Allow 0% battery level 2026-02-26 14:12:39 -06:00
5 changed files with 26 additions and 10 deletions

View File

@@ -60,15 +60,15 @@ export function BatteryIcon({
/>
</mask>
<g mask="url(#mask0_4_39)" className={classNames(col, 'opacity-100')}>
<rect width={charging ? 18 : value * 18} height="9" />
<rect width={charging ? 18 : value > 2 ? 0 : value * 18} height="9" />
</g>
{charging && value <= 1 && (
{charging && (value <= 1 || value > 2) && (
<path
d="M 7.7638355,8.4189633 8.0112251,4.9834646 5.7712838,4.9834645 8.5644084,0.07977871 8.3170195,3.5152773 H 10.55696 Z"
fill="#081e30"
/>
)}
{charging && value > 1 && (
{charging && value > 1 && value <= 2 && (
<path
d="M 5.5342464,4.6225095 C 6.1777799,5.0106205 6.6131537,5.2516456 7.5253371,6.545223 8.4340868,4.4016445 8.7809738,3.661475 10.605195,1.5520288"
fill="none"

View File

@@ -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 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 (
<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 && (

View File

@@ -151,7 +151,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';
}

View File

@@ -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
}

View File

@@ -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 -> {