Skip to content
Merged

Runtime #1678

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 46 additions & 23 deletions gui/src/components/tracker/TrackerBattery.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,24 @@ import { useConfig } from '@/hooks/config';
import { useLocaleConfig } from '@/i18n/config';
import { BatteryIcon } from '@/components/commons/icon/BatteryIcon';
import { Typography } from '@/components/commons/Typography';
import { Tooltip } from '@/components/commons/Tooltip';

export function TrackerBattery({
value,
voltage,
runtime,
disabled,
moreInfo = false,
textColor = 'primary',
}: {
/**
* a [0, 1] value range is expected
*/
value: number;
voltage?: number | null;
runtime?: bigint | null;
disabled?: boolean;
moreInfo?: boolean;
textColor?: string;
}) {
const { currentLocales } = useLocaleConfig();
Expand All @@ -28,31 +33,49 @@ export function TrackerBattery({
});

const charging = (voltage || 0) > 4.3;
const showVoltage = voltage && config?.debug;
const debug = config?.debug || config?.devSettings.moreInfo;
const showVoltage = moreInfo && voltage && debug;

return (
<div className="flex gap-2">
<div className="flex flex-col justify-around">
<BatteryIcon value={value} disabled={disabled} charging={charging} />
</div>
{((!charging || showVoltage) && (
<div className="w-10">
{!charging && (
<Typography color={textColor}>
{percentFormatter.format(value)}
</Typography>
)}
{showVoltage && (
<Typography color={textColor}>
{voltageFormatter.format(voltage)}V
</Typography>
)}
</div>
)) || (
<div className="flex flex-col justify-center w-10">
<div className="w-5 h-1 bg-background-30 rounded-full" />
<Tooltip
disabled={!charging && (!runtime || debug)}
preferedDirection="left"
content=<Typography>{percentFormatter.format(value)}</Typography>
>
<div className="flex gap-2">
<div className="flex flex-col justify-around">
<BatteryIcon value={value} disabled={disabled} charging={charging} />
</div>
)}
</div>
{((!charging || showVoltage) && (
<div className="w-15">
{!charging && runtime != null && runtime > 0 && (
<Typography color={textColor}>
{(runtime / BigInt(3600000000)).toString() +
'h ' +
(
(runtime % BigInt(3600000000)) /
BigInt(60000000)
).toString() +
'min'}
</Typography>
)}
{!charging && (!runtime || debug) && (
<Typography color={textColor}>
{percentFormatter.format(value)}
</Typography>
)}
{showVoltage && (
<Typography color={textColor}>
{voltageFormatter.format(voltage)}V
</Typography>
)}
</div>
)) || (
<div className="flex flex-col justify-center w-15">
<div className="w-5 h-1 bg-background-30 rounded-full" />
</div>
)}
</div>
</Tooltip>
);
}
3 changes: 3 additions & 0 deletions gui/src/components/tracker/TrackerCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ function TrackerBig({
<TrackerBattery
voltage={device.hardwareStatus.batteryVoltage}
value={device.hardwareStatus.batteryPctEstimate / 100}
runtime={device.hardwareStatus.batteryRuntimeEstimate}
disabled={tracker.status === TrackerStatusEnum.DISCONNECTED}
moreInfo={true}
/>
)}
<div className="flex gap-2">
Expand Down Expand Up @@ -119,6 +121,7 @@ function TrackerSmol({
<TrackerBattery
voltage={device.hardwareStatus.batteryVoltage}
value={device.hardwareStatus.batteryPctEstimate / 100}
runtime={device.hardwareStatus.batteryRuntimeEstimate}
disabled={tracker.status === TrackerStatusEnum.DISCONNECTED}
/>
)}
Expand Down
4 changes: 3 additions & 1 deletion gui/src/components/tracker/TrackersTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,9 @@ function Row({
<TrackerBattery
value={device.hardwareStatus.batteryPctEstimate / 100}
voltage={device.hardwareStatus.batteryVoltage}
runtime={device.hardwareStatus.batteryRuntimeEstimate}
disabled={tracker.status === TrackerStatusEnum.DISCONNECTED}
moreInfo={config?.devSettings.moreInfo}
textColor={fontColor}
/>
)}
Expand Down Expand Up @@ -329,7 +331,7 @@ export function TrackersTable({
const cols = [
'minmax(150px, 1.5fr)', // Name
'minmax(100px, 1fr)', // Type
'minmax(60px, 1fr)', // Battery
'minmax(110px, 1fr)', // Battery
'6rem', // Ping (w-24)
'minmax(60px, 1fr)', // TPS
config?.devSettings?.preciseRotation ? '11rem' : '8rem', // Rotation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,9 @@ public static int createDeviceData(
HardwareStatus.addRssi(fbb, (short) tracker.getSignalStrength().floatValue());
}

if (tracker.getBatteryRemainingRuntime() != null) {
HardwareStatus.addBatteryRuntimeEstimate(fbb, tracker.getBatteryRemainingRuntime());
}

int hardwareDataOffset = HardwareStatus.endHardwareStatus(fbb);
int hardwareInfoOffset = DataFeedBuilder.createHardwareInfo(fbb, device);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ class Tracker @JvmOverloads constructor(
val trackerFlexHandler: TrackerFlexHandler = TrackerFlexHandler(this)
var batteryVoltage: Float? = null
var batteryLevel: Float? = null
var batteryRemainingRuntime: Long? = null
var ping: Int? = null
var signalStrength: Int? = null
var temperature: Float? = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ class HIDCommon {
}

// Packet data
var runtime: Long? = null
var batt: Int? = null
var batt_v: Int? = null
var temp: Int? = null
Expand Down Expand Up @@ -221,6 +222,11 @@ class HIDCommon {
}
}

5 -> { // runtime
// ulong as little endian
runtime = (dataReceived[i + 9].toUByte().toLong() shl 56) or (dataReceived[i + 8].toUByte().toLong() shl 48) or (dataReceived[i + 7].toUByte().toLong() shl 40) or (dataReceived[i + 6].toUByte().toLong() shl 32) or (dataReceived[i + 5].toUByte().toLong() shl 24) or (dataReceived[i + 4].toUByte().toLong() shl 16) or (dataReceived[i + 3].toUByte().toLong() shl 8) or dataReceived[i + 2].toUByte().toLong()
}

6 -> { // data
button = dataReceived[i + 2].toUByte().toInt()
rssi = dataReceived[i + 15].toUByte().toInt()
Expand Down Expand Up @@ -248,6 +254,9 @@ class HIDCommon {
}

// Assign data
if (runtime != null) {
tracker.batteryRemainingRuntime = runtime
}
if (batt != null) {
tracker.batteryLevel = if (batt == 128) 1f else (batt and 127).toFloat()
}
Expand Down