From 035121040f3f24f869e7f468cf19d13baf1d80a4 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Fri, 7 Jul 2023 15:55:40 -0700
Subject: [PATCH] Don't tickle Bluetooth PS4 controllers in simple mode with an
effects packet
That will put the PS4 controller into enhanced mode, which breaks DirectInput games
(cherry picked from commit efed24850af2994802c28f7a257ea17c9ec97d0a)
(cherry picked from commit 1f7bc08884f93ede9775cdec5ae1582796fb947c)
---
src/joystick/hidapi/SDL_hidapi_ps4.c | 23 ++++++++++++++++-------
1 file changed, 16 insertions(+), 7 deletions(-)
diff --git a/src/joystick/hidapi/SDL_hidapi_ps4.c b/src/joystick/hidapi/SDL_hidapi_ps4.c
index dc7a0faf4c3a..e8c60d3cc94c 100644
--- a/src/joystick/hidapi/SDL_hidapi_ps4.c
+++ b/src/joystick/hidapi/SDL_hidapi_ps4.c
@@ -660,16 +660,25 @@ static int HIDAPI_DriverPS4_UpdateEffects(SDL_HIDAPI_Device *device)
static void HIDAPI_DriverPS4_TickleBluetooth(SDL_HIDAPI_Device *device)
{
- /* This is just a dummy packet that should have no effect, since we don't set the CRC */
- Uint8 data[78];
+ SDL_DriverPS4_Context *ctx = (SDL_DriverPS4_Context *)device->context;
- SDL_zeroa(data);
+ if (ctx->enhanced_mode) {
+ /* This is just a dummy packet that should have no effect, since we don't set the CRC */
+ Uint8 data[78];
- data[0] = k_EPS4ReportIdBluetoothEffects;
- data[1] = 0xC0; /* Magic value HID + CRC */
+ SDL_zeroa(data);
- if (SDL_HIDAPI_LockRumble() == 0) {
- SDL_HIDAPI_SendRumbleAndUnlock(device, data, sizeof(data));
+ data[0] = k_EPS4ReportIdBluetoothEffects;
+ data[1] = 0xC0; /* Magic value HID + CRC */
+
+ if (SDL_HIDAPI_LockRumble() == 0) {
+ SDL_HIDAPI_SendRumbleAndUnlock(device, data, sizeof(data));
+ }
+ } else {
+ /* We can't even send an invalid effects packet, or it will put the controller in enhanced mode */
+ if (device->num_joysticks > 0) {
+ HIDAPI_JoystickDisconnected(device, device->joysticks[0]);
+ }
}
}