Wait for input before reconnecting a Bluetooth device On Windows, the Bluetooth device can remain in a connected state if the controller just shut down. It won't return any errors, but it also won't generate any input reports in this state, so wait until we know for sure that the Bluetooth controller is sending data before letting the application know it's available.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
diff --git a/src/joystick/hidapi/SDL_hidapi_ps4.c b/src/joystick/hidapi/SDL_hidapi_ps4.c
index c9c24a3..7aefd79 100644
--- a/src/joystick/hidapi/SDL_hidapi_ps4.c
+++ b/src/joystick/hidapi/SDL_hidapi_ps4.c
@@ -961,7 +961,9 @@ HIDAPI_DriverPS4_UpdateDevice(SDL_HIDAPI_Device *device)
if (device->num_joysticks == 0 &&
device->is_bluetooth &&
!HIDAPI_HasConnectedUSBDevice(device->serial)) {
- HIDAPI_JoystickConnected(device, NULL);
+ if (SDL_hid_read_timeout(device->dev, data, sizeof(data), 0) > 0) {
+ HIDAPI_JoystickConnected(device, NULL);
+ }
}
if (device->num_joysticks > 0) {
diff --git a/src/joystick/hidapi/SDL_hidapi_ps5.c b/src/joystick/hidapi/SDL_hidapi_ps5.c
index 423d4e9..1bd1a26 100644
--- a/src/joystick/hidapi/SDL_hidapi_ps5.c
+++ b/src/joystick/hidapi/SDL_hidapi_ps5.c
@@ -1269,7 +1269,9 @@ HIDAPI_DriverPS5_UpdateDevice(SDL_HIDAPI_Device *device)
if (device->num_joysticks == 0 &&
device->is_bluetooth &&
!HIDAPI_HasConnectedUSBDevice(device->serial)) {
- HIDAPI_JoystickConnected(device, NULL);
+ if (SDL_hid_read_timeout(device->dev, data, sizeof(data), 0) > 0) {
+ HIDAPI_JoystickConnected(device, NULL);
+ }
}
if (device->num_joysticks > 0) {
diff --git a/src/joystick/hidapi/SDL_hidapi_switch.c b/src/joystick/hidapi/SDL_hidapi_switch.c
index 5c542b3..62e826c 100644
--- a/src/joystick/hidapi/SDL_hidapi_switch.c
+++ b/src/joystick/hidapi/SDL_hidapi_switch.c
@@ -2089,7 +2089,9 @@ HIDAPI_DriverSwitch_UpdateDevice(SDL_HIDAPI_Device *device)
if (device->num_joysticks == 0 &&
device->is_bluetooth &&
!HIDAPI_HasConnectedUSBDevice(device->serial)) {
- HIDAPI_JoystickConnected(device, NULL);
+ if (ReadInput(ctx) > 0) {
+ HIDAPI_JoystickConnected(device, NULL);
+ }
}
if (device->num_joysticks > 0) {