Add accelDataTick

This commit is contained in:
Butterscotch!
2026-01-02 05:35:32 -05:00
parent 92e9081cf9
commit 0567662a35
3 changed files with 16 additions and 0 deletions

View File

@@ -179,6 +179,10 @@ class Tracker @JvmOverloads constructor(
val stayAligned = StayAlignedTrackerState(this)
val yawResetSmoothing = InterpolationHandler()
// Currently only used for accel resets, to add anything else, consider using a
// subscribable event listener instead
var accelTickCallback: ((tracker: Tracker) -> Unit)? = null
init {
// IMPORTANT: Look here for the required states of inputs
require(!allowReset || (hasRotation && allowReset)) {
@@ -488,6 +492,13 @@ class Tracker @JvmOverloads constructor(
}
}
/**
* Tells the tracker that it received new accel data
* Accel may be (and usually is) desynced from rotation data, so if we want the
* latest, we need to process it here
*/
fun accelDataTick() = accelTickCallback?.invoke(this)
/**
* A way to delay the timeout of the tracker
*/

View File

@@ -378,6 +378,9 @@ class HIDCommon {
if (packetType == 1 || packetType == 2 || packetType == 4 || packetType == 7) {
tracker.dataTick() // only data tick if there is rotation data
}
if (packetType == 1 || packetType == 2 || packetType == 7) {
tracker.accelDataTick()
}
}
}
}

View File

@@ -424,6 +424,7 @@ class TrackersUDPServer(private val port: Int, name: String, private val tracker
} else {
tracker.setAcceleration(SENSOR_OFFSET_CORRECTION.sandwich(packet.acceleration))
}
tracker.accelDataTick()
}
tracker.dataTick()
}
@@ -462,6 +463,7 @@ class TrackersUDPServer(private val port: Int, name: String, private val tracker
} else {
tracker.setAcceleration(SENSOR_OFFSET_CORRECTION.sandwich(packet.acceleration))
}
tracker.accelDataTick()
}
is UDPPacket10PingPong -> {