Add support for more Xbox controller models

This commit is contained in:
Cameron Gutman 2016-06-13 22:28:48 -05:00
parent 26a4fc75a5
commit 36be943854
2 changed files with 44 additions and 61 deletions

View File

@ -10,56 +10,38 @@ import com.limelight.nvstream.input.ControllerPacket;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
public class Xbox360Controller extends AbstractXboxController { public class Xbox360Controller extends AbstractXboxController {
private static final int XB360_IFACE_SUBCLASS = 93;
private static final int XB360_IFACE_PROTOCOL = 1; // Wired only
// This list is taken from the Xpad driver in the Linux kernel. private static final int[] SUPPORTED_VENDORS = {
// I've excluded the devices that aren't "controllers" in the traditional sense, but 0x044f, // Thrustmaster
// if people really want to use their dancepads or fight sticks with Moonlight, I can 0x045e, // Microsoft
// put them in. 0x046d, // Logitech
private static final DeviceIdTuple[] supportedDeviceTuples = { 0x0738, // Mad Catz
new DeviceIdTuple(0x045e, 0x028e, "Microsoft X-Box 360 pad"), 0x0e6f, // Unknown
new DeviceIdTuple(0x044f, 0xb326, "Thrustmaster Gamepad GP XID"), 0x12ab, // Unknown
new DeviceIdTuple(0x046d, 0xc21d, "Logitech Gamepad F310"), 0x1430, // RedOctane
new DeviceIdTuple(0x046d, 0xc21e, "Logitech Gamepad F510"), 0x146b, // BigBen
new DeviceIdTuple(0x046d, 0xc21f, "Logitech Gamepad F710"), 0x1bad, // Harmonix
new DeviceIdTuple(0x046d, 0xc242, "Logitech Chillstream Controller"), 0x0f0d, // Hori
new DeviceIdTuple(0x0738, 0x4716, "Mad Catz Wired Xbox 360 Controller"), 0x1689, // Razer Onza
new DeviceIdTuple(0x0738, 0x4726, "Mad Catz Xbox 360 Controller"), 0x24c6, // PowerA
new DeviceIdTuple(0x0738, 0xb726, "Mad Catz Xbox controller - MW2"), 0x1532, // Razer Sabertooth
new DeviceIdTuple(0x0738, 0xbeef, "Mad Catz JOYTECH NEO SE Advanced GamePad"), 0x15e4, // Numark
new DeviceIdTuple(0x0738, 0xcb02, "Saitek Cyborg Rumble Pad - PC/Xbox 360"), 0x162e, // Joytech
new DeviceIdTuple(0x0738, 0xcb03, "Saitek P3200 Rumble Pad - PC/Xbox 360"),
new DeviceIdTuple(0x0e6f, 0x0113, "Afterglow AX.1 Gamepad for Xbox 360"),
new DeviceIdTuple(0x0e6f, 0x0201, "Pelican PL-3601 'TSZ' Wired Xbox 360 Controller"),
new DeviceIdTuple(0x0e6f, 0x0213, "Afterglow Gamepad for Xbox 360"),
new DeviceIdTuple(0x0e6f, 0x021f, "Rock Candy Gamepad for Xbox 360"),
new DeviceIdTuple(0x0e6f, 0x0301, "Logic3 Controller"),
new DeviceIdTuple(0x0e6f, 0x0401, "Logic3 Controller"),
new DeviceIdTuple(0x12ab, 0x0301, "PDP AFTERGLOW AX.1"),
new DeviceIdTuple(0x146b, 0x0601, "BigBen Interactive XBOX 360 Controller"),
new DeviceIdTuple(0x1532, 0x0037, "Razer Sabertooth"),
new DeviceIdTuple(0x15e4, 0x3f00, "Power A Mini Pro Elite"),
new DeviceIdTuple(0x15e4, 0x3f0a, "Xbox Airflo wired controller"),
new DeviceIdTuple(0x15e4, 0x3f10, "Batarang Xbox 360 controller"),
new DeviceIdTuple(0x162e, 0xbeef, "Joytech Neo-Se Take2"),
new DeviceIdTuple(0x1689, 0xfd00, "Razer Onza Tournament Edition"),
new DeviceIdTuple(0x1689, 0xfd01, "Razer Onza Classic Edition"),
new DeviceIdTuple(0x24c6, 0x5d04, "Razer Sabertooth"),
new DeviceIdTuple(0x1bad, 0xf016, "Mad Catz Xbox 360 Controller"),
new DeviceIdTuple(0x1bad, 0xf023, "MLG Pro Circuit Controller (Xbox)"),
new DeviceIdTuple(0x1bad, 0xf900, "Harmonix Xbox 360 Controller"),
new DeviceIdTuple(0x1bad, 0xf901, "Gamestop Xbox 360 Controller"),
new DeviceIdTuple(0x1bad, 0xf903, "Tron Xbox 360 controller"),
new DeviceIdTuple(0x24c6, 0x5300, "PowerA MINI PROEX Controller"),
new DeviceIdTuple(0x24c6, 0x5303, "Xbox Airflo wired controller"),
}; };
public static boolean canClaimDevice(UsbDevice device) { public static boolean canClaimDevice(UsbDevice device) {
for (DeviceIdTuple tuple : supportedDeviceTuples) { for (int supportedVid : SUPPORTED_VENDORS) {
if (device.getVendorId() == tuple.vid && device.getProductId() == tuple.pid) { if (device.getVendorId() == supportedVid &&
LimeLog.info("XB360 can claim device: " + tuple.name); device.getInterfaceCount() >= 1 &&
device.getInterface(0).getInterfaceClass() == UsbConstants.USB_CLASS_VENDOR_SPEC &&
device.getInterface(0).getInterfaceSubclass() == XB360_IFACE_SUBCLASS &&
device.getInterface(0).getInterfaceProtocol() == XB360_IFACE_PROTOCOL) {
return true; return true;
} }
} }
return false; return false;
} }
@ -151,16 +133,4 @@ public class Xbox360Controller extends AbstractXboxController {
// No need to fail init if the LED command fails // No need to fail init if the LED command fails
return true; return true;
} }
private static class DeviceIdTuple {
public final int vid;
public final int pid;
public final String name;
public DeviceIdTuple(int vid, int pid, String name) {
this.vid = vid;
this.pid = pid;
this.name = name;
}
}
} }

View File

@ -15,10 +15,17 @@ import java.nio.ByteOrder;
public class XboxOneController extends AbstractXboxController { public class XboxOneController extends AbstractXboxController {
private static final int MICROSOFT_VID = 0x045e;
private static final int XB1_IFACE_SUBCLASS = 71; private static final int XB1_IFACE_SUBCLASS = 71;
private static final int XB1_IFACE_PROTOCOL = 208; private static final int XB1_IFACE_PROTOCOL = 208;
private static final int[] SUPPORTED_VENDORS = {
0x045e, // Microsoft
0x0738, // Mad Catz
0x0e6f, // Unknown
0x0f0d, // Hori
0x24c6, // PowerA
};
// FIXME: odata_serial // FIXME: odata_serial
private static final byte[] XB1_INIT_DATA = {0x05, 0x20, 0x00, 0x01, 0x00}; private static final byte[] XB1_INIT_DATA = {0x05, 0x20, 0x00, 0x01, 0x00};
@ -78,11 +85,17 @@ public class XboxOneController extends AbstractXboxController {
} }
public static boolean canClaimDevice(UsbDevice device) { public static boolean canClaimDevice(UsbDevice device) {
return device.getVendorId() == MICROSOFT_VID && for (int supportedVid : SUPPORTED_VENDORS) {
if (device.getVendorId() == supportedVid &&
device.getInterfaceCount() >= 1 && device.getInterfaceCount() >= 1 &&
device.getInterface(0).getInterfaceClass() == UsbConstants.USB_CLASS_VENDOR_SPEC && device.getInterface(0).getInterfaceClass() == UsbConstants.USB_CLASS_VENDOR_SPEC &&
device.getInterface(0).getInterfaceSubclass() == XB1_IFACE_SUBCLASS && device.getInterface(0).getInterfaceSubclass() == XB1_IFACE_SUBCLASS &&
device.getInterface(0).getInterfaceProtocol() == XB1_IFACE_PROTOCOL; device.getInterface(0).getInterfaceProtocol() == XB1_IFACE_PROTOCOL) {
return true;
}
}
return false;
} }
@Override @Override