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

View file

@ -2034,16 +2034,15 @@ HIDAPI_DriverSwitch_UpdateDevice(SDL_HIDAPI_Device *device)
switch (ctx->m_rgucReadBuffer[0]) { switch (ctx->m_rgucReadBuffer[0]) {
case k_eSwitchInputReportIDs_SimpleControllerState: case k_eSwitchInputReportIDs_SimpleControllerState:
HandleSimpleControllerState(joystick, ctx, (SwitchSimpleStatePacket_t *)&ctx->m_rgucReadBuffer[1]); HandleSimpleControllerState(joystick, ctx, (SwitchSimpleStatePacket_t *)&ctx->m_rgucReadBuffer[1]);
ctx->m_unLastInput = now;
break; break;
case k_eSwitchInputReportIDs_FullControllerState: case k_eSwitchInputReportIDs_FullControllerState:
HandleFullControllerState(joystick, ctx, (SwitchStatePacket_t *)&ctx->m_rgucReadBuffer[1]); HandleFullControllerState(joystick, ctx, (SwitchStatePacket_t *)&ctx->m_rgucReadBuffer[1]);
ctx->m_unLastInput = now;
break; break;
default: default:
break; break;
} }
} }
ctx->m_unLastInput = now;
} }
if (!ctx->m_bInputOnly && !ctx->m_bUsingBluetooth && 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 */ /* Steam may have put the controller back into non-reporting mode */
WriteProprietary(ctx, k_eSwitchProprietaryCommandIDs_ForceUSB, NULL, 0, SDL_FALSE); 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) { if (ctx->m_bRumblePending || ctx->m_bRumbleZeroPending) {