Button to assign on HID

This commit is contained in:
loucass003 committed 2026-09-22 02:52:20 +02:00
1 parent 30d5d5e462
commit f8aebdd066
3 files changed
+58

No files matched your search

@@ -0,0 +1,36 @@
@file:Suppress("DEPRECATION")
package dev.slimevr.hid.behaviours.legacy
import dev.slimevr.hid.HIDDataLegacy
import dev.slimevr.hid.HIDReceiver
import dev.slimevr.hid.HIDReceiverBehaviour
import dev.slimevr.hid.HIDRotationButtonLegacy
import solarxr_protocol.rpc.TapDetectionSetupNotification
class HIDButtonLegacyBehaviour : HIDReceiverBehaviour {
private val lastButton = mutableMapOf<Int, Int>()
override fun observe(receiver: HIDReceiver) {
receiver.packetEvents.on<HIDDataLegacy> { onButton(receiver, it.hidId, it.button) }
.launchIn(receiver.context.scope)
receiver.packetEvents.on<HIDRotationButtonLegacy> { onButton(receiver, it.hidId, it.button) }
.launchIn(receiver.context.scope)
}
private suspend fun onButton(receiver: HIDReceiver, hidId: Int, button: Int) {
val fired = (button and (lastButton[hidId] ?: 0).inv()) and BUTTON_ACTION_MASK != 0
lastButton[hidId] = button
if (!fired) return
if (!receiver.appContext.tapDetectionManager.context.state.value.setupMode) return
val tracker = receiver.getTracker(hidId) ?: return
receiver.appContext.server.sendSolarxrRpc(
TapDetectionSetupNotification(tracker.context.state.value.id.toUShort()),
)
}
companion object {
private const val BUTTON_ACTION_MASK = 0b11
}
}
@@ -0,0 +1,18 @@
package dev.slimevr.hid.behaviours.v3
import dev.slimevr.hid.HIDButton
import dev.slimevr.hid.HIDReceiver
import dev.slimevr.hid.HIDReceiverBehaviour
import solarxr_protocol.rpc.TapDetectionSetupNotification
class HIDButtonV3Behaviour : HIDReceiverBehaviour {
override fun observe(receiver: HIDReceiver) {
receiver.packetEvents.on<HIDButton> { packet ->
if (!receiver.appContext.tapDetectionManager.context.state.value.setupMode) return@on
val tracker = receiver.getTracker(packet.hidId) ?: return@on
receiver.appContext.server.sendSolarxrRpc(
TapDetectionSetupNotification(tracker.context.state.value.id.toUShort()),
)
}.launchIn(receiver.context.scope)
}
}
@@ -8,11 +8,13 @@ import dev.slimevr.device.Device
import dev.slimevr.device.DeviceActions
import dev.slimevr.hid.behaviours.HIDReceiverConfigBehaviour
import dev.slimevr.hid.behaviours.legacy.HIDBatteryBehaviour
import dev.slimevr.hid.behaviours.legacy.HIDButtonLegacyBehaviour
import dev.slimevr.hid.behaviours.legacy.HIDDeviceInfoBehaviour
import dev.slimevr.hid.behaviours.legacy.HIDRegistrationBehaviour
import dev.slimevr.hid.behaviours.legacy.HIDRotationBehaviour
import dev.slimevr.hid.behaviours.legacy.HIDSleepLegacyBehaviour
import dev.slimevr.hid.behaviours.legacy.HIDStatusBehaviour
import dev.slimevr.hid.behaviours.v3.HIDButtonV3Behaviour
import dev.slimevr.hid.behaviours.v3.HIDDeviceInfoV3Behaviour
import dev.slimevr.hid.behaviours.v3.HIDDeviceStateBehaviour
import dev.slimevr.hid.behaviours.v3.HIDDongleInfoBehaviour
@@ -84,6 +86,7 @@ private fun v3Behaviours(): List<HIDReceiverBehaviour> = listOf(
HIDRssiBehaviour(),
HIDPacketLossBehaviour(),
HIDSleepV3Behaviour(),
HIDButtonV3Behaviour(),
)
private fun legacyBehaviours(): List<HIDReceiverBehaviour> = listOf(
@@ -93,6 +96,7 @@ private fun legacyBehaviours(): List<HIDReceiverBehaviour> = listOf(
HIDBatteryBehaviour(),
HIDStatusBehaviour(),
HIDSleepLegacyBehaviour(),
HIDButtonLegacyBehaviour(),
)
class HIDReceiver(