kopia lustrzana https://github.com/mik3y/usb-serial-for-android
Porównaj commity
3 Commity
5db45548ba
...
9bd1f25773
Autor | SHA1 | Data |
---|---|---|
kai-morich | 9bd1f25773 | |
kai-morich | 083b9ae7fe | |
kai-morich | fd551970be |
|
@ -40,7 +40,7 @@ dependencyResolutionManagement {
|
|||
Add library to dependencies
|
||||
```gradle
|
||||
dependencies {
|
||||
implementation 'com.github.mik3y:usb-serial-for-android:3.4.6'
|
||||
implementation 'com.github.mik3y:usb-serial-for-android:3.5.1'
|
||||
}
|
||||
```
|
||||
|
||||
|
|
|
@ -37,30 +37,30 @@ public class CdcAcmSerialDriver implements UsbSerialDriver {
|
|||
public CdcAcmSerialDriver(UsbDevice device) {
|
||||
mDevice = device;
|
||||
mPorts = new ArrayList<>();
|
||||
int ports = countPorts(device);
|
||||
for (int port = 0; port < ports; port++) {
|
||||
mPorts.add(new CdcAcmSerialPort(mDevice, port));
|
||||
}
|
||||
if (mPorts.size() == 0) {
|
||||
mPorts.add(new CdcAcmSerialPort(mDevice, -1));
|
||||
}
|
||||
}
|
||||
int ports = countPorts(device);
|
||||
for (int port = 0; port < ports; port++) {
|
||||
mPorts.add(new CdcAcmSerialPort(mDevice, port));
|
||||
}
|
||||
if (mPorts.size() == 0) {
|
||||
mPorts.add(new CdcAcmSerialPort(mDevice, -1));
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings({"unused"})
|
||||
public static boolean probe(UsbDevice device) {
|
||||
return countPorts(device) > 0;
|
||||
}
|
||||
|
||||
private static int countPorts(UsbDevice device) {
|
||||
@SuppressWarnings({"unused"})
|
||||
public static boolean probe(UsbDevice device) {
|
||||
return countPorts(device) > 0;
|
||||
}
|
||||
|
||||
private static int countPorts(UsbDevice device) {
|
||||
int controlInterfaceCount = 0;
|
||||
int dataInterfaceCount = 0;
|
||||
for (int i = 0; i < device.getInterfaceCount(); i++) {
|
||||
if (device.getInterface(i).getInterfaceClass() == UsbConstants.USB_CLASS_COMM)
|
||||
for (int i = 0; i < device.getInterfaceCount(); i++) {
|
||||
if (device.getInterface(i).getInterfaceClass() == UsbConstants.USB_CLASS_COMM)
|
||||
controlInterfaceCount++;
|
||||
if (device.getInterface(i).getInterfaceClass() == UsbConstants.USB_CLASS_CDC_DATA)
|
||||
if (device.getInterface(i).getInterfaceClass() == UsbConstants.USB_CLASS_CDC_DATA)
|
||||
dataInterfaceCount++;
|
||||
}
|
||||
return Math.min(controlInterfaceCount, dataInterfaceCount);
|
||||
return Math.min(controlInterfaceCount, dataInterfaceCount);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -141,7 +141,7 @@ public class CdcAcmSerialDriver implements UsbSerialDriver {
|
|||
private void openInterface() throws IOException {
|
||||
Log.d(TAG, "claiming interfaces, count=" + mDevice.getInterfaceCount());
|
||||
|
||||
int rndisControlInterfaceCount = 0;
|
||||
int rndisControlInterfaceCount = 0;
|
||||
int controlInterfaceCount = 0;
|
||||
int dataInterfaceCount = 0;
|
||||
mControlInterface = null;
|
||||
|
@ -150,28 +150,28 @@ public class CdcAcmSerialDriver implements UsbSerialDriver {
|
|||
UsbInterface usbInterface = mDevice.getInterface(i);
|
||||
if (usbInterface.getInterfaceClass() == UsbConstants.USB_CLASS_COMM) {
|
||||
if(controlInterfaceCount == mPortNumber) {
|
||||
mControlIndex = i;
|
||||
mControlIndex = usbInterface.getId();
|
||||
mControlInterface = usbInterface;
|
||||
}
|
||||
controlInterfaceCount++;
|
||||
}
|
||||
if (usbInterface.getInterfaceClass() == UsbConstants.USB_CLASS_CDC_DATA) {
|
||||
if(dataInterfaceCount == mPortNumber + rndisControlInterfaceCount) {
|
||||
if(dataInterfaceCount == mPortNumber + rndisControlInterfaceCount) {
|
||||
mDataInterface = usbInterface;
|
||||
}
|
||||
dataInterfaceCount++;
|
||||
}
|
||||
if (mDataInterface == null &&
|
||||
usbInterface.getInterfaceClass() == UsbConstants.USB_CLASS_WIRELESS_CONTROLLER &&
|
||||
usbInterface.getInterfaceSubclass() == 1 &&
|
||||
usbInterface.getInterfaceProtocol() == 3) {
|
||||
/*
|
||||
* RNDIS is a MSFT variant of CDC-ACM states the Linux kernel in rndis_host.c
|
||||
* The devices provide IAD descriptors to indicate consecutive interfaces belonging
|
||||
* together, but this is not exposed to Java. So simply skip related data interfaces.
|
||||
*/
|
||||
rndisControlInterfaceCount++;
|
||||
}
|
||||
if (mDataInterface == null &&
|
||||
usbInterface.getInterfaceClass() == UsbConstants.USB_CLASS_WIRELESS_CONTROLLER &&
|
||||
usbInterface.getInterfaceSubclass() == 1 &&
|
||||
usbInterface.getInterfaceProtocol() == 3) {
|
||||
/*
|
||||
* RNDIS is a MSFT variant of CDC-ACM states the Linux kernel in rndis_host.c
|
||||
* The devices provide IAD descriptors to indicate consecutive interfaces belonging
|
||||
* together, but this is not exposed to Java. So simply skip related data interfaces.
|
||||
*/
|
||||
rndisControlInterfaceCount++;
|
||||
}
|
||||
}
|
||||
|
||||
if(mControlInterface == null) {
|
||||
|
@ -306,9 +306,9 @@ public class CdcAcmSerialDriver implements UsbSerialDriver {
|
|||
|
||||
}
|
||||
|
||||
@SuppressWarnings({"unused"})
|
||||
@SuppressWarnings({"unused"})
|
||||
public static Map<Integer, int[]> getSupportedDevices() {
|
||||
return new LinkedHashMap<>();
|
||||
return new LinkedHashMap<>();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Ładowanie…
Reference in New Issue