Skip to content

Commit

Permalink
Better fix to make sure we're only returning controllers from the HID…
Browse files Browse the repository at this point in the history
…API joystick API
  • Loading branch information
slouken committed Sep 1, 2018
1 parent 4ffcd88 commit 34237b8
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/joystick/controller_type.h
Expand Up @@ -286,7 +286,7 @@ static const ControllerDescription_t arrControllers[] = {
{ MAKE_CONTROLLER_ID( 0x1430, 0x4748 ), k_eControllerType_XBox360Controller }, // RedOctane Guitar Hero X-plorer
{ MAKE_CONTROLLER_ID( 0x1430, 0xf801 ), k_eControllerType_XBox360Controller }, // RedOctane Controller
{ MAKE_CONTROLLER_ID( 0x146b, 0x0601 ), k_eControllerType_XBox360Controller }, // BigBen Interactive XBOX 360 Controller
// { MAKE_CONTROLLER_ID( 0x1532, 0x0037 ), k_eControllerType_XBox360Controller }, // Razer Sabertooth - The Razer DeathAdder mouse also shows up as this VID/PID
{ MAKE_CONTROLLER_ID( 0x1532, 0x0037 ), k_eControllerType_XBox360Controller }, // Razer Sabertooth
{ MAKE_CONTROLLER_ID( 0x1532, 0x0a00 ), k_eControllerType_XBoxOneController }, // Razer Atrox Arcade Stick
{ MAKE_CONTROLLER_ID( 0x1532, 0x0a03 ), k_eControllerType_XBoxOneController }, // Razer Wildcat
{ MAKE_CONTROLLER_ID( 0x15e4, 0x3f00 ), k_eControllerType_XBox360Controller }, // Power A Mini Pro Elite
Expand Down
10 changes: 1 addition & 9 deletions src/joystick/hidapi/SDL_hidapi_ps4.c
Expand Up @@ -214,16 +214,8 @@ static uint8_t GetPlaystationVolumeFromFloat(float fVolume)
}

static SDL_bool
HIDAPI_DriverPS4_IsSupportedDevice(Uint16 vendor_id, Uint16 product_id, Uint16 version, int interface_number, Uint16 usage_page, Uint16 usage)
HIDAPI_DriverPS4_IsSupportedDevice(Uint16 vendor_id, Uint16 product_id, Uint16 version, int interface_number)
{
/* The Revolution Pro Controller and Razer Raiju expose multiple interfaces on Windows */
const Uint16 NACON_USB_VID = 0x146b;
const Uint16 RAZER_USB_VID = 0x1532;
if ((vendor_id == NACON_USB_VID || vendor_id == RAZER_USB_VID) &&
(usage_page != 0 && usage_page != 1)) {
return SDL_FALSE;
}

return SDL_IsJoystickPS4(vendor_id, product_id);
}

Expand Down
2 changes: 1 addition & 1 deletion src/joystick/hidapi/SDL_hidapi_switch.c
Expand Up @@ -210,7 +210,7 @@ typedef struct {


static SDL_bool
HIDAPI_DriverSwitch_IsSupportedDevice(Uint16 vendor_id, Uint16 product_id, Uint16 version, int interface_number, Uint16 usage_page, Uint16 usage)
HIDAPI_DriverSwitch_IsSupportedDevice(Uint16 vendor_id, Uint16 product_id, Uint16 version, int interface_number)
{
return SDL_IsJoystickNintendoSwitchPro(vendor_id, product_id);
}
Expand Down
2 changes: 1 addition & 1 deletion src/joystick/hidapi/SDL_hidapi_xbox360.c
Expand Up @@ -107,7 +107,7 @@ HIDAPI_DriverXbox360_GuessXInputSlot(WORD wButtons)
#endif /* __WIN32__ */

static SDL_bool
HIDAPI_DriverXbox360_IsSupportedDevice(Uint16 vendor_id, Uint16 product_id, Uint16 version, int interface_number, Uint16 usage_page, Uint16 usage)
HIDAPI_DriverXbox360_IsSupportedDevice(Uint16 vendor_id, Uint16 product_id, Uint16 version, int interface_number)
{
#if defined(__MACOSX__) || defined(__WIN32__)
if (vendor_id == 0x045e && product_id == 0x028e && version == 1) {
Expand Down
2 changes: 1 addition & 1 deletion src/joystick/hidapi/SDL_hidapi_xboxone.c
Expand Up @@ -131,7 +131,7 @@ typedef struct {


static SDL_bool
HIDAPI_DriverXboxOne_IsSupportedDevice(Uint16 vendor_id, Uint16 product_id, Uint16 version, int interface_number, Uint16 usage_page, Uint16 usage)
HIDAPI_DriverXboxOne_IsSupportedDevice(Uint16 vendor_id, Uint16 product_id, Uint16 version, int interface_number)
{
return SDL_IsJoystickXboxOne(vendor_id, product_id);
}
Expand Down
15 changes: 13 additions & 2 deletions src/joystick/hidapi/SDL_hidapijoystick.c
Expand Up @@ -552,7 +552,7 @@ HIDAPI_IsDeviceSupported(Uint16 vendor_id, Uint16 product_id, Uint16 version)

for (i = 0; i < SDL_arraysize(SDL_HIDAPI_drivers); ++i) {
SDL_HIDAPI_DeviceDriver *driver = SDL_HIDAPI_drivers[i];
if (driver->enabled && driver->IsSupportedDevice(vendor_id, product_id, version, -1, 0, 0)) {
if (driver->enabled && driver->IsSupportedDevice(vendor_id, product_id, version, -1)) {
return SDL_TRUE;
}
}
Expand All @@ -562,15 +562,26 @@ HIDAPI_IsDeviceSupported(Uint16 vendor_id, Uint16 product_id, Uint16 version)
static SDL_HIDAPI_DeviceDriver *
HIDAPI_GetDeviceDriver(SDL_HIDAPI_Device *device)
{
const Uint16 USAGE_PAGE_GENERIC_DESKTOP = 0x0001;
const Uint16 USAGE_JOYSTICK = 0x0004;
const Uint16 USAGE_GAMEPAD = 0x0005;
const Uint16 USAGE_MULTIAXISCONTROLLER = 0x0008;
int i;

if (SDL_ShouldIgnoreJoystick(device->name, device->guid)) {
return NULL;
}

if (device->usage_page && device->usage_page != USAGE_PAGE_GENERIC_DESKTOP) {
return NULL;
}
if (device->usage && device->usage != USAGE_JOYSTICK && device->usage != USAGE_GAMEPAD && device->usage != USAGE_MULTIAXISCONTROLLER) {
return NULL;
}

for (i = 0; i < SDL_arraysize(SDL_HIDAPI_drivers); ++i) {
SDL_HIDAPI_DeviceDriver *driver = SDL_HIDAPI_drivers[i];
if (driver->enabled && driver->IsSupportedDevice(device->vendor_id, device->product_id, device->version, device->interface_number, device->usage_page, device->usage)) {
if (driver->enabled && driver->IsSupportedDevice(device->vendor_id, device->product_id, device->version, device->interface_number)) {
return driver;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/joystick/hidapi/SDL_hidapijoystick_c.h
Expand Up @@ -45,7 +45,7 @@ typedef struct _SDL_HIDAPI_DeviceDriver
{
const char *hint;
SDL_bool enabled;
SDL_bool (*IsSupportedDevice)(Uint16 vendor_id, Uint16 product_id, Uint16 version, int interface_number, Uint16 usage_page, Uint16 usage);
SDL_bool (*IsSupportedDevice)(Uint16 vendor_id, Uint16 product_id, Uint16 version, int interface_number);
const char *(*GetDeviceName)(Uint16 vendor_id, Uint16 product_id);
SDL_bool (*Init)(SDL_Joystick *joystick, hid_device *dev, Uint16 vendor_id, Uint16 product_id, void **context);
int (*Rumble)(SDL_Joystick *joystick, hid_device *dev, void *context, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble, Uint32 duration_ms);
Expand Down

0 comments on commit 34237b8

Please sign in to comment.