I'm trying to find a way to control the UVC extension unit for a USB camera app on Android. I'm currently attempting to use the android.hardware.usb API to access the UVC XU, but I'm unsure if this is possible.
After reading the UVC 1.5 Class specification and the controlTransfer API, I've attempted to write my code as follows:
Given my scenario, does anyone know how to implement UVC extension unit control to determine the wValue and wIndex?
https://i.stack.imgur.com/jQ4zW.jpg
val usbInterface = usbDevice?.getInterface(0)
if (usbInterface != null)
{
val claim = usbDeviceConnection?.claimInterface(usbInterface, true)
val endpoint = usbInterface.getEndpoint(idx)
if (endpoint == null){
val buffer = ByteArray(32)
val wvalue = 0
val windex = (0x03 shl 8) or usbInterface.id
val result = usbDeviceConnection?.controlTransfer(REQ_TYPE_GET, UVC_GET_INFO, wvalue, windex, buffer, buffer.size, TIMEOUT_MS)
val resul2 = usbDeviceConnection?.controlTransfer(REQ_TYPE_SET, UVC_SET_CUR, 1, 0, buffer, buffer.size, TIMEOUT_MS)
}
}
companion object {
private const val REQ_TYPE_SET = 0x21
private const val REQ_TYPE_GET = 0xa1
private const val UVC_SET_CUR = 0x01
private const val UVC_GET_CUR = 0x81
private const val UVC_GET_MIN = 0x82
private const val UVC_GET_MAX = 0x83
private const val UVC_GET_RES = 0x84
private const val UVC_GET_LEN = 0x85
private const val UVC_GET_INFO = 0x86
private const val TIMEOUT_MS = 1000
}
Thanks