mirror of
https://github.com/SlimeVR/SlimeVR-Server.git
synced 2026-11-30 05:42:46 -08:00
Dongle settings page + tweaks
This commit is contained in:
1 parent
9c15ddc79b
commit
5eba00d32b
17 files changed
+421
-33
No files matched your search
@@ -18,6 +18,11 @@ class DefaultSettingsBehaviour : SettingsBehaviour {
|
||||
state.copy(data = state.data.copy(trackers = state.data.trackers + (action.hardwareId to action.transform(existing))))
|
||||
}
|
||||
|
||||
is SettingsActions.UpdateDongle -> {
|
||||
val existing = state.data.dongles[action.serialNumber] ?: DongleConfig()
|
||||
state.copy(data = state.data.copy(dongles = state.data.dongles + (action.serialNumber to action.transform(existing))))
|
||||
}
|
||||
|
||||
is SettingsActions.AddAllowedUdpDevice -> state.copy(data = state.data.copy(allowedUdpDevices = state.data.allowedUdpDevices + action.mac))
|
||||
|
||||
is SettingsActions.RemoveAllowedUdpDevice -> state.copy(data = state.data.copy(allowedUdpDevices = state.data.allowedUdpDevices - action.mac))
|
||||
|
||||
@@ -33,6 +33,11 @@ data class TrackerConfig(
|
||||
val magEnabled: Boolean? = null,
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class DongleConfig(
|
||||
val customName: String? = null,
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class TrackersConfig(
|
||||
val trackerPort: Int = 6969, // Not in SolarXR
|
||||
@@ -212,6 +217,7 @@ data class SettingsConfigState(
|
||||
val mutedChecklistSteps: Set<String> = emptySet(),
|
||||
val allowedUdpDevices: Set<String> = emptySet(),
|
||||
val trackers: Map<String, TrackerConfig> = emptyMap(),
|
||||
val dongles: Map<String, DongleConfig> = emptyMap(),
|
||||
val trackersConfig: TrackersConfig = TrackersConfig(),
|
||||
val hidConfig: HidConfig = HidConfig(),
|
||||
val boneRoutingConfig: BoneRoutingConfig = BoneRoutingConfig(),
|
||||
@@ -246,6 +252,7 @@ sealed interface SettingsActions {
|
||||
data class Update(val transform: SettingsConfigState.() -> SettingsConfigState) : SettingsActions
|
||||
data class LoadProfile(val newState: SettingsState) : SettingsActions
|
||||
data class UpdateTracker(val hardwareId: String, val transform: TrackerConfig.() -> TrackerConfig) : SettingsActions
|
||||
data class UpdateDongle(val serialNumber: String, val transform: DongleConfig.() -> DongleConfig) : SettingsActions
|
||||
data class AddAllowedUdpDevice(val mac: String) : SettingsActions
|
||||
data class RemoveAllowedUdpDevice(val mac: String) : SettingsActions
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package dev.slimevr.hid
|
||||
|
||||
import dev.slimevr.VRServerActions
|
||||
import dev.slimevr.config.Settings
|
||||
import dev.slimevr.config.SettingsActions
|
||||
import dev.slimevr.device.Device
|
||||
import dev.slimevr.device.DeviceActions
|
||||
import dev.slimevr.logging.AppLogger
|
||||
@@ -9,6 +11,10 @@ import dev.slimevr.tracker.TrackerActions
|
||||
import dev.slimevr.util.timeSource
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.flow.distinctUntilChangedBy
|
||||
import kotlinx.coroutines.flow.drop
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
import kotlinx.coroutines.launch
|
||||
import solarxr_protocol.datatypes.DeviceOrigin
|
||||
import solarxr_protocol.datatypes.TrackerStatus
|
||||
@@ -31,6 +37,8 @@ class HIDRegistrationBehaviour : HIDReceiverBehaviour {
|
||||
|
||||
is HIDReceiverActions.SetStatus -> state.copy(status = action.status)
|
||||
|
||||
is HIDReceiverActions.SetCustomName -> state.copy(customName = action.customName)
|
||||
|
||||
else -> state
|
||||
}
|
||||
|
||||
@@ -66,6 +74,21 @@ class HIDRegistrationBehaviour : HIDReceiverBehaviour {
|
||||
}
|
||||
}
|
||||
|
||||
class HIDReceiverConfigBehaviour(
|
||||
private val settings: Settings,
|
||||
private val serialNumber: String,
|
||||
) : HIDReceiverBehaviour {
|
||||
override fun observe(receiver: HIDReceiver) {
|
||||
receiver.context.state
|
||||
.distinctUntilChangedBy { it.customName }
|
||||
.drop(1)
|
||||
.onEach { state ->
|
||||
settings.context.dispatch(SettingsActions.UpdateDongle(serialNumber) { copy(customName = state.customName) })
|
||||
}
|
||||
.launchIn(receiver.context.scope)
|
||||
}
|
||||
}
|
||||
|
||||
class HIDDeviceInfoBehaviour : HIDReceiverBehaviour {
|
||||
override fun reduce(state: HIDReceiverState, action: HIDReceiverActions): HIDReceiverState = when (action) {
|
||||
is HIDReceiverActions.TrackerRegistered -> {
|
||||
|
||||
@@ -23,6 +23,7 @@ data class HIDReceiverState(
|
||||
val isDirect: Boolean, // True if this HID device is a tracker connected directly over USB
|
||||
val status: DongleStatus,
|
||||
val displayName: String,
|
||||
val customName: String?,
|
||||
val hardwareRevision: String,
|
||||
val model: String,
|
||||
val manufacturer: String,
|
||||
@@ -38,6 +39,7 @@ sealed interface HIDReceiverActions {
|
||||
data class DeviceRegistered(val hidId: Int, val address: String, val deviceId: Int) : HIDReceiverActions
|
||||
data class TrackerRegistered(val hidId: Int, val trackerId: Int) : HIDReceiverActions
|
||||
data class SetStatus(val status: DongleStatus) : HIDReceiverActions
|
||||
data class SetCustomName(val customName: String?) : HIDReceiverActions
|
||||
}
|
||||
|
||||
typealias HIDReceiverContext = Context<HIDReceiverState, HIDReceiverActions>
|
||||
@@ -70,6 +72,9 @@ class HIDReceiver(
|
||||
appContext: AppContextProvider,
|
||||
scope: CoroutineScope,
|
||||
): HIDReceiver {
|
||||
val settings = appContext.config.settings
|
||||
val savedConfig = settings.context.state.value.data.dongles[serialNumber]
|
||||
|
||||
val behaviours = listOf(
|
||||
HIDRegistrationBehaviour(),
|
||||
HIDDeviceInfoBehaviour(),
|
||||
@@ -78,6 +83,7 @@ class HIDReceiver(
|
||||
HIDStatusBehaviour(),
|
||||
HIDPacketLossBehaviour(),
|
||||
HIDSleepBehaviour(),
|
||||
HIDReceiverConfigBehaviour(settings, serialNumber),
|
||||
)
|
||||
|
||||
val context = Context.create(
|
||||
@@ -88,6 +94,7 @@ class HIDReceiver(
|
||||
status = DongleStatus.DISCONNECTED,
|
||||
trackers = emptyMap(),
|
||||
displayName = "Dongle #${serialNumber}",
|
||||
customName = savedConfig?.customName,
|
||||
hardwareRevision = "1",
|
||||
manufacturer = "SlimeVR",
|
||||
model = "SuperCool",
|
||||
|
||||
@@ -139,6 +139,7 @@ private fun createDongle(dongle: HIDReceiverState, mask: DongleDataMask): Dongle
|
||||
return DongleData(
|
||||
id = dongle.id.toUShort(),
|
||||
displayName = dongle.displayName.takeIf { mask.displayName == true },
|
||||
customName = dongle.customName.takeIf { mask.customName == true },
|
||||
hardwareRevision = dongle.hardwareRevision.takeIf { mask.hardwareRevision == true },
|
||||
hardwareAddress = null, // FIXME: send me
|
||||
model = dongle.model.takeIf { mask.model == true },
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
package dev.slimevr.solarxr
|
||||
|
||||
import dev.slimevr.VRServer
|
||||
import dev.slimevr.hid.HIDReceiverActions
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
import solarxr_protocol.rpc.ChangeDongleSettingsRequest
|
||||
|
||||
class DongleSettingsBehaviour(
|
||||
private val server: VRServer,
|
||||
) : SolarXRBridgeBehaviour {
|
||||
override fun observe(receiver: SolarXRBridge) {
|
||||
receiver.rpcDispatcher.on<ChangeDongleSettingsRequest> { req ->
|
||||
val id = req.dongleId ?: return@on
|
||||
val dongle = server.context.state.value.dongles[id.toInt()]
|
||||
?: return@on
|
||||
|
||||
dongle.context.dispatch(
|
||||
HIDReceiverActions.SetCustomName(req.displayName),
|
||||
)
|
||||
}.launchIn(receiver.context.scope)
|
||||
}
|
||||
}
|
||||
@@ -139,6 +139,7 @@ class SolarXRBridge(
|
||||
add(SkeletonProportionsBehaviour(appContext.config.userConfig, appContext.skeleton))
|
||||
add(TrackingChecklistBehaviour(appContext.trackingChecklist, appContext.config.settings))
|
||||
add(AssignTrackerBehaviour(appContext.server))
|
||||
add(DongleSettingsBehaviour(appContext.server))
|
||||
add(DriverHandshakeBehaviour(appContext.server))
|
||||
add(DriverOutgoingTrackersBehaviour(appContext))
|
||||
add(DriverIncomingTrackersBehaviour(appContext.server))
|
||||
|
||||
Reference in new issue
Block a user