Merge pull request #255 from TheSven73/fix-microchip-v2

Correctly determine Microchip pid:vid 04d8:000a device class
pull/261/head
Felipe Herranz 2019-07-07 23:46:12 +02:00 zatwierdzone przez GitHub
commit d0232ed59a
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
3 zmienionych plików z 25 dodań i 5 usunięć

Wyświetl plik

@ -1,5 +1,8 @@
package com.felhr.deviceids;
import android.hardware.usb.UsbDevice;
import android.hardware.usb.UsbInterface;
import static com.felhr.deviceids.Helpers.createTable;
import static com.felhr.deviceids.Helpers.createDevice;
@ -251,7 +254,6 @@ public class FTDISioIds
createDevice(0x03eb, 0x2109),
createDevice(0x0456, 0xf000),
createDevice(0x0456, 0xf001),
createDevice(0x04d8, 0x000a),
createDevice(0x0584, 0xb020),
createDevice(0x0647, 0x0100),
createDevice(0x06CE, 0x8311),
@ -560,7 +562,25 @@ public class FTDISioIds
createDevice(0x0403, 0x0) //fake FTDI reprogrammed by driver
);
public static boolean isDeviceSupported(int vendorId, int productId) {
private static boolean isMicrochipFtdi(UsbDevice dev) {
if (dev.getVendorId() != 0x04d8 || dev.getProductId() != 0x000a)
return false;
for (int i = 0; i < dev.getInterfaceCount(); i++) {
UsbInterface intf = dev.getInterface(i);
if (intf.getInterfaceClass() == 0xff && intf.getInterfaceSubclass() == 0xff &&
intf.getInterfaceProtocol() == 0x00)
return true;
}
return false;
}
public static boolean isDeviceSupported(UsbDevice dev) {
return Helpers.exists(ftdiDevices, dev.getVendorId(), dev.getProductId()) ||
isMicrochipFtdi(dev);
}
static boolean isDeviceIdSupported(int vendorId, int productId) {
return Helpers.exists(ftdiDevices, vendorId, productId);
}
}

Wyświetl plik

@ -72,7 +72,7 @@ public abstract class UsbSerialDevice implements UsbSerialInterface
int vid = device.getVendorId();
int pid = device.getProductId();
if(FTDISioIds.isDeviceSupported(vid, pid))
if(FTDISioIds.isDeviceSupported(device))
return new FTDISerialDevice(device, connection, iface);
else if(CP210xIds.isDeviceSupported(vid, pid))
return new CP2102SerialDevice(device, connection, iface);
@ -107,7 +107,7 @@ public abstract class UsbSerialDevice implements UsbSerialInterface
int vid = device.getVendorId();
int pid = device.getProductId();
if(FTDISioIds.isDeviceSupported(vid, pid))
if(FTDISioIds.isDeviceSupported(device))
return true;
else if(CP210xIds.isDeviceSupported(vid, pid))
return true;

Wyświetl plik

@ -48,7 +48,7 @@ public class DeviceIdTest {
for (TestCase tc : cases) {
Assert.assertTrue(CP210xIds.isDeviceSupported(tc.vendor, tc.product));
Assert.assertFalse(FTDISioIds.isDeviceSupported(tc.vendor, tc.product));
Assert.assertFalse(FTDISioIds.isDeviceIdSupported(tc.vendor, tc.product));
}
}