Whitelist HID devices for serial access, send serial device type to GUI

This commit is contained in:
Sapphire committed 2026-06-22 15:50:25 -05:00
1 parent 71895dec63
commit 9edc747344
9 files changed
+66 -57

No files matched your search

@@ -16,6 +16,7 @@ import dev.slimevr.AppLogger
import dev.slimevr.device.DeviceActions
import dev.slimevr.hid.HIDReceiver
import dev.slimevr.hid.parseHIDPackets
import dev.slimevr.hid.isCompatibleHidDevice
import dev.slimevr.util.safeLaunch
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
@@ -31,16 +32,6 @@ import solarxr_protocol.datatypes.TrackerStatus
private const val ACTION_USB_HID_PERMISSION = "dev.slimevr.android.USB_HID_PERMISSION"
private const val HID_POLL_INTERVAL_MS = 3000L
private data class HidProductRule(val vendorId: Int, val productId: Int, val productMask: Int = 0xFFFF)
private val HID_PRODUCT_RULES = listOf(
HidProductRule(0x1209, 0x7690), // SlimeVR receiver
HidProductRule(0x1209, 0x7692), // SlimeVR tracker direct
HidProductRule(0x4E76, 0xD200, 0xFF00), // Gestures Inc. D2XX
)
private fun isCompatibleDevice(vid: Int, pid: Int) = HID_PRODUCT_RULES.any { rule -> vid == rule.vendorId && (pid and rule.productMask) == rule.productId }
private fun findHidInputEndpoint(device: UsbDevice): Pair<UsbInterface, UsbEndpoint>? {
for (ifaceIdx in 0 until device.interfaceCount) {
val iface = device.getInterface(ifaceIdx)
@@ -89,7 +80,7 @@ fun createAndroidHIDManager(context: Context, appContext: AppContextProvider, sc
val found = withContext(Dispatchers.IO) {
try {
usbManager.deviceList.values
.filter { device -> isCompatibleDevice(device.vendorId, device.productId) }
.filter { device -> isCompatibleHidDevice(device.vendorId, device.productId) }
.associate { device -> device.deviceName to device }
} catch (e: Exception) {
AppLogger.hid.error(e, "HID enumeration failed")
@@ -15,6 +15,7 @@ import dev.slimevr.AppLogger
import dev.slimevr.serial.SerialPortHandle
import dev.slimevr.serial.SerialPortInfo
import dev.slimevr.serial.SerialServer
import dev.slimevr.serial.isKnownSerialBoard
import dev.slimevr.util.safeLaunch
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
@@ -27,20 +28,6 @@ private const val TAG = "SerialServer"
private const val ACTION_USB_SERIAL_PERMISSION = "dev.slimevr.android.USB_SERIAL_PERMISSION"
private const val POLL_INTERVAL_MS = 3000L
private val SUPPORTED_BOARDS: Set<Pair<Int, Int>> = setOf(
Pair(0x1A86, 0x7522), // CH340
Pair(0x1A86, 0x7523), // CH340
Pair(0x1A86, 0x5523), // CH341
Pair(0x1A86, 0x55D3), // CH343
Pair(0x1A86, 0x55D4), // CH9102x
Pair(0x10C4, 0xEA60), // CP210x
Pair(0x303A, 0x1001), // ESP32-S3
Pair(0x303A, 0x0002), // ESP32
Pair(0x0403, 0x6001), // FTDI FT232
)
private fun isKnownBoard(vid: Int, pid: Int) = SUPPORTED_BOARDS.contains(vid to pid)
private fun openAndroidPort(
portLocation: String,
usbManager: UsbManager,
@@ -128,7 +115,7 @@ private suspend fun runAndroidSerialPoller(
val current = withContext(Dispatchers.IO) {
UsbSerialProber.getDefaultProber()
.findAllDrivers(usbManager)
.filter { driver -> isKnownBoard(driver.device.vendorId, driver.device.productId) }
.filter { driver -> isKnownSerialBoard(driver.device.vendorId, driver.device.productId) }
.associateBy { driver -> driver.device.deviceName }
}