|
@@ -475,73 +475,43 @@ public class NoiseAnalysis extends AppCompatActivity implements OpenDevicesRecei
|
|
|
{
|
|
|
if (mUsbManager.hasPermission(usbDevice)) {
|
|
|
|
|
|
- mUsbDeviceConnection = mUsbManager.openDevice(usbDevice);
|
|
|
- if (mUsbDeviceConnection != null) {
|
|
|
+ UsbInterface usbInterface = usbDevice.getInterface(1);
|
|
|
|
|
|
- int interfaceCount = usbDevice.getInterfaceCount();
|
|
|
- // for (int interfaceIndex = 0; interfaceIndex < interfaceCount; interfaceIndex++)
|
|
|
- {
|
|
|
- // UsbInterface usbInterface = usbDevice.getInterface(interfaceIndex);
|
|
|
- UsbInterface usbInterface = usbDevice.getInterface(1);
|
|
|
-
|
|
|
- if(UsbConstants.USB_CLASS_HID != usbInterface.getInterfaceClass())
|
|
|
- {
|
|
|
- // continue;
|
|
|
- }
|
|
|
-
|
|
|
- for (int i = 0; i < usbInterface.getEndpointCount(); i++) {
|
|
|
- UsbEndpoint ep = usbInterface.getEndpoint(i);
|
|
|
- //if (ep.getType() == UsbConstants.USB_ENDPOINT_XFER_INT) {
|
|
|
- // if (ep.getType() == UsbConstants.USB_ENDPOINT_XFER_CONTROL) {
|
|
|
- // if (ep.getType() == UsbConstants.USB_ENDPOINT_XFER_ISOC) {
|
|
|
- if (ep.getType() == UsbConstants.USB_ENDPOINT_XFER_BULK) {
|
|
|
- if (ep.getDirection() == UsbConstants.USB_DIR_OUT) {
|
|
|
- //mUsbEndpointIn = ep;
|
|
|
- mUsbEndpointOut = ep;
|
|
|
- } else {
|
|
|
- //mUsbEndpointOut = ep;
|
|
|
- mUsbEndpointIn = ep;
|
|
|
- }
|
|
|
- }
|
|
|
- else{
|
|
|
- // mHandler.sendEmptyMessage(CONNECTED_SUCCESS);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if ((null == mUsbEndpointIn) || (null == mUsbEndpointOut)) {
|
|
|
- //if ((null == mUsbEndpointIn) && (null == mUsbEndpointOut)) {
|
|
|
- // tvInfo.append("endpoint is null\n");
|
|
|
- int i = mUsbDeviceConnection.controlTransfer(0x00, 0x09,
|
|
|
- 0x002, 0, null, 0, 100);
|
|
|
- SystemClock.sleep(1000);
|
|
|
- if(i>=0){
|
|
|
- //mHandler.sendEmptyMessage(DEBUG_MESSAGE_SUCCESS);
|
|
|
- }
|
|
|
- else{
|
|
|
- //mHandler.sendEmptyMessage(DEBUG_MESSAGE_ERROR);
|
|
|
- }
|
|
|
+ for (int i = 0; i < usbInterface.getEndpointCount(); i++) {
|
|
|
+ UsbEndpoint ep = usbInterface.getEndpoint(i);
|
|
|
|
|
|
+ if (ep.getDirection() == UsbConstants.USB_DIR_OUT) {
|
|
|
+ //mUsbEndpointIn = ep;
|
|
|
+ mUsbEndpointOut = ep;
|
|
|
+ } else {
|
|
|
+ //mUsbEndpointOut = ep;
|
|
|
+ mUsbEndpointIn = ep;
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
+ if ((null == mUsbEndpointIn) || (null == mUsbEndpointOut)) {
|
|
|
+ mUsbDeviceConnection = mUsbManager.openDevice(usbDevice);
|
|
|
+ if (mUsbDeviceConnection!=null) {
|
|
|
+ int i = mUsbDeviceConnection.controlTransfer(0x00, 0x09,
|
|
|
+ 0x002, 0, null, 0, 100);
|
|
|
+ SystemClock.sleep(1000);
|
|
|
+ if (i >= 0) {
|
|
|
+ //mHandler.sendEmptyMessage(DEBUG_MESSAGE_SUCCESS);
|
|
|
} else {
|
|
|
-
|
|
|
-
|
|
|
- //if(0x80 == mUsbEndpointIn)
|
|
|
- bIsconnected = false;
|
|
|
- //isDetached = true;
|
|
|
- isNeedFindDevice = false;
|
|
|
-
|
|
|
- mUsbInterface = usbInterface;
|
|
|
- mUsbDeviceConnection = mUsbManager.openDevice(usbDevice);
|
|
|
- if(null != mUsbEndpointIn){
|
|
|
- iProductId = usbDevice.getProductId();
|
|
|
- bIsconnected = true;
|
|
|
- }
|
|
|
+ //mHandler.sendEmptyMessage(DEBUG_MESSAGE_ERROR);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+ } else {
|
|
|
+ bIsconnected = false;
|
|
|
+ isNeedFindDevice = false;
|
|
|
+ mUsbInterface = usbInterface;
|
|
|
+ mUsbDeviceConnection = mUsbManager.openDevice(usbDevice);
|
|
|
+ mUsbDeviceConnection.claimInterface(mUsbInterface, true);
|
|
|
+ if(null != mUsbEndpointIn){
|
|
|
+ iProductId = usbDevice.getProductId();
|
|
|
+ bIsconnected = true;
|
|
|
+ }
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
} else {
|
|
|
mUsbManager.requestPermission(usbDevice, PendingIntent.getBroadcast(mDataContext, 0, new Intent(""), 0));
|
|
|
}
|