Skip to content

Commit b44dcaa

Browse files
authored
Runtime (#1678)
2 parents 9a27fb1 + ff0d823 commit b44dcaa

File tree

7 files changed

+66
-25
lines changed

7 files changed

+66
-25
lines changed

gui/src/components/tracker/TrackerBattery.tsx

Lines changed: 46 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,24 @@ import { useConfig } from '@/hooks/config';
22
import { useLocaleConfig } from '@/i18n/config';
33
import { BatteryIcon } from '@/components/commons/icon/BatteryIcon';
44
import { Typography } from '@/components/commons/Typography';
5+
import { Tooltip } from '@/components/commons/Tooltip';
56

67
export function TrackerBattery({
78
value,
89
voltage,
10+
runtime,
911
disabled,
12+
moreInfo = false,
1013
textColor = 'primary',
1114
}: {
1215
/**
1316
* a [0, 1] value range is expected
1417
*/
1518
value: number;
1619
voltage?: number | null;
20+
runtime?: bigint | null;
1721
disabled?: boolean;
22+
moreInfo?: boolean;
1823
textColor?: string;
1924
}) {
2025
const { currentLocales } = useLocaleConfig();
@@ -28,31 +33,49 @@ export function TrackerBattery({
2833
});
2934

3035
const charging = (voltage || 0) > 4.3;
31-
const showVoltage = voltage && config?.debug;
36+
const debug = config?.debug || config?.devSettings.moreInfo;
37+
const showVoltage = moreInfo && voltage && debug;
3238

3339
return (
34-
<div className="flex gap-2">
35-
<div className="flex flex-col justify-around">
36-
<BatteryIcon value={value} disabled={disabled} charging={charging} />
37-
</div>
38-
{((!charging || showVoltage) && (
39-
<div className="w-10">
40-
{!charging && (
41-
<Typography color={textColor}>
42-
{percentFormatter.format(value)}
43-
</Typography>
44-
)}
45-
{showVoltage && (
46-
<Typography color={textColor}>
47-
{voltageFormatter.format(voltage)}V
48-
</Typography>
49-
)}
50-
</div>
51-
)) || (
52-
<div className="flex flex-col justify-center w-10">
53-
<div className="w-5 h-1 bg-background-30 rounded-full" />
40+
<Tooltip
41+
disabled={!charging && (!runtime || debug)}
42+
preferedDirection="left"
43+
content=<Typography>{percentFormatter.format(value)}</Typography>
44+
>
45+
<div className="flex gap-2">
46+
<div className="flex flex-col justify-around">
47+
<BatteryIcon value={value} disabled={disabled} charging={charging} />
5448
</div>
55-
)}
56-
</div>
49+
{((!charging || showVoltage) && (
50+
<div className="w-15">
51+
{!charging && runtime != null && runtime > 0 && (
52+
<Typography color={textColor}>
53+
{(runtime / BigInt(3600000000)).toString() +
54+
'h ' +
55+
(
56+
(runtime % BigInt(3600000000)) /
57+
BigInt(60000000)
58+
).toString() +
59+
'min'}
60+
</Typography>
61+
)}
62+
{!charging && (!runtime || debug) && (
63+
<Typography color={textColor}>
64+
{percentFormatter.format(value)}
65+
</Typography>
66+
)}
67+
{showVoltage && (
68+
<Typography color={textColor}>
69+
{voltageFormatter.format(voltage)}V
70+
</Typography>
71+
)}
72+
</div>
73+
)) || (
74+
<div className="flex flex-col justify-center w-15">
75+
<div className="w-5 h-1 bg-background-30 rounded-full" />
76+
</div>
77+
)}
78+
</div>
79+
</Tooltip>
5780
);
5881
}

gui/src/components/tracker/TrackerCard.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ function TrackerBig({
5151
<TrackerBattery
5252
voltage={device.hardwareStatus.batteryVoltage}
5353
value={device.hardwareStatus.batteryPctEstimate / 100}
54+
runtime={device.hardwareStatus.batteryRuntimeEstimate}
5455
disabled={tracker.status === TrackerStatusEnum.DISCONNECTED}
56+
moreInfo={true}
5557
/>
5658
)}
5759
<div className="flex gap-2">
@@ -119,6 +121,7 @@ function TrackerSmol({
119121
<TrackerBattery
120122
voltage={device.hardwareStatus.batteryVoltage}
121123
value={device.hardwareStatus.batteryPctEstimate / 100}
124+
runtime={device.hardwareStatus.batteryRuntimeEstimate}
122125
disabled={tracker.status === TrackerStatusEnum.DISCONNECTED}
123126
/>
124127
)}

gui/src/components/tracker/TrackersTable.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,9 @@ function Row({
229229
<TrackerBattery
230230
value={device.hardwareStatus.batteryPctEstimate / 100}
231231
voltage={device.hardwareStatus.batteryVoltage}
232+
runtime={device.hardwareStatus.batteryRuntimeEstimate}
232233
disabled={tracker.status === TrackerStatusEnum.DISCONNECTED}
234+
moreInfo={config?.devSettings.moreInfo}
233235
textColor={fontColor}
234236
/>
235237
)}
@@ -329,7 +331,7 @@ export function TrackersTable({
329331
const cols = [
330332
'minmax(150px, 1.5fr)', // Name
331333
'minmax(100px, 1fr)', // Type
332-
'minmax(60px, 1fr)', // Battery
334+
'minmax(110px, 1fr)', // Battery
333335
'6rem', // Ping (w-24)
334336
'minmax(60px, 1fr)', // TPS
335337
config?.devSettings?.preciseRotation ? '11rem' : '8rem', // Rotation

server/core/src/main/java/dev/slimevr/protocol/datafeed/DataFeedBuilder.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,9 @@ public static int createDeviceData(
317317
HardwareStatus.addRssi(fbb, (short) tracker.getSignalStrength().floatValue());
318318
}
319319

320+
if (tracker.getBatteryRemainingRuntime() != null) {
321+
HardwareStatus.addBatteryRuntimeEstimate(fbb, tracker.getBatteryRemainingRuntime());
322+
}
320323

321324
int hardwareDataOffset = HardwareStatus.endHardwareStatus(fbb);
322325
int hardwareInfoOffset = DataFeedBuilder.createHardwareInfo(fbb, device);

server/core/src/main/java/dev/slimevr/tracking/trackers/Tracker.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ class Tracker @JvmOverloads constructor(
112112
val trackerFlexHandler: TrackerFlexHandler = TrackerFlexHandler(this)
113113
var batteryVoltage: Float? = null
114114
var batteryLevel: Float? = null
115+
var batteryRemainingRuntime: Long? = null
115116
var ping: Int? = null
116117
var signalStrength: Int? = null
117118
var temperature: Float? = null

server/core/src/main/java/dev/slimevr/tracking/trackers/hid/HIDCommon.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ class HIDCommon {
138138
}
139139

140140
// Packet data
141+
var runtime: Long? = null
141142
var batt: Int? = null
142143
var batt_v: Int? = null
143144
var temp: Int? = null
@@ -221,6 +222,11 @@ class HIDCommon {
221222
}
222223
}
223224

225+
5 -> { // runtime
226+
// ulong as little endian
227+
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()
228+
}
229+
224230
6 -> { // data
225231
button = dataReceived[i + 2].toUByte().toInt()
226232
rssi = dataReceived[i + 15].toUByte().toInt()
@@ -248,6 +254,9 @@ class HIDCommon {
248254
}
249255

250256
// Assign data
257+
if (runtime != null) {
258+
tracker.batteryRemainingRuntime = runtime
259+
}
251260
if (batt != null) {
252261
tracker.batteryLevel = if (batt == 128) 1f else (batt and 127).toFloat()
253262
}

0 commit comments

Comments
 (0)