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.
This commit is contained in:
Sam Lantinga 2022-09-26 20:41:51 -07:00
parent 71fb91f7e4
commit 67db8a9103
3 changed files with 9 additions and 3 deletions

View File

@ -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) {

View File

@ -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) {

View File

@ -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) {