Added support for wireless Xbox 360 controllers using the HIDAPI driver
authorSam Lantinga <slouken@libsdl.org>
Thu, 19 Dec 2019 15:01:32 -0800
changeset 133551adaa20a4ae0
parent 13354 8c22865bd138
child 13356 6c431d30a6df
Added support for wireless Xbox 360 controllers using the HIDAPI driver
android-project/app/src/main/java/org/libsdl/app/HIDDeviceManager.java
src/hidapi/libusb/hid.c
src/joystick/controller_type.h
src/joystick/hidapi/SDL_hidapijoystick.c
src/joystick/hidapi/SDL_hidapijoystick_c.h
     1.1 --- a/android-project/app/src/main/java/org/libsdl/app/HIDDeviceManager.java	Thu Dec 19 15:01:30 2019 -0800
     1.2 +++ b/android-project/app/src/main/java/org/libsdl/app/HIDDeviceManager.java	Thu Dec 19 15:01:32 2019 -0800
     1.3 @@ -255,17 +255,16 @@
     1.4          if (usbInterface.getInterfaceClass() == UsbConstants.USB_CLASS_HID) {
     1.5              return true;
     1.6          }
     1.7 -        if (interface_number == 0) {
     1.8 -            if (isXbox360Controller(usbDevice, usbInterface) || isXboxOneController(usbDevice, usbInterface)) {
     1.9 -                return true;
    1.10 -            }
    1.11 +        if (isXbox360Controller(usbDevice, usbInterface) || isXboxOneController(usbDevice, usbInterface)) {
    1.12 +            return true;
    1.13          }
    1.14          return false;
    1.15      }
    1.16  
    1.17      private boolean isXbox360Controller(UsbDevice usbDevice, UsbInterface usbInterface) {
    1.18          final int XB360_IFACE_SUBCLASS = 93;
    1.19 -        final int XB360_IFACE_PROTOCOL = 1; // Wired only
    1.20 +        final int XB360_IFACE_PROTOCOL = 1; // Wired
    1.21 +        final int XB360W_IFACE_PROTOCOL = 129; // Wireless
    1.22          final int[] SUPPORTED_VENDORS = {
    1.23              0x0079, // GPD Win 2
    1.24              0x044f, // Thrustmaster
    1.25 @@ -290,10 +289,10 @@
    1.26              0x24c6, // PowerA
    1.27          };
    1.28  
    1.29 -        if (usbInterface.getId() == 0 &&
    1.30 -            usbInterface.getInterfaceClass() == UsbConstants.USB_CLASS_VENDOR_SPEC &&
    1.31 +        if (usbInterface.getInterfaceClass() == UsbConstants.USB_CLASS_VENDOR_SPEC &&
    1.32              usbInterface.getInterfaceSubclass() == XB360_IFACE_SUBCLASS &&
    1.33 -            usbInterface.getInterfaceProtocol() == XB360_IFACE_PROTOCOL) {
    1.34 +            (usbInterface.getInterfaceProtocol() == XB360_IFACE_PROTOCOL ||
    1.35 +             usbInterface.getInterfaceProtocol() == XB360W_IFACE_PROTOCOL)) {
    1.36              int vendor_id = usbDevice.getVendorId();
    1.37              for (int supportedVid : SUPPORTED_VENDORS) {
    1.38                  if (vendor_id == supportedVid) {
     2.1 --- a/src/hidapi/libusb/hid.c	Thu Dec 19 15:01:30 2019 -0800
     2.2 +++ b/src/hidapi/libusb/hid.c	Thu Dec 19 15:01:32 2019 -0800
     2.3 @@ -481,7 +481,8 @@
     2.4  static int is_xbox360(unsigned short vendor_id, const struct libusb_interface_descriptor *intf_desc)
     2.5  {
     2.6  	static const int XB360_IFACE_SUBCLASS = 93;
     2.7 -	static const int XB360_IFACE_PROTOCOL = 1; /* Wired only */
     2.8 +	static const int XB360_IFACE_PROTOCOL = 1; /* Wired */
     2.9 +	static const int XB360W_IFACE_PROTOCOL = 129; /* Wireless */
    2.10  	static const int SUPPORTED_VENDORS[] = {
    2.11  		0x0079, /* GPD Win 2 */
    2.12  		0x044f, /* Thrustmaster */
    2.13 @@ -506,10 +507,10 @@
    2.14  		0x24c6, /* PowerA */
    2.15  	};
    2.16  
    2.17 -	if (intf_desc->bInterfaceNumber == 0 &&
    2.18 -	    intf_desc->bInterfaceClass == LIBUSB_CLASS_VENDOR_SPEC &&
    2.19 +	if (intf_desc->bInterfaceClass == LIBUSB_CLASS_VENDOR_SPEC &&
    2.20  	    intf_desc->bInterfaceSubClass == XB360_IFACE_SUBCLASS &&
    2.21 -	    intf_desc->bInterfaceProtocol == XB360_IFACE_PROTOCOL) {
    2.22 +	    (intf_desc->bInterfaceProtocol == XB360_IFACE_PROTOCOL ||
    2.23 +	     intf_desc->bInterfaceProtocol == XB360W_IFACE_PROTOCOL)) {
    2.24  		int i;
    2.25  		for (i = 0; i < sizeof(SUPPORTED_VENDORS)/sizeof(SUPPORTED_VENDORS[0]); ++i) {
    2.26  			if (vendor_id == SUPPORTED_VENDORS[i]) {
     3.1 --- a/src/joystick/controller_type.h	Thu Dec 19 15:01:30 2019 -0800
     3.2 +++ b/src/joystick/controller_type.h	Thu Dec 19 15:01:32 2019 -0800
     3.3 @@ -169,7 +169,7 @@
     3.4  	{ MAKE_CONTROLLER_ID( 0x044f, 0xb326 ), k_eControllerType_XBox360Controller, NULL },	// Thrustmaster Gamepad GP XID
     3.5  	{ MAKE_CONTROLLER_ID( 0x045e, 0x028e ), k_eControllerType_XBox360Controller, "Xbox 360 Controller" },	// Microsoft X-Box 360 pad
     3.6  	{ MAKE_CONTROLLER_ID( 0x045e, 0x028f ), k_eControllerType_XBox360Controller, "Xbox 360 Controller" },	// Microsoft X-Box 360 pad v2
     3.7 -	{ MAKE_CONTROLLER_ID( 0x045e, 0x0291 ), k_eControllerType_XBox360Controller, NULL },	// Xbox 360 Wireless Receiver (XBOX)
     3.8 +	{ MAKE_CONTROLLER_ID( 0x045e, 0x0291 ), k_eControllerType_XBox360Controller, "Xbox 360 Wireless Controller" },	// Xbox 360 Wireless Receiver (XBOX)
     3.9  	{ MAKE_CONTROLLER_ID( 0x045e, 0x02a0 ), k_eControllerType_XBox360Controller, NULL },	// Microsoft X-Box 360 Big Button IR
    3.10  	{ MAKE_CONTROLLER_ID( 0x045e, 0x02a1 ), k_eControllerType_XBox360Controller, NULL },	// Microsoft X-Box 360 pad
    3.11  	{ MAKE_CONTROLLER_ID( 0x045e, 0x0719 ), k_eControllerType_XBox360Controller, "Xbox 360 Wireless Controller" },	// Xbox 360 Wireless Receiver
     4.1 --- a/src/joystick/hidapi/SDL_hidapijoystick.c	Thu Dec 19 15:01:30 2019 -0800
     4.2 +++ b/src/joystick/hidapi/SDL_hidapijoystick.c	Thu Dec 19 15:01:32 2019 -0800
     4.3 @@ -69,6 +69,7 @@
     4.4  #endif
     4.5  #ifdef SDL_JOYSTICK_HIDAPI_XBOX360
     4.6      &SDL_HIDAPI_DriverXbox360,
     4.7 +    &SDL_HIDAPI_DriverXbox360W,
     4.8  #endif
     4.9  #ifdef SDL_JOYSTICK_HIDAPI_XBOXONE
    4.10      &SDL_HIDAPI_DriverXboxOne,
     5.1 --- a/src/joystick/hidapi/SDL_hidapijoystick_c.h	Thu Dec 19 15:01:30 2019 -0800
     5.2 +++ b/src/joystick/hidapi/SDL_hidapijoystick_c.h	Thu Dec 19 15:01:32 2019 -0800
     5.3 @@ -93,6 +93,7 @@
     5.4  extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverSteam;
     5.5  extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverSwitch;
     5.6  extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverXbox360;
     5.7 +extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverXbox360W;
     5.8  extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverXboxOne;
     5.9  
    5.10  /* Return true if a HID device is present and supported as a joystick */