From 144956442d0aa281d916f6df104b405bd4457105 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Mon, 18 Nov 2019 11:44:51 -0800 Subject: [PATCH] Added identifiers for the Xbox One Elite Series 2 controller --- src/joystick/controller_type.h | 2 ++ src/joystick/hidapi/SDL_hidapi_xboxone.c | 23 ++++++++++++++++------- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/joystick/controller_type.h b/src/joystick/controller_type.h index 2411b738d3451..8ae50853437c2 100644 --- a/src/joystick/controller_type.h +++ b/src/joystick/controller_type.h @@ -83,6 +83,8 @@ static const ControllerDescription_t arrControllers[] = { { MAKE_CONTROLLER_ID( 0x045e, 0x02ea ), k_eControllerType_XBoxOneController }, // Microsoft X-Box One S pad { MAKE_CONTROLLER_ID( 0x045e, 0x02fd ), k_eControllerType_XBoxOneController }, // Microsoft X-Box One S pad (Bluetooth) { MAKE_CONTROLLER_ID( 0x045e, 0x02ff ), k_eControllerType_XBoxOneController }, // Microsoft X-Box One Elite pad + { MAKE_CONTROLLER_ID( 0x045e, 0x0b00 ), k_eControllerType_XBoxOneController }, // Microsoft X-Box One Elite Series 2 pad + { MAKE_CONTROLLER_ID( 0x045e, 0x0b05 ), k_eControllerType_XBoxOneController }, // Microsoft X-Box One Elite Series 2 pad (Bluetooth) { MAKE_CONTROLLER_ID( 0x045e, 0x0719 ), k_eControllerType_XBox360Controller }, // Xbox 360 Wireless Receiver { MAKE_CONTROLLER_ID( 0x046d, 0xc21d ), k_eControllerType_XBox360Controller }, // Logitech Gamepad F310 { MAKE_CONTROLLER_ID( 0x046d, 0xc21e ), k_eControllerType_XBox360Controller }, // Logitech Gamepad F510 diff --git a/src/joystick/hidapi/SDL_hidapi_xboxone.c b/src/joystick/hidapi/SDL_hidapi_xboxone.c index 0e97fe99d4f5d..d636762cb0bf4 100644 --- a/src/joystick/hidapi/SDL_hidapi_xboxone.c +++ b/src/joystick/hidapi/SDL_hidapi_xboxone.c @@ -130,12 +130,25 @@ typedef struct { } SDL_DriverXboxOne_Context; +static SDL_bool +IsBluetoothXboxOneController(Uint16 vendor_id, Uint16 product_id) +{ + /* Check to see if it's the Xbox One S or Xbox One Elite Series 2 in Bluetooth mode */ + const Uint16 USB_VENDOR_MICROSOFT = 0x045e; + const Uint16 USB_PRODUCT_XBOX_ONE_S = 0x02fd; + const Uint16 USB_PRODUCT_XBOX_ONE_ELITE_SERIES_2 = 0x0b05; + + if (vendor_id == USB_VENDOR_MICROSOFT && (product_id == USB_PRODUCT_XBOX_ONE_S || product_id == USB_PRODUCT_XBOX_ONE_ELITE_SERIES_2)) { + return SDL_TRUE; + } + return SDL_FALSE; +} + static SDL_bool HIDAPI_DriverXboxOne_IsSupportedDevice(Uint16 vendor_id, Uint16 product_id, Uint16 version, int interface_number, const char *name) { #ifdef __LINUX__ - /* Check to see if it's the Xbox One S in Bluetooth mode */ - if (vendor_id == 0x045e && product_id == 0x02fd) { + if (IsBluetoothXboxOneController(vendor_id, product_id)) { /* We can't do rumble on this device, hid_write() fails, so don't try to open it here */ return SDL_FALSE; } @@ -155,7 +168,6 @@ HIDAPI_DriverXboxOne_Init(SDL_Joystick *joystick, hid_device *dev, Uint16 vendor SDL_DriverXboxOne_Context *ctx; int i; Uint8 init_packet[USB_PACKET_LENGTH]; - SDL_bool is_bluetooth = SDL_FALSE; ctx = (SDL_DriverXboxOne_Context *)SDL_calloc(1, sizeof(*ctx)); if (!ctx) { @@ -164,10 +176,7 @@ HIDAPI_DriverXboxOne_Init(SDL_Joystick *joystick, hid_device *dev, Uint16 vendor } *context = ctx; - if (vendor_id == 0x045e && product_id == 0x02fd) { - is_bluetooth = SDL_TRUE; - } - if (!is_bluetooth) { + if (!IsBluetoothXboxOneController(vendor_id, product_id)) { /* Send the controller init data */ for (i = 0; i < SDL_arraysize(xboxone_init_packets); ++i) { const SDL_DriverXboxOne_InitPacket *packet = &xboxone_init_packets[i];