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.
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 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451
diff --git a/src/joystick/hidapi/SDL_hidapi_ps4.c b/src/joystick/hidapi/SDL_hidapi_ps4.c
index d1c422c..6925be4 100644
--- a/src/joystick/hidapi/SDL_hidapi_ps4.c
+++ b/src/joystick/hidapi/SDL_hidapi_ps4.c
@@ -124,7 +124,6 @@ typedef struct {
SDL_HIDAPI_Device *device;
SDL_Joystick *joystick;
SDL_bool is_dongle;
- SDL_bool is_bluetooth;
SDL_bool official_controller;
SDL_bool sensors_supported;
SDL_bool lightbar_supported;
@@ -268,7 +267,7 @@ HIDAPI_DriverPS4_InitDevice(SDL_HIDAPI_Device *device)
/* Check for type of connection */
ctx->is_dongle = (device->vendor_id == USB_VENDOR_SONY && device->product_id == USB_PRODUCT_SONY_DS4_DONGLE);
if (ctx->is_dongle) {
- ctx->is_bluetooth = SDL_FALSE;
+ device->is_bluetooth = SDL_FALSE;
ctx->official_controller = SDL_TRUE;
ctx->enhanced_mode = SDL_TRUE;
} else if (device->vendor_id == USB_VENDOR_SONY) {
@@ -277,10 +276,10 @@ HIDAPI_DriverPS4_InitDevice(SDL_HIDAPI_Device *device)
if (size >= 7) {
SDL_snprintf(serial, sizeof(serial), "%.2x-%.2x-%.2x-%.2x-%.2x-%.2x",
data[6], data[5], data[4], data[3], data[2], data[1]);
- ctx->is_bluetooth = SDL_FALSE;
+ device->is_bluetooth = SDL_FALSE;
ctx->enhanced_mode = SDL_TRUE;
} else {
- ctx->is_bluetooth = SDL_TRUE;
+ device->is_bluetooth = SDL_TRUE;
/* Read a report to see if we're in enhanced mode */
size = SDL_hid_read_timeout(device->dev, data, sizeof(data), 16);
@@ -300,11 +299,11 @@ HIDAPI_DriverPS4_InitDevice(SDL_HIDAPI_Device *device)
ctx->official_controller = SDL_TRUE;
} else {
/* Third party controllers appear to all be wired */
- ctx->is_bluetooth = SDL_FALSE;
+ device->is_bluetooth = SDL_FALSE;
ctx->enhanced_mode = SDL_TRUE;
}
#ifdef DEBUG_PS4
- SDL_Log("PS4 dongle = %s, bluetooth = %s\n", ctx->is_dongle ? "TRUE" : "FALSE", ctx->is_bluetooth ? "TRUE" : "FALSE");
+ SDL_Log("PS4 dongle = %s, bluetooth = %s\n", ctx->is_dongle ? "TRUE" : "FALSE", device->is_bluetooth ? "TRUE" : "FALSE");
#endif
/* Get the device capabilities */
@@ -374,6 +373,14 @@ HIDAPI_DriverPS4_InitDevice(SDL_HIDAPI_Device *device)
}
HIDAPI_SetDeviceSerial(device, serial);
+ /* Prefer the USB device over the Bluetooth device */
+ if (device->is_bluetooth) {
+ if (HIDAPI_HasConnectedUSBDevice(device->serial)) {
+ return SDL_TRUE;
+ }
+ } else {
+ HIDAPI_DisconnectBluetoothDevice(device->serial);
+ }
return HIDAPI_JoystickConnected(device, NULL);
}
@@ -408,7 +415,7 @@ HIDAPI_DriverPS4_LoadCalibrationData(SDL_HIDAPI_Device *device)
return;
}
- if (ctx->is_bluetooth) {
+ if (device->is_bluetooth) {
size = ReadFeatureReport(device->dev, k_ePS4FeatureReportIdGyroCalibration_BT, data, sizeof(data));
if (size < 35) {
#ifdef DEBUG_PS4_CALIBRATION
@@ -454,7 +461,7 @@ HIDAPI_DriverPS4_LoadCalibrationData(SDL_HIDAPI_Device *device)
sGyroYawBias = LOAD16(data[3], data[4]);
sGyroRollBias = LOAD16(data[5], data[6]);
- if (ctx->is_bluetooth || ctx->is_dongle) {
+ if (device->is_bluetooth || ctx->is_dongle) {
sGyroPitchPlus = LOAD16(data[7], data[8]);
sGyroYawPlus = LOAD16(data[9], data[10]);
sGyroRollPlus = LOAD16(data[11], data[12]);
@@ -657,7 +664,7 @@ HIDAPI_DriverPS4_OpenJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick)
/* Initialize the joystick capabilities */
joystick->nbuttons = ctx->touchpad_supported ? 16 : 15;
joystick->naxes = SDL_CONTROLLER_AXIS_MAX;
- joystick->epowerlevel = ctx->is_bluetooth ? SDL_JOYSTICK_POWER_UNKNOWN : SDL_JOYSTICK_POWER_WIRED;
+ joystick->epowerlevel = device->is_bluetooth ? SDL_JOYSTICK_POWER_UNKNOWN : SDL_JOYSTICK_POWER_WIRED;
if (ctx->enhanced_mode) {
/* Force initialization when opening the joystick */
@@ -743,7 +750,7 @@ HIDAPI_DriverPS4_SendJoystickEffect(SDL_HIDAPI_Device *device, SDL_Joystick *joy
SDL_zeroa(data);
- if (ctx->is_bluetooth) {
+ if (device->is_bluetooth) {
data[0] = k_EPS4ReportIdBluetoothEffects;
data[1] = 0xC0 | 0x04; /* Magic value HID + CRC, also sets interval to 4ms for samples */
data[3] = 0x03; /* 0x1 is rumble, 0x2 is lightbar, 0x4 is the blink interval */
@@ -760,7 +767,7 @@ HIDAPI_DriverPS4_SendJoystickEffect(SDL_HIDAPI_Device *device, SDL_Joystick *joy
SDL_memcpy(&data[offset], effect, SDL_min((sizeof(data) - offset), (size_t)size));
- if (ctx->is_bluetooth) {
+ if (device->is_bluetooth) {
/* Bluetooth reports need a CRC at the end of the packet (at least on Linux) */
Uint8 ubHdr = 0xA2; /* hidp header is part of the CRC calculation */
Uint32 unCRC;
@@ -950,6 +957,13 @@ HIDAPI_DriverPS4_UpdateDevice(SDL_HIDAPI_Device *device)
int size;
int packet_count = 0;
+ /* Reconnect the Bluetooth device once the USB device is gone */
+ if (device->is_bluetooth &&
+ device->num_joysticks == 0 &&
+ !HIDAPI_HasConnectedUSBDevice(device->serial)) {
+ HIDAPI_JoystickConnected(device, NULL);
+ }
+
if (device->num_joysticks > 0) {
joystick = SDL_JoystickFromInstanceID(device->joysticks[0]);
} else {
@@ -997,7 +1011,7 @@ HIDAPI_DriverPS4_UpdateDevice(SDL_HIDAPI_Device *device)
}
}
- if (ctx->is_bluetooth && packet_count == 0) {
+ if (device->is_bluetooth && packet_count == 0) {
/* Check to see if it looks like the device disconnected */
if (SDL_TICKS_PASSED(SDL_GetTicks(), ctx->last_packet + BLUETOOTH_DISCONNECT_TIMEOUT_MS)) {
/* Send an empty output report to tickle the Bluetooth stack */
diff --git a/src/joystick/hidapi/SDL_hidapi_ps5.c b/src/joystick/hidapi/SDL_hidapi_ps5.c
index 5f72d56..390a9c2 100644
--- a/src/joystick/hidapi/SDL_hidapi_ps5.c
+++ b/src/joystick/hidapi/SDL_hidapi_ps5.c
@@ -198,7 +198,6 @@ typedef struct {
typedef struct {
SDL_HIDAPI_Device *device;
SDL_Joystick *joystick;
- SDL_bool is_bluetooth;
SDL_bool use_alternate_report;
SDL_bool sensors_supported;
SDL_bool lightbar_supported;
@@ -377,15 +376,15 @@ HIDAPI_DriverPS5_InitDevice(SDL_HIDAPI_Device *device)
#endif
if (size == 64) {
/* Connected over USB */
- ctx->is_bluetooth = SDL_FALSE;
+ device->is_bluetooth = SDL_FALSE;
ctx->enhanced_mode = SDL_TRUE;
} else if (size > 0 && data[0] == k_EPS5ReportIdBluetoothEffects) {
/* Connected over Bluetooth, using enhanced reports */
- ctx->is_bluetooth = SDL_TRUE;
+ device->is_bluetooth = SDL_TRUE;
ctx->enhanced_mode = SDL_TRUE;
} else {
/* Connected over Bluetooth, using simple reports (DirectInput enabled) */
- ctx->is_bluetooth = SDL_TRUE;
+ device->is_bluetooth = SDL_TRUE;
/* Games written prior the introduction of PS5 controller support in SDL will not be aware of
SDL_HINT_JOYSTICK_HIDAPI_PS5_RUMBLE, but they did know SDL_HINT_JOYSTICK_HIDAPI_PS4_RUMBLE.
@@ -479,6 +478,14 @@ HIDAPI_DriverPS5_InitDevice(SDL_HIDAPI_Device *device)
}
HIDAPI_SetDeviceSerial(device, serial);
+ /* Prefer the USB device over the Bluetooth device */
+ if (device->is_bluetooth) {
+ if (HIDAPI_HasConnectedUSBDevice(device->serial)) {
+ return SDL_TRUE;
+ }
+ } else {
+ HIDAPI_DisconnectBluetoothDevice(device->serial);
+ }
return HIDAPI_JoystickConnected(device, NULL);
}
@@ -618,7 +625,7 @@ HIDAPI_DriverPS5_UpdateEffects(SDL_HIDAPI_Device *device, int effect_mask)
SDL_zero(effects);
/* Make sure the Bluetooth connection sequence has completed before sending LED color change */
- if (ctx->is_bluetooth &&
+ if (device->is_bluetooth &&
(effect_mask & (k_EDS5EffectLED | k_EDS5EffectPadLights)) != 0) {
if (ctx->led_reset_state != k_EDS5LEDResetStateComplete) {
ctx->led_reset_state = k_EDS5LEDResetStatePending;
@@ -819,7 +826,7 @@ HIDAPI_DriverPS5_OpenJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick)
/* Initialize the joystick capabilities */
joystick->nbuttons = ctx->touchpad_supported ? 17 : 15;
joystick->naxes = SDL_CONTROLLER_AXIS_MAX;
- joystick->epowerlevel = ctx->is_bluetooth ? SDL_JOYSTICK_POWER_UNKNOWN : SDL_JOYSTICK_POWER_WIRED;
+ joystick->epowerlevel = device->is_bluetooth ? SDL_JOYSTICK_POWER_UNKNOWN : SDL_JOYSTICK_POWER_WIRED;
joystick->firmware_version = ctx->firmware_version;
if (ctx->enhanced_mode) {
@@ -916,7 +923,7 @@ HIDAPI_DriverPS5_SendJoystickEffect(SDL_HIDAPI_Device *device, SDL_Joystick *joy
SDL_zeroa(data);
- if (ctx->is_bluetooth) {
+ if (device->is_bluetooth) {
data[0] = k_EPS5ReportIdBluetoothEffects;
data[1] = 0x02; /* Magic value */
@@ -931,7 +938,7 @@ HIDAPI_DriverPS5_SendJoystickEffect(SDL_HIDAPI_Device *device, SDL_Joystick *joy
SDL_memcpy(&data[offset], effect, SDL_min((sizeof(data) - offset), (size_t)size));
- if (ctx->is_bluetooth) {
+ if (device->is_bluetooth) {
/* Bluetooth reports need a CRC at the end of the packet (at least on Linux) */
Uint8 ubHdr = 0xA2; /* hidp header is part of the CRC calculation */
Uint32 unCRC;
@@ -1206,7 +1213,7 @@ HIDAPI_DriverPS5_HandleStatePacket(SDL_Joystick *joystick, SDL_hid_device *dev,
/* A check of packet->ucBatteryLevel & 0x10 should work as a check for BT vs USB but doesn't
* seem to always work. Possibly related to being 100% charged?
*/
- if (!ctx->is_bluetooth) {
+ if (!ctx->device->is_bluetooth) {
/* 0x20 set means fully charged */
SDL_PrivateJoystickBatteryLevel(joystick, SDL_JOYSTICK_POWER_WIRED);
} else {
@@ -1258,6 +1265,13 @@ HIDAPI_DriverPS5_UpdateDevice(SDL_HIDAPI_Device *device)
int size;
int packet_count = 0;
+ /* Reconnect the Bluetooth device once the USB device is gone */
+ if (device->is_bluetooth &&
+ device->num_joysticks == 0 &&
+ !HIDAPI_HasConnectedUSBDevice(device->serial)) {
+ HIDAPI_JoystickConnected(device, NULL);
+ }
+
if (device->num_joysticks > 0) {
joystick = SDL_JoystickFromInstanceID(device->joysticks[0]);
} else {
@@ -1311,7 +1325,7 @@ HIDAPI_DriverPS5_UpdateDevice(SDL_HIDAPI_Device *device)
}
}
- if (ctx->is_bluetooth && packet_count == 0) {
+ if (device->is_bluetooth && packet_count == 0) {
/* Check to see if it looks like the device disconnected */
if (SDL_TICKS_PASSED(SDL_GetTicks(), ctx->last_packet + BLUETOOTH_DISCONNECT_TIMEOUT_MS)) {
/* Send an empty output report to tickle the Bluetooth stack */
diff --git a/src/joystick/hidapi/SDL_hidapi_switch.c b/src/joystick/hidapi/SDL_hidapi_switch.c
index d2e8404..b2cbcd1 100644
--- a/src/joystick/hidapi/SDL_hidapi_switch.c
+++ b/src/joystick/hidapi/SDL_hidapi_switch.c
@@ -238,7 +238,6 @@ typedef struct {
SDL_HIDAPI_Device *device;
SDL_Joystick *joystick;
SDL_bool m_bInputOnly;
- SDL_bool m_bUsingBluetooth;
SDL_bool m_bIsGameCube;
SDL_bool m_bUseButtonLabels;
SDL_bool m_bPlayerLights;
@@ -383,7 +382,7 @@ static void ConstructSubcommand(SDL_DriverSwitch_Context *ctx, ESwitchSubcommand
static SDL_bool WritePacket(SDL_DriverSwitch_Context *ctx, void *pBuf, Uint8 ucLen)
{
Uint8 rgucBuf[k_unSwitchMaxOutputPacketLength];
- const size_t unWriteSize = ctx->m_bUsingBluetooth ? k_unSwitchBluetoothPacketLength : k_unSwitchUSBPacketLength;
+ const size_t unWriteSize = ctx->device->is_bluetooth ? k_unSwitchBluetoothPacketLength : k_unSwitchUSBPacketLength;
if (ucLen > k_unSwitchOutputPacketDataLength) {
return SDL_FALSE;
@@ -584,7 +583,7 @@ static SDL_bool BReadDeviceInfo(SDL_DriverSwitch_Context *ctx)
{
SwitchSubcommandInputPacket_t *reply = NULL;
- ctx->m_bUsingBluetooth = SDL_FALSE;
+ ctx->device->is_bluetooth = SDL_FALSE;
if (WriteProprietary(ctx, k_eSwitchProprietaryCommandIDs_Status, NULL, 0, SDL_TRUE)) {
SwitchProprietaryStatusPacket_t *status = (SwitchProprietaryStatusPacket_t *)&ctx->m_rgucReadBuffer[0];
@@ -598,7 +597,7 @@ static SDL_bool BReadDeviceInfo(SDL_DriverSwitch_Context *ctx)
return SDL_TRUE;
}
- ctx->m_bUsingBluetooth = SDL_TRUE;
+ ctx->device->is_bluetooth = SDL_TRUE;
if (WriteSubcommand(ctx, k_eSwitchSubcommandIDs_RequestDeviceInfo, NULL, 0, &reply)) {
// Byte 2: Controller ID (1=LJC, 2=RJC, 3=Pro)
@@ -610,7 +609,7 @@ static SDL_bool BReadDeviceInfo(SDL_DriverSwitch_Context *ctx)
return SDL_TRUE;
}
- ctx->m_bUsingBluetooth = SDL_FALSE;
+ ctx->device->is_bluetooth = SDL_FALSE;
return SDL_FALSE;
}
@@ -945,7 +944,7 @@ ReadJoyConControllerType(SDL_HIDAPI_Device *device)
} else {
SwitchSubcommandInputPacket_t *reply = NULL;
- ctx->m_bUsingBluetooth = SDL_TRUE;
+ device->is_bluetooth = SDL_TRUE;
if (WriteSubcommand(ctx, k_eSwitchSubcommandIDs_RequestDeviceInfo, NULL, 0, &reply)) {
eControllerType = CalculateControllerType(ctx, (ESwitchDeviceInfoControllerType)reply->deviceInfo.ucDeviceType);
}
@@ -1244,6 +1243,14 @@ HIDAPI_DriverSwitch_InitDevice(SDL_HIDAPI_Device *device)
UpdateDeviceIdentity(device);
}
+ /* Prefer the USB device over the Bluetooth device */
+ if (device->is_bluetooth) {
+ if (HIDAPI_HasConnectedUSBDevice(device->serial)) {
+ return SDL_TRUE;
+ }
+ } else {
+ HIDAPI_DisconnectBluetoothDevice(device->serial);
+ }
return HIDAPI_JoystickConnected(device, NULL);
}
@@ -1282,7 +1289,7 @@ HIDAPI_DriverSwitch_OpenJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joysti
SetNeutralRumble(&ctx->m_RumblePacket.rumbleData[0]);
SetNeutralRumble(&ctx->m_RumblePacket.rumbleData[1]);
- if (!ctx->m_bUsingBluetooth) {
+ if (!device->is_bluetooth) {
if (!BTrySetupUSB(ctx)) {
SDL_SetError("Couldn't setup USB mode");
return SDL_FALSE;
@@ -1290,7 +1297,7 @@ HIDAPI_DriverSwitch_OpenJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joysti
}
/* Determine the desired input mode (needed before loading stick calibration) */
- if (ctx->m_bUsingBluetooth) {
+ if (device->is_bluetooth) {
input_mode = k_eSwitchInputReportIDs_SimpleControllerState;
} else {
input_mode = k_eSwitchInputReportIDs_FullControllerState;
@@ -1351,7 +1358,7 @@ HIDAPI_DriverSwitch_OpenJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joysti
}
/* Start sending USB reports */
- if (!ctx->m_bUsingBluetooth) {
+ if (!device->is_bluetooth) {
/* ForceUSB doesn't generate an ACK, so don't wait for a reply */
if (!WriteProprietary(ctx, k_eSwitchProprietaryCommandIDs_ForceUSB, NULL, 0, SDL_FALSE)) {
SDL_SetError("Couldn't start USB reports");
@@ -1390,7 +1397,7 @@ HIDAPI_DriverSwitch_OpenJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joysti
/* Initialize the joystick capabilities */
joystick->nbuttons = 16;
joystick->naxes = SDL_CONTROLLER_AXIS_MAX;
- joystick->epowerlevel = ctx->m_bUsingBluetooth ? SDL_JOYSTICK_POWER_UNKNOWN : SDL_JOYSTICK_POWER_WIRED;
+ joystick->epowerlevel = device->is_bluetooth ? SDL_JOYSTICK_POWER_UNKNOWN : SDL_JOYSTICK_POWER_WIRED;
/* Set up for input */
ctx->m_bSyncWrite = SDL_FALSE;
@@ -2069,6 +2076,13 @@ HIDAPI_DriverSwitch_UpdateDevice(SDL_HIDAPI_Device *device)
int size;
Uint32 now;
+ /* Reconnect the Bluetooth device once the USB device is gone */
+ if (device->is_bluetooth &&
+ device->num_joysticks == 0 &&
+ !HIDAPI_HasConnectedUSBDevice(device->serial)) {
+ HIDAPI_JoystickConnected(device, NULL);
+ }
+
if (device->num_joysticks > 0) {
joystick = SDL_JoystickFromInstanceID(device->joysticks[0]);
} else {
@@ -2101,14 +2115,14 @@ HIDAPI_DriverSwitch_UpdateDevice(SDL_HIDAPI_Device *device)
}
if (joystick) {
- if (!ctx->m_bInputOnly && !ctx->m_bUsingBluetooth &&
+ if (!ctx->m_bInputOnly && !device->is_bluetooth &&
ctx->device->product_id != USB_PRODUCT_NINTENDO_SWITCH_JOYCON_GRIP) {
const Uint32 INPUT_WAIT_TIMEOUT_MS = 100;
if (SDL_TICKS_PASSED(now, ctx->m_unLastInput + INPUT_WAIT_TIMEOUT_MS)) {
/* Steam may have put the controller back into non-reporting mode */
WriteProprietary(ctx, k_eSwitchProprietaryCommandIDs_ForceUSB, NULL, 0, SDL_FALSE);
}
- } else if (ctx->m_bUsingBluetooth) {
+ } else if (device->is_bluetooth) {
const Uint32 INPUT_WAIT_TIMEOUT_MS = 3000;
if (SDL_TICKS_PASSED(now, ctx->m_unLastInput + INPUT_WAIT_TIMEOUT_MS)) {
/* Bluetooth may have disconnected, try reopening the controller */
diff --git a/src/joystick/hidapi/SDL_hidapijoystick.c b/src/joystick/hidapi/SDL_hidapijoystick.c
index f5d4674..4900b38 100644
--- a/src/joystick/hidapi/SDL_hidapijoystick.c
+++ b/src/joystick/hidapi/SDL_hidapijoystick.c
@@ -530,6 +530,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)
{
int i, j;
diff --git a/src/joystick/hidapi/SDL_hidapijoystick_c.h b/src/joystick/hidapi/SDL_hidapijoystick_c.h
index f1c7b2b..a03221c 100644
--- a/src/joystick/hidapi/SDL_hidapijoystick_c.h
+++ b/src/joystick/hidapi/SDL_hidapijoystick_c.h
@@ -73,6 +73,7 @@ typedef struct _SDL_HIDAPI_Device
int interface_protocol;
Uint16 usage_page; /* Available on Windows and Mac OS X */
Uint16 usage; /* Available on Windows and Mac OS X */
+ SDL_bool is_bluetooth;
SDL_JoystickType joystick_type;
SDL_GameControllerType type;
@@ -157,6 +158,8 @@ extern void HIDAPI_UpdateDevices(void);
extern void HIDAPI_SetDeviceName(SDL_HIDAPI_Device *device, const char *name);
extern void HIDAPI_SetDeviceProduct(SDL_HIDAPI_Device *device, Uint16 product_id);
extern void HIDAPI_SetDeviceSerial(SDL_HIDAPI_Device *device, const char *serial);
+extern SDL_bool HIDAPI_HasConnectedUSBDevice(const char *serial);
+extern void HIDAPI_DisconnectBluetoothDevice(const char *serial);
extern SDL_bool HIDAPI_JoystickConnected(SDL_HIDAPI_Device *device, SDL_JoystickID *pJoystickID);
extern void HIDAPI_JoystickDisconnected(SDL_HIDAPI_Device *device, SDL_JoystickID joystickID);