Prefer USB input over Bluetooth for PS5/PS5/Switch controllers

Nintendo Switch controllers will automatically turn off Bluetooth when connected over USB, but this takes care of that a little more quickly.

PS4 and PS5 controllers will happily send reports over both Bluetooth and USB, so we'll prefer USB if connected and switch back to Bluetooth if USB is disconnected.
This commit is contained in:
Sam Lantinga 2022-09-26 14:20:34 -07:00
parent 17d7d03adf
commit 39adcc0a6b
5 changed files with 114 additions and 34 deletions

View file

@ -529,6 +529,41 @@ HIDAPI_SetDeviceSerial(SDL_HIDAPI_Device *device, const char *serial)
}
}
SDL_bool
HIDAPI_HasConnectedUSBDevice(const char *serial)
{
SDL_HIDAPI_Device *device;
for (device = SDL_HIDAPI_devices; device; device = device->next) {
if (device->is_bluetooth) {
continue;
}
if (device->serial && SDL_strcmp(serial, device->serial) == 0) {
return SDL_TRUE;
}
}
return SDL_FALSE;
}
void
HIDAPI_DisconnectBluetoothDevice(const char *serial)
{
SDL_HIDAPI_Device *device;
for (device = SDL_HIDAPI_devices; device; device = device->next) {
if (!device->is_bluetooth) {
continue;
}
if (device->serial && SDL_strcmp(serial, device->serial) == 0) {
while (device->num_joysticks && device->joysticks) {
HIDAPI_JoystickDisconnected(device, device->joysticks[0]);
}
}
}
}
SDL_bool
HIDAPI_JoystickConnected(SDL_HIDAPI_Device *device, SDL_JoystickID *pJoystickID)
{