Improved detection of third party PS4 and PS5 controllers

This commit is contained in:
Sam Lantinga 2022-09-22 23:42:25 -07:00
parent 7312b93d32
commit fa2063fb44
17 changed files with 132 additions and 51 deletions

View file

@ -235,7 +235,6 @@ HIDAPI_GetDeviceDriver(SDL_HIDAPI_Device *device)
const Uint16 USAGE_GAMEPAD = 0x0005;
const Uint16 USAGE_MULTIAXISCONTROLLER = 0x0008;
int i;
SDL_GameControllerType type;
if (device->num_children > 0) {
return &SDL_HIDAPI_DriverCombined;
@ -254,10 +253,9 @@ HIDAPI_GetDeviceDriver(SDL_HIDAPI_Device *device)
}
}
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, device->name, type, device->vendor_id, device->product_id, device->version, device->interface_number, device->interface_class, device->interface_subclass, device->interface_protocol)) {
if (driver->enabled && driver->IsSupportedDevice(device, device->name, device->type, device->vendor_id, device->product_id, device->version, device->interface_number, device->interface_class, device->interface_subclass, device->interface_protocol)) {
return driver;
}
}
@ -690,6 +688,7 @@ HIDAPI_AddDevice(const struct SDL_hid_device_info *info, int num_children, SDL_H
/* FIXME: Is there any way to tell whether this is a Bluetooth device? */
device->guid = SDL_CreateJoystickGUID(SDL_HARDWARE_BUS_USB, device->vendor_id, device->product_id, device->version, device->name, 'h', 0);
device->type = SDL_GetJoystickGameControllerProtocol(device->name, device->vendor_id, device->product_id, device->interface_number, device->interface_class, device->interface_subclass, device->interface_protocol);
if (num_children > 0) {
int i;
@ -914,14 +913,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_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) {
device->type == 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_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) {
if (device->type == SDL_CONTROLLER_TYPE_XBOX360 || device->type == SDL_CONTROLLER_TYPE_XBOXONE) {
return SDL_TRUE;
}
}
@ -947,8 +945,7 @@ HIDAPI_IsDeviceTypePresent(SDL_GameControllerType type)
SDL_LockJoysticks();
for (device = SDL_HIDAPI_devices; device; device = device->next) {
if (device->driver &&
SDL_GetJoystickGameControllerProtocol(device->name, device->vendor_id, device->product_id, device->interface_number, device->interface_class, device->interface_subclass, device->interface_protocol) == type) {
if (device->driver && device->type == type) {
result = SDL_TRUE;
break;
}
@ -1013,6 +1010,24 @@ HIDAPI_IsDevicePresent(Uint16 vendor_id, Uint16 product_id, Uint16 version, cons
return result;
}
SDL_GameControllerType
HIDAPI_GetGameControllerTypeFromGUID(SDL_JoystickGUID guid)
{
SDL_HIDAPI_Device *device;
SDL_GameControllerType type = SDL_CONTROLLER_TYPE_UNKNOWN;
SDL_LockJoysticks();
for (device = SDL_HIDAPI_devices; device; device = device->next) {
if (SDL_memcmp(&guid, &device->guid, sizeof(guid)) == 0) {
type = device->type;
break;
}
}
SDL_UnlockJoysticks();
return type;
}
static void
HIDAPI_JoystickDetect(void)
{