Skip to content

Commit 7f53652

Browse files
committed
Parse runtime from HID tracker
1 parent 3982249 commit 7f53652

File tree

4 files changed

+14
-1
lines changed

4 files changed

+14
-1
lines changed

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
@@ -310,6 +310,9 @@ public static int createDeviceData(
310310
HardwareStatus.addRssi(fbb, (short) tracker.getSignalStrength().floatValue());
311311
}
312312

313+
if (tracker.getBatteryRemainingRuntime() != null) {
314+
HardwareStatus.addBatteryRuntimeEstimate(fbb, tracker.getBatteryRemainingRuntime());
315+
}
313316

314317
int hardwareDataOffset = HardwareStatus.endHardwareStatus(fbb);
315318
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)