mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-10-04 17:06:25 +00:00
Improved detection of third party PS4 and PS5 controllers
This commit is contained in:
@@ -250,12 +250,6 @@ HIDAPI_DriverPS5_IsEnabled(void)
|
||||
SDL_HIDAPI_DEFAULT));
|
||||
}
|
||||
|
||||
static SDL_bool
|
||||
HIDAPI_DriverPS5_IsSupportedDevice(SDL_HIDAPI_Device *device, const char *name, SDL_GameControllerType type, Uint16 vendor_id, Uint16 product_id, Uint16 version, int interface_number, int interface_class, int interface_subclass, int interface_protocol)
|
||||
{
|
||||
return (type == SDL_CONTROLLER_TYPE_PS5) ? SDL_TRUE : SDL_FALSE;
|
||||
}
|
||||
|
||||
static int ReadFeatureReport(SDL_hid_device *dev, Uint8 report_id, Uint8 *report, size_t length)
|
||||
{
|
||||
SDL_memset(report, 0, length);
|
||||
@@ -263,6 +257,21 @@ static int ReadFeatureReport(SDL_hid_device *dev, Uint8 report_id, Uint8 *report
|
||||
return SDL_hid_get_feature_report(dev, report, length);
|
||||
}
|
||||
|
||||
static SDL_bool
|
||||
HIDAPI_DriverPS5_IsSupportedDevice(SDL_HIDAPI_Device *device, const char *name, SDL_GameControllerType type, Uint16 vendor_id, Uint16 product_id, Uint16 version, int interface_number, int interface_class, int interface_subclass, int interface_protocol)
|
||||
{
|
||||
Uint8 data[USB_PACKET_LENGTH];
|
||||
int size;
|
||||
|
||||
if (device && SONY_THIRDPARTY_VENDOR(device->vendor_id) &&
|
||||
(size = ReadFeatureReport(device->dev, k_EPS5FeatureReportIdCapabilities, data, sizeof(data))) == 48 &&
|
||||
data[2] == 0x28) {
|
||||
/* Supported third party controller */
|
||||
return SDL_TRUE;
|
||||
}
|
||||
return (type == SDL_CONTROLLER_TYPE_PS5) ? SDL_TRUE : SDL_FALSE;
|
||||
}
|
||||
|
||||
static void
|
||||
SetLedsForPlayerIndex(DS5EffectsState_t *effects, int player_index)
|
||||
{
|
||||
@@ -317,10 +326,6 @@ HIDAPI_DriverPS5_InitDevice(SDL_HIDAPI_Device *device)
|
||||
int size;
|
||||
char serial[18];
|
||||
|
||||
if (device->vendor_id == USB_VENDOR_SONY) {
|
||||
HIDAPI_SetDeviceName(device, "PS5 Controller");
|
||||
}
|
||||
|
||||
ctx = (SDL_DriverPS5_Context *)SDL_calloc(1, sizeof(*ctx));
|
||||
if (!ctx) {
|
||||
SDL_OutOfMemory();
|
||||
@@ -416,6 +421,10 @@ HIDAPI_DriverPS5_InitDevice(SDL_HIDAPI_Device *device)
|
||||
ctx->use_alternate_report = SDL_TRUE;
|
||||
}
|
||||
|
||||
device->type = SDL_CONTROLLER_TYPE_PS5;
|
||||
if (device->vendor_id == USB_VENDOR_SONY) {
|
||||
HIDAPI_SetDeviceName(device, "PS5 Controller");
|
||||
}
|
||||
HIDAPI_SetDeviceSerial(device, serial);
|
||||
|
||||
return HIDAPI_JoystickConnected(device, NULL);
|
||||
|
Reference in New Issue
Block a user