Fixed detecting Bluetooth disconnection on Nintendo Switch controllers

This commit is contained in:
Sam Lantinga 2022-08-09 13:25:52 -07:00
parent 3a9295e14f
commit 8aa6922fec
1 changed files with 7 additions and 2 deletions

View File

@ -2034,16 +2034,15 @@ HIDAPI_DriverSwitch_UpdateDevice(SDL_HIDAPI_Device *device)
switch (ctx->m_rgucReadBuffer[0]) {
case k_eSwitchInputReportIDs_SimpleControllerState:
HandleSimpleControllerState(joystick, ctx, (SwitchSimpleStatePacket_t *)&ctx->m_rgucReadBuffer[1]);
ctx->m_unLastInput = now;
break;
case k_eSwitchInputReportIDs_FullControllerState:
HandleFullControllerState(joystick, ctx, (SwitchStatePacket_t *)&ctx->m_rgucReadBuffer[1]);
ctx->m_unLastInput = now;
break;
default:
break;
}
}
ctx->m_unLastInput = now;
}
if (!ctx->m_bInputOnly && !ctx->m_bUsingBluetooth &&
@ -2053,6 +2052,12 @@ HIDAPI_DriverSwitch_UpdateDevice(SDL_HIDAPI_Device *device)
/* 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) {
const Uint32 INPUT_WAIT_TIMEOUT_MS = 1000;
if (SDL_TICKS_PASSED(now, ctx->m_unLastInput + INPUT_WAIT_TIMEOUT_MS)) {
/* Bluetooth may have disconnected, try reopening the controller */
size = -1;
}
}
if (ctx->m_bRumblePending || ctx->m_bRumbleZeroPending) {