Separate the controller protocol from the controller style
This allows us to handle controllers that use the Xbox protocol but look like Nintendo Switch or Playstation controllers, like the Qanba Dragon Arcade Stick in PC mode
This commit is contained in:
parent
94f6080895
commit
16f55fbdb4
6 changed files with 211 additions and 202 deletions
|
@ -110,11 +110,96 @@ HIDAPI_RemapVal(float val, float val_min, float val_max, float output_min, float
|
|||
static void HIDAPI_JoystickDetect(void);
|
||||
static void HIDAPI_JoystickClose(SDL_Joystick *joystick);
|
||||
|
||||
static SDL_GameControllerType
|
||||
SDL_GetJoystickGameControllerProtocol(const char *name, Uint16 vendor, Uint16 product, int interface_number, int interface_class, int interface_subclass, int interface_protocol)
|
||||
{
|
||||
static const int LIBUSB_CLASS_VENDOR_SPEC = 0xFF;
|
||||
static const int XB360_IFACE_SUBCLASS = 93;
|
||||
static const int XB360_IFACE_PROTOCOL = 1; /* Wired */
|
||||
static const int XB360W_IFACE_PROTOCOL = 129; /* Wireless */
|
||||
static const int XBONE_IFACE_SUBCLASS = 71;
|
||||
static const int XBONE_IFACE_PROTOCOL = 208;
|
||||
|
||||
SDL_GameControllerType type = SDL_CONTROLLER_TYPE_UNKNOWN;
|
||||
|
||||
/* This code should match the checks in libusb/hid.c and HIDDeviceManager.java */
|
||||
if (interface_class == LIBUSB_CLASS_VENDOR_SPEC &&
|
||||
interface_subclass == XB360_IFACE_SUBCLASS &&
|
||||
(interface_protocol == XB360_IFACE_PROTOCOL ||
|
||||
interface_protocol == XB360W_IFACE_PROTOCOL)) {
|
||||
|
||||
static const int SUPPORTED_VENDORS[] = {
|
||||
0x0079, /* GPD Win 2 */
|
||||
0x044f, /* Thrustmaster */
|
||||
0x045e, /* Microsoft */
|
||||
0x046d, /* Logitech */
|
||||
0x056e, /* Elecom */
|
||||
0x06a3, /* Saitek */
|
||||
0x0738, /* Mad Catz */
|
||||
0x07ff, /* Mad Catz */
|
||||
0x0e6f, /* PDP */
|
||||
0x0f0d, /* Hori */
|
||||
0x1038, /* SteelSeries */
|
||||
0x11c9, /* Nacon */
|
||||
0x12ab, /* Unknown */
|
||||
0x1430, /* RedOctane */
|
||||
0x146b, /* BigBen */
|
||||
0x1532, /* Razer */
|
||||
0x15e4, /* Numark */
|
||||
0x162e, /* Joytech */
|
||||
0x1689, /* Razer Onza */
|
||||
0x1949, /* Lab126, Inc. */
|
||||
0x1bad, /* Harmonix */
|
||||
0x20d6, /* PowerA */
|
||||
0x24c6, /* PowerA */
|
||||
0x2c22, /* Qanba */
|
||||
};
|
||||
|
||||
int i;
|
||||
for (i = 0; i < SDL_arraysize(SUPPORTED_VENDORS); ++i) {
|
||||
if (vendor == SUPPORTED_VENDORS[i]) {
|
||||
type = SDL_CONTROLLER_TYPE_XBOX360;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (interface_number == 0 &&
|
||||
interface_class == LIBUSB_CLASS_VENDOR_SPEC &&
|
||||
interface_subclass == XBONE_IFACE_SUBCLASS &&
|
||||
interface_protocol == XBONE_IFACE_PROTOCOL) {
|
||||
|
||||
static const int SUPPORTED_VENDORS[] = {
|
||||
0x045e, /* Microsoft */
|
||||
0x0738, /* Mad Catz */
|
||||
0x0e6f, /* PDP */
|
||||
0x0f0d, /* Hori */
|
||||
0x1532, /* Razer */
|
||||
0x20d6, /* PowerA */
|
||||
0x24c6, /* PowerA */
|
||||
0x2e24, /* Hyperkin */
|
||||
};
|
||||
|
||||
int i;
|
||||
for (i = 0; i < SDL_arraysize(SUPPORTED_VENDORS); ++i) {
|
||||
if (vendor == SUPPORTED_VENDORS[i]) {
|
||||
type = SDL_CONTROLLER_TYPE_XBOXONE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (type == SDL_CONTROLLER_TYPE_UNKNOWN) {
|
||||
type = SDL_GetJoystickGameControllerTypeFromVIDPID(vendor, product, name, SDL_FALSE);
|
||||
}
|
||||
return type;
|
||||
}
|
||||
|
||||
static SDL_bool
|
||||
HIDAPI_IsDeviceSupported(Uint16 vendor_id, Uint16 product_id, Uint16 version, const char *name)
|
||||
{
|
||||
int i;
|
||||
SDL_GameControllerType type = SDL_GetJoystickGameControllerType(name, vendor_id, product_id, -1, 0, 0, 0);
|
||||
SDL_GameControllerType type = SDL_GetJoystickGameControllerProtocol(name, vendor_id, product_id, -1, 0, 0, 0);
|
||||
|
||||
for (i = 0; i < SDL_arraysize(SDL_HIDAPI_drivers); ++i) {
|
||||
SDL_HIDAPI_DeviceDriver *driver = SDL_HIDAPI_drivers[i];
|
||||
|
@ -148,7 +233,7 @@ HIDAPI_GetDeviceDriver(SDL_HIDAPI_Device *device)
|
|||
}
|
||||
}
|
||||
|
||||
type = SDL_GetJoystickGameControllerType(device->name, device->vendor_id, device->product_id, device->interface_number, device->interface_class, device->interface_subclass, device->interface_protocol);
|
||||
type = SDL_GetJoystickGameControllerProtocol(device->name, device->vendor_id, device->product_id, device->interface_number, device->interface_class, device->interface_subclass, device->interface_protocol);
|
||||
for (i = 0; i < SDL_arraysize(SDL_HIDAPI_drivers); ++i) {
|
||||
SDL_HIDAPI_DeviceDriver *driver = SDL_HIDAPI_drivers[i];
|
||||
if (driver->enabled && driver->IsSupportedDevice(device->name, type, device->vendor_id, device->product_id, device->version, device->interface_number, device->interface_class, device->interface_subclass, device->interface_protocol)) {
|
||||
|
@ -457,38 +542,6 @@ HIDAPI_AddDevice(struct SDL_hid_device_info *info)
|
|||
char *serial_number = HIDAPI_ConvertString(info->serial_number);
|
||||
|
||||
device->name = SDL_CreateJoystickName(device->vendor_id, device->product_id, manufacturer_string, product_string);
|
||||
if (SDL_strncmp(device->name, "0x", 2) == 0) {
|
||||
/* Couldn't find a controller name, try to give it one based on device type */
|
||||
const char *name = NULL;
|
||||
|
||||
switch (SDL_GetJoystickGameControllerType(NULL, device->vendor_id, device->product_id, device->interface_number, device->interface_class, device->interface_subclass, device->interface_protocol)) {
|
||||
case SDL_CONTROLLER_TYPE_XBOX360:
|
||||
name = "Xbox 360 Controller";
|
||||
break;
|
||||
case SDL_CONTROLLER_TYPE_XBOXONE:
|
||||
name = "Xbox One Controller";
|
||||
break;
|
||||
case SDL_CONTROLLER_TYPE_PS3:
|
||||
name = "PS3 Controller";
|
||||
break;
|
||||
case SDL_CONTROLLER_TYPE_PS4:
|
||||
name = "PS4 Controller";
|
||||
break;
|
||||
case SDL_CONTROLLER_TYPE_PS5:
|
||||
name = "PS5 Controller";
|
||||
break;
|
||||
case SDL_CONTROLLER_TYPE_NINTENDO_SWITCH_PRO:
|
||||
name = "Nintendo Switch Pro Controller";
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (name) {
|
||||
SDL_free(device->name);
|
||||
device->name = SDL_strdup(name);
|
||||
}
|
||||
}
|
||||
|
||||
if (manufacturer_string) {
|
||||
SDL_free(manufacturer_string);
|
||||
|
@ -621,13 +674,13 @@ HIDAPI_IsEquivalentToDevice(Uint16 vendor_id, Uint16 product_id, SDL_HIDAPI_Devi
|
|||
|
||||
/* If we're looking for the raw input Xbox One controller, match it against any other Xbox One controller */
|
||||
if (product_id == USB_PRODUCT_XBOX_ONE_XBOXGIP_CONTROLLER &&
|
||||
SDL_GetJoystickGameControllerType(device->name, device->vendor_id, device->product_id, device->interface_number, device->interface_class, device->interface_subclass, device->interface_protocol) == SDL_CONTROLLER_TYPE_XBOXONE) {
|
||||
SDL_GetJoystickGameControllerProtocol(device->name, device->vendor_id, device->product_id, device->interface_number, device->interface_class, device->interface_subclass, device->interface_protocol) == SDL_CONTROLLER_TYPE_XBOXONE) {
|
||||
return SDL_TRUE;
|
||||
}
|
||||
|
||||
/* If we're looking for an XInput controller, match it against any other Xbox controller */
|
||||
if (product_id == USB_PRODUCT_XBOX_ONE_XINPUT_CONTROLLER) {
|
||||
SDL_GameControllerType type = SDL_GetJoystickGameControllerType(device->name, device->vendor_id, device->product_id, device->interface_number, device->interface_class, device->interface_subclass, device->interface_protocol);
|
||||
SDL_GameControllerType type = SDL_GetJoystickGameControllerProtocol(device->name, device->vendor_id, device->product_id, device->interface_number, device->interface_class, device->interface_subclass, device->interface_protocol);
|
||||
if (type == SDL_CONTROLLER_TYPE_XBOX360 || type == SDL_CONTROLLER_TYPE_XBOXONE) {
|
||||
return SDL_TRUE;
|
||||
}
|
||||
|
@ -656,7 +709,7 @@ HIDAPI_IsDeviceTypePresent(SDL_GameControllerType type)
|
|||
device = SDL_HIDAPI_devices;
|
||||
while (device) {
|
||||
if (device->driver &&
|
||||
SDL_GetJoystickGameControllerType(device->name, device->vendor_id, device->product_id, device->interface_number, device->interface_class, device->interface_subclass, device->interface_protocol) == type) {
|
||||
SDL_GetJoystickGameControllerProtocol(device->name, device->vendor_id, device->product_id, device->interface_number, device->interface_class, device->interface_subclass, device->interface_protocol) == type) {
|
||||
result = SDL_TRUE;
|
||||
break;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue