From 3513b5ab0bbb3da7ad3c21e44f412e3f91458371 Mon Sep 17 00:00:00 2001 From: Mathieu Broillet Date: Sat, 8 Feb 2025 17:05:17 +0100 Subject: [PATCH] filter usb devices --- .../java/ch/mathieubroillet/djiffchack/MainActivity.kt | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/ch/mathieubroillet/djiffchack/MainActivity.kt b/app/src/main/java/ch/mathieubroillet/djiffchack/MainActivity.kt index 5cea06f..06350a0 100644 --- a/app/src/main/java/ch/mathieubroillet/djiffchack/MainActivity.kt +++ b/app/src/main/java/ch/mathieubroillet/djiffchack/MainActivity.kt @@ -97,8 +97,16 @@ class MainActivity : ComponentActivity() { private fun refreshUsbConnection() { if (usbManager.deviceList.isNotEmpty()) { 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) + if (usbConnection == null) { Log.d("USB_CONNECTION", "Requesting USB Permission") requestUsbPermission(device) @@ -143,7 +151,6 @@ class MainActivity : ComponentActivity() { -127, 31 ), 1000 ) - usbSerialPort.close() } catch (e: Exception) { Log.e("USB_PATCH", "Error sending patch: ${e.message}") Toast.makeText(this, "Patch failed: ${e.message}", Toast.LENGTH_SHORT).show()