Commit 802b5ef7dcfd022ae3108a20b63f2895a235dccd

Sam Lantinga 2022-12-12T10:54:29

Added support for the STRIKEPAD PS4 Grip Add-on to the HIDAPI driver (cherry picked from commit 618340bf990512247ed29a1beb38606e371d60e8)

diff --git a/src/joystick/hidapi/SDL_hidapi_ps4.c b/src/joystick/hidapi/SDL_hidapi_ps4.c
index 36280a6..56c5807 100644
--- a/src/joystick/hidapi/SDL_hidapi_ps4.c
+++ b/src/joystick/hidapi/SDL_hidapi_ps4.c
@@ -273,6 +273,10 @@ static SDL_bool HIDAPI_DriverPS4_InitDevice(SDL_HIDAPI_Device *device)
         }
         device->is_bluetooth = SDL_FALSE;
         ctx->enhanced_mode = SDL_TRUE;
+    } else if (device->vendor_id == USB_VENDOR_SONY && device->product_id == USB_PRODUCT_SONY_DS4_STRIKEPAD) {
+        device->is_bluetooth = SDL_FALSE;
+        ctx->enhanced_mode = SDL_TRUE;
+
     } else if (device->vendor_id == USB_VENDOR_SONY) {
         /* This will fail if we're on Bluetooth */
         size = ReadFeatureReport(device->dev, k_ePS4FeatureReportIdSerialNumber, data, sizeof(data));
@@ -310,13 +314,7 @@ static SDL_bool HIDAPI_DriverPS4_InitDevice(SDL_HIDAPI_Device *device)
 
     size = ReadFeatureReport(device->dev, k_ePS4FeatureReportIdCapabilities, data, sizeof data);
     /* Get the device capabilities */
-    if (device->vendor_id == USB_VENDOR_SONY) {
-        ctx->official_controller = SDL_TRUE;
-        ctx->sensors_supported = SDL_TRUE;
-        ctx->lightbar_supported = SDL_TRUE;
-        ctx->vibration_supported = SDL_TRUE;
-        ctx->touchpad_supported = SDL_TRUE;
-    } else if (size == 48 && data[2] == 0x27) {
+    if (size == 48 && data[2] == 0x27) {
         Uint8 capabilities = data[4];
         Uint8 device_type = data[5];
 
@@ -362,6 +360,12 @@ static SDL_bool HIDAPI_DriverPS4_InitDevice(SDL_HIDAPI_Device *device)
             joystick_type = SDL_JOYSTICK_TYPE_UNKNOWN;
             break;
         }
+    } else if (device->vendor_id == USB_VENDOR_SONY) {
+        ctx->official_controller = SDL_TRUE;
+        ctx->sensors_supported = SDL_TRUE;
+        ctx->lightbar_supported = SDL_TRUE;
+        ctx->vibration_supported = SDL_TRUE;
+        ctx->touchpad_supported = SDL_TRUE;
     } else if (device->vendor_id == USB_VENDOR_RAZER) {
         /* The Razer Raiju doesn't respond to the detection protocol, but has a touchpad and vibration */
         ctx->vibration_supported = SDL_TRUE;
@@ -385,7 +389,7 @@ static SDL_bool HIDAPI_DriverPS4_InitDevice(SDL_HIDAPI_Device *device)
 
     device->joystick_type = joystick_type;
     device->type = SDL_CONTROLLER_TYPE_PS4;
-    if (device->vendor_id == USB_VENDOR_SONY) {
+    if (ctx->official_controller) {
         HIDAPI_SetDeviceName(device, "PS4 Controller");
     }
     HIDAPI_SetDeviceSerial(device, serial);
diff --git a/src/joystick/usb_ids.h b/src/joystick/usb_ids.h
index 4cf9d80..2ae2f96 100644
--- a/src/joystick/usb_ids.h
+++ b/src/joystick/usb_ids.h
@@ -100,6 +100,7 @@
 #define USB_PRODUCT_SONY_DS4                              0x05c4
 #define USB_PRODUCT_SONY_DS4_DONGLE                       0x0ba0
 #define USB_PRODUCT_SONY_DS4_SLIM                         0x09cc
+#define USB_PRODUCT_SONY_DS4_STRIKEPAD                    0x05c5
 #define USB_PRODUCT_SONY_DS5                              0x0ce6
 #define USB_PRODUCT_SONY_DS5_EDGE                         0x0df2
 #define USB_PRODUCT_VICTRIX_FS_PRO_V2                     0x0207