filter usb devices

This commit is contained in:
Mathieu Broillet 2025-02-08 17:05:17 +01:00
parent 65d8cacd50
commit 3513b5ab0b

View File

@ -97,8 +97,16 @@ class MainActivity : ComponentActivity() {
private fun refreshUsbConnection() { private fun refreshUsbConnection() {
if (usbManager.deviceList.isNotEmpty()) { if (usbManager.deviceList.isNotEmpty()) {
val device: UsbDevice = usbManager.deviceList.values.first() val device: UsbDevice = usbManager.deviceList.values.first()
// Check to be sure the device is the initialized DJI Remote (and not another USB device)
if (device.productId != 4128) {
Log.d("USB_CONNECTION", "Device not supported ${device.productId}")
return
}
usbConnection = usbManager.openDevice(device) usbConnection = usbManager.openDevice(device)
if (usbConnection == null) { if (usbConnection == null) {
Log.d("USB_CONNECTION", "Requesting USB Permission") Log.d("USB_CONNECTION", "Requesting USB Permission")
requestUsbPermission(device) requestUsbPermission(device)
@ -143,7 +151,6 @@ class MainActivity : ComponentActivity() {
-127, 31 -127, 31
), 1000 ), 1000
) )
usbSerialPort.close()
} catch (e: Exception) { } catch (e: Exception) {
Log.e("USB_PATCH", "Error sending patch: ${e.message}") Log.e("USB_PATCH", "Error sending patch: ${e.message}")
Toast.makeText(this, "Patch failed: ${e.message}", Toast.LENGTH_SHORT).show() Toast.makeText(this, "Patch failed: ${e.message}", Toast.LENGTH_SHORT).show()