|
@@ -572,7 +572,8 @@ public class GT9MainActivity extends AppCompatActivity
|
|
|
for (UsbDevice usbDevice : deviceList.values()) {
|
|
|
//int productId = usbDevice.getProductId();
|
|
|
int vendorId = usbDevice.getVendorId();
|
|
|
- if (( vendorId == 0x27C0)
|
|
|
+ if ((vendorId == 0x27C0)
|
|
|
+ ||(vendorId == 0x27C6)
|
|
|
||(vendorId == 0x222A) //奕力的VID
|
|
|
||(vendorId == 0x056A)) //8191主动笔和Wacom主动笔
|
|
|
{
|
|
@@ -623,71 +624,54 @@ public class GT9MainActivity extends AppCompatActivity
|
|
|
if (!values.isEmpty()) {
|
|
|
for (UsbDevice usbDevice : values) {
|
|
|
//int productId = usbDevice.getProductId();
|
|
|
- int vendorId = usbDevice.getVendorId();
|
|
|
+ int iVendorId = usbDevice.getVendorId();
|
|
|
//if (productId == 0x0818 || productId == 0x0001 )
|
|
|
- if (( vendorId == 0x27C0)
|
|
|
- ||(vendorId == 0x222A) //奕力的VID
|
|
|
- ||(vendorId == 0x056A)) //8191主动笔和Wacom主动笔
|
|
|
- { //0x0001是奕力的PID
|
|
|
+ if ((iVendorId == 0x27C0) //之前VID错误了,做兼容
|
|
|
+ ||(iVendorId == 0x27C6) //汇顶的VID
|
|
|
+ ||(iVendorId == 0x222A) //奕力的VID
|
|
|
+ ||(iVendorId == 0x056A)) //8191主动笔和Wacom主动笔
|
|
|
+ {
|
|
|
|
|
|
if (mUsbManager.hasPermission(usbDevice)) {
|
|
|
+ UsbInterface usbInterface = usbDevice.getInterface(1);
|
|
|
|
|
|
- mUsbDeviceConnection = mUsbManager.openDevice(usbDevice);
|
|
|
- if (mUsbDeviceConnection != null) {
|
|
|
-
|
|
|
- {
|
|
|
-
|
|
|
- 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);
|
|
|
|
|
|
- for (int i = 0; i < usbInterface.getEndpointCount(); i++) {
|
|
|
- UsbEndpoint ep = usbInterface.getEndpoint(i);
|
|
|
- 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 (ep.getDirection() == UsbConstants.USB_DIR_OUT) {
|
|
|
+ //mUsbEndpointIn = ep;
|
|
|
+ mUsbEndpointOut = ep;
|
|
|
+ } else {
|
|
|
+ //mUsbEndpointOut = ep;
|
|
|
+ mUsbEndpointIn = ep;
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- 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);
|
|
|
- }
|
|
|
+ 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)
|
|
|
- //mlog1.setEnabled(true);
|
|
|
- mToggle = false;
|
|
|
- isDetached = true;
|
|
|
- isNeedFindDevice = false;
|
|
|
- // mSendMessage.setEnabled(true);
|
|
|
-
|
|
|
- mUsbInterface = usbInterface;
|
|
|
- mUsbDeviceConnection = mUsbManager.openDevice(usbDevice);
|
|
|
- if(null != mUsbEndpointIn){
|
|
|
- mHandler.sendEmptyMessage(CONNECTED_SUCCESS);
|
|
|
- }
|
|
|
-
|
|
|
+ //mHandler.sendEmptyMessage(DEBUG_MESSAGE_ERROR);
|
|
|
}
|
|
|
}
|
|
|
+ } else {
|
|
|
+ isNeedFindDevice = false;
|
|
|
+ mUsbInterface = usbInterface;
|
|
|
+ mUsbDeviceConnection = mUsbManager.openDevice(usbDevice);
|
|
|
+ mUsbDeviceConnection.claimInterface(mUsbInterface, true);
|
|
|
+ if(null != mUsbEndpointIn){
|
|
|
+ //iProductId = usbDevice.getProductId();
|
|
|
+ mHandler.sendEmptyMessage(CONNECTED_SUCCESS);
|
|
|
+ }
|
|
|
}
|
|
|
- } else {
|
|
|
+
|
|
|
+ }
|
|
|
+ else {
|
|
|
mUsbManager.requestPermission(usbDevice, PendingIntent.getBroadcast(mShowID, 0, new Intent(""), 0));
|
|
|
}
|
|
|
}
|