tap inputs

This commit is contained in:
Erimel committed 2025-07-22 20:16:44 -04:00
1 parent 0221cf3985
commit c9dac8ebe3
7 files changed
+84 -34

No files matched your search

@@ -10,6 +10,8 @@ import dev.slimevr.firmware.SerialFlashingHandler
import dev.slimevr.games.vrchat.VRCConfigHandler
import dev.slimevr.games.vrchat.VRCConfigHandlerStub
import dev.slimevr.games.vrchat.VRChatConfigManager
import dev.slimevr.inputs.Input
import dev.slimevr.inputs.TapInputManager
import dev.slimevr.osc.OSCHandler
import dev.slimevr.osc.OSCRouter
import dev.slimevr.osc.VMCHandler
@@ -116,6 +118,9 @@ class VRServer @JvmOverloads constructor(
@JvmField
val handshakeHandler = HandshakeHandler()
val tapInputManager: TapInputManager
val inputs: MutableList<Input> = FastList()
init {
// UwU
configManager = ConfigManager(configPath)
@@ -148,6 +153,7 @@ class VRServer @JvmOverloads constructor(
bridges.add(bridge)
bridge.addFingerBones(humanPoseManager.shareableFingerBones)
}
tapInputManager = TapInputManager(humanPoseManager.skeleton, this)
// Initialize OSC handlers
vrcOSCHandler = VRCOSCHandler(
@@ -245,11 +251,23 @@ class VRServer @JvmOverloads constructor(
tracker.tick()
}
humanPoseManager.update()
// Check for tap inputs
tapInputManager.update()
// Update bridges
for (bridge in bridges) {
// Send inputs to each bridge
for (input in inputs) {
bridge.sendInput(input)
}
bridge.dataWrite()
}
// Don't forget to clear inputs so that we don't send the same ones again
inputs.clear()
vrcOSCHandler.update()
vMCHandler.update()
// final long time = System.currentTimeMillis() - start;
try {
sleep(1) // 1000Hz
@@ -56,7 +56,7 @@ interface Bridge {
* @param input the object containing the data about the input
*/
@VRServerThread
fun sendBooleanInput(input: Input)
fun sendInput(input: Input)
@VRServerThread
fun startBridge()
@@ -1,53 +1,83 @@
package dev.slimevr.inputs
import dev.slimevr.tracking.processor.HumanPoseManager
import dev.slimevr.VRServer
import dev.slimevr.tracking.processor.skeleton.HumanSkeleton
import dev.slimevr.tracking.processor.skeleton.TapDetection
import dev.slimevr.tracking.trackers.Tracker
import dev.slimevr.util.ann.VRServerThread
/**
* Handles tap detection for SteamVR virtual controller input
*/
class TapInputManager(
private val skeleton: HumanSkeleton,
private val humanPoseManager: HumanPoseManager?,
private val vrServer: VRServer,
) {
// tap detectors
private var leftDoubleDetector: TapDetection? = null
private var leftTripleDetector: TapDetection? = null
private var rightDoubleDetector: TapDetection? = null
private var rightTripleDetector: TapDetection? = null
private lateinit var leftDoubleDetector: TapDetection
private lateinit var leftTripleDetector: TapDetection
private lateinit var rightDoubleDetector: TapDetection
private lateinit var rightTripleDetector: TapDetection
val NS_CONVERTER: Float = 1.0e9f
private var doubleTapDelay = 0.25f * NS_CONVERTER
init {
// Create tap detectors for both hands
leftDoubleDetector = TapDetection(skeleton, trackerToWatchLeftHand)
leftTripleDetector = TapDetection(skeleton, trackerToWatchLeftHand)
rightDoubleDetector = TapDetection(skeleton, trackerToWatchRightHand)
rightTripleDetector = TapDetection(skeleton, trackerToWatchRightHand)
reinit()
}
fun update() {
if (leftDoubleDetector == null ||
leftTripleDetector == null ||
rightDoubleDetector == null ||
rightTripleDetector == null
) {
return
}
fun reinit() {
// Create tap detectors for both hands
leftDoubleDetector = TapDetection(skeleton, trackerToWatchLeftHand)
leftDoubleDetector.enabled = true
leftDoubleDetector.setMaxTaps(2)
leftTripleDetector = TapDetection(skeleton, trackerToWatchLeftHand)
leftTripleDetector.enabled = true
leftTripleDetector.setMaxTaps(3)
rightDoubleDetector = TapDetection(skeleton, trackerToWatchRightHand)
rightDoubleDetector.enabled = true
rightDoubleDetector.setMaxTaps(2)
rightTripleDetector = TapDetection(skeleton, trackerToWatchRightHand)
rightTripleDetector.enabled = true
rightTripleDetector.setMaxTaps(3)
}
@VRServerThread
fun update() {
// update the tap detectors
leftDoubleDetector!!.update()
leftTripleDetector!!.update()
rightDoubleDetector!!.update()
rightTripleDetector!!.update()
leftDoubleDetector.update()
leftTripleDetector.update()
rightDoubleDetector.update()
rightTripleDetector.update()
// check if any tap detectors have detected taps
// TODO
if (3 <= leftTripleDetector.taps) {
leftTripleDetector.resetDetector()
leftDoubleDetector.resetDetector()
vrServer.inputs.add(Input(false, InputType.TRIPLE_TAP))
} else if (2 <= leftDoubleDetector.taps && System.nanoTime() - rightDoubleDetector.detectionTime > doubleTapDelay) {
leftTripleDetector.resetDetector()
leftDoubleDetector.resetDetector()
vrServer.inputs.add(Input(false, InputType.DOUBLE_TAP))
}
if (3 <= rightTripleDetector.taps) {
rightTripleDetector.resetDetector()
rightDoubleDetector.resetDetector()
vrServer.inputs.add(Input(true, InputType.TRIPLE_TAP))
} else if (2 <= rightDoubleDetector.taps && System.nanoTime() - rightDoubleDetector.detectionTime > doubleTapDelay) {
rightTripleDetector.resetDetector()
rightDoubleDetector.resetDetector()
vrServer.inputs.add(Input(true, InputType.DOUBLE_TAP))
}
}
private val trackerToWatchLeftHand: Tracker?
get() = listOf(
get() = listOfNotNull(
skeleton.leftHandTracker,
skeleton.leftLowerArmTracker,
skeleton.leftUpperArmTracker,
@@ -57,7 +87,7 @@ class TapInputManager(
).firstOrNull()
private val trackerToWatchRightHand: Tracker?
get() = listOf(
get() = listOfNotNull(
skeleton.rightHandTracker,
skeleton.rightLowerArmTracker,
skeleton.rightUpperArmTracker,
@@ -487,6 +487,7 @@ class HumanSkeleton(
// Update tap detection's trackers
tapDetectionManager.updateConfig(trackers)
humanPoseManager.server?.tapInputManager?.reinit()
// Update bones tracker field
refreshBoneTracker()
@@ -233,7 +233,7 @@ class WebSocketVRBridge(
// TODO Auto-generated method stub
}
override fun sendBooleanInput(input: Input) {
override fun sendInput(input: Input) {
// TODO Auto-generated method stub
}
@@ -20,9 +20,8 @@ import io.eiren.util.collections.FastList
import io.eiren.util.logging.LogManager
import io.github.axisangles.ktmath.Quaternion
import io.github.axisangles.ktmath.Vector3
import java.util.Queue
import java.util.*
import java.util.concurrent.LinkedBlockingQueue
import kotlin.collections.HashMap
abstract class ProtobufBridge(@JvmField protected val bridgeName: String) : ISteamVRBridge {
@JvmField
@@ -163,7 +162,9 @@ abstract class ProtobufBridge(@JvmField protected val bridgeName: String) : ISte
val trackerIsLeftHand = localTracker.trackerPosition == TrackerPosition.LEFT_HAND
val trackerIsRightHand = localTracker.trackerPosition == TrackerPosition.RIGHT_HAND
if (trackerIsLeftHand || trackerIsRightHand) {
for (input in inputs) {
val iterator = inputs.iterator()
while (iterator.hasNext()) {
val input = iterator.next()
if ((input.rightHand && trackerIsRightHand) || (!input.rightHand && trackerIsLeftHand)) {
val inputBuilder = Input.newBuilder()
if (input.type == InputType.DOUBLE_TAP) {
@@ -176,7 +177,7 @@ abstract class ProtobufBridge(@JvmField protected val bridgeName: String) : ISte
builder.addInput(inputBuilder.build())
inputs.remove(input)
iterator.remove()
} else {
// Input side doesn't match controller side
}
@@ -188,7 +189,7 @@ abstract class ProtobufBridge(@JvmField protected val bridgeName: String) : ISte
}
@VRServerThread
override fun sendBooleanInput(input: dev.slimevr.inputs.Input) {
override fun sendInput(input: dev.slimevr.inputs.Input) {
inputs.add(input)
}
@@ -145,7 +145,7 @@ public class UnixSocketRpcBridge implements dev.slimevr.bridge.Bridge,
}
@Override
public void sendBooleanInput(@NotNull Input input) {
public void sendInput(@NotNull Input input) {
}
}