From 32d015a6a0c2a4fcfc8aad74fa60a3b8c5f6f53b Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Thu, 8 Jun 2023 10:46:56 -0700
Subject: [PATCH] Fixed PS3 controller initialization over Bluetooth
Now that we have hidapi that knows whether the controller is connected via Bluetooth or USB, this is much easier to fix.
---
src/joystick/hidapi/SDL_hidapi_ps3.c | 4 ++--
src/joystick/hidapi/SDL_hidapijoystick.c | 1 +
2 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/src/joystick/hidapi/SDL_hidapi_ps3.c b/src/joystick/hidapi/SDL_hidapi_ps3.c
index ae6e6bb3ed9b..a84dd4b47414 100644
--- a/src/joystick/hidapi/SDL_hidapi_ps3.c
+++ b/src/joystick/hidapi/SDL_hidapi_ps3.c
@@ -144,14 +144,14 @@ static SDL_bool HIDAPI_DriverPS3_InitDevice(SDL_HIDAPI_Device *device)
device->context = ctx;
/* Set the controller into report mode over Bluetooth */
- {
+ if (device->is_bluetooth) {
Uint8 data[] = { 0xf4, 0x42, 0x03, 0x00, 0x00 };
SendFeatureReport(device->dev, data, sizeof(data));
}
/* Set the controller into report mode over USB */
- {
+ if (!device->is_bluetooth) {
Uint8 data[USB_PACKET_LENGTH];
int size = ReadFeatureReport(device->dev, 0xf2, data, 17);
diff --git a/src/joystick/hidapi/SDL_hidapijoystick.c b/src/joystick/hidapi/SDL_hidapijoystick.c
index a0db7c4df24f..8fb3612ac2a0 100644
--- a/src/joystick/hidapi/SDL_hidapijoystick.c
+++ b/src/joystick/hidapi/SDL_hidapijoystick.c
@@ -866,6 +866,7 @@ static SDL_HIDAPI_Device *HIDAPI_AddDevice(const struct SDL_hid_device_info *inf
device->interface_protocol = info->interface_protocol;
device->usage_page = info->usage_page;
device->usage = info->usage;
+ device->is_bluetooth = (info->bus_type == SDL_HID_API_BUS_BLUETOOTH);
device->dev_lock = SDL_CreateMutex();
/* Need the device name before getting the driver to know whether to ignore this device */