Add UsbUtils utility object for shared USB functions
This commit is contained in:
parent
ff419d9f36
commit
5fbe0712e8
1 changed files with 30 additions and 0 deletions
30
android/app/src/main/java/com/eddy/atomrelay/UsbUtils.kt
Normal file
30
android/app/src/main/java/com/eddy/atomrelay/UsbUtils.kt
Normal file
|
|
@ -0,0 +1,30 @@
|
||||||
|
package com.eddy.atomrelay
|
||||||
|
|
||||||
|
import android.hardware.usb.UsbConstants
|
||||||
|
import android.hardware.usb.UsbDevice
|
||||||
|
import android.hardware.usb.UsbEndpoint
|
||||||
|
import android.hardware.usb.UsbInterface
|
||||||
|
|
||||||
|
object UsbUtils {
|
||||||
|
private const val CDC_DATA_INTERFACE_CLASS = 0x0A
|
||||||
|
|
||||||
|
fun findCdcDataInterface(device: UsbDevice): UsbInterface? {
|
||||||
|
for (i in 0 until device.interfaceCount) {
|
||||||
|
val intf = device.getInterface(i)
|
||||||
|
if (intf.interfaceClass == CDC_DATA_INTERFACE_CLASS) {
|
||||||
|
return intf
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
fun findBulkEndpoint(intf: UsbInterface, direction: Int): UsbEndpoint? {
|
||||||
|
for (i in 0 until intf.endpointCount) {
|
||||||
|
val ep = intf.getEndpoint(i)
|
||||||
|
if (ep.type == UsbConstants.USB_ENDPOINT_XFER_BULK && ep.direction == direction) {
|
||||||
|
return ep
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue