mirror of
https://github.com/libsdl-org/SDL.git
synced 2024-11-23 02:43:30 +08:00
Fixed rare case of wireless Steam Controller not being detected at startup
This commit is contained in:
parent
572cc7af63
commit
2b10a040ff
@ -1214,6 +1214,31 @@ static bool HIDAPI_DriverSteam_SetSensorsEnabled(SDL_HIDAPI_Device *device, SDL_
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool ControllerConnected(SDL_HIDAPI_Device *device, SDL_Joystick **joystick)
|
||||
{
|
||||
SDL_DriverSteam_Context *ctx = (SDL_DriverSteam_Context *)device->context;
|
||||
|
||||
if (!HIDAPI_JoystickConnected(device, NULL)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// We'll automatically accept this controller if we're in pairing mode
|
||||
HIDAPI_DriverSteam_CommitPairing(ctx);
|
||||
|
||||
*joystick = SDL_GetJoystickFromID(device->joysticks[0]);
|
||||
ctx->connected = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
static void ControllerDisconnected(SDL_HIDAPI_Device *device, SDL_Joystick **joystick)
|
||||
{
|
||||
SDL_DriverSteam_Context *ctx = (SDL_DriverSteam_Context *)device->context;
|
||||
|
||||
HIDAPI_JoystickDisconnected(device, device->joysticks[0]);
|
||||
ctx->connected = false;
|
||||
*joystick = NULL;
|
||||
}
|
||||
|
||||
static bool HIDAPI_DriverSteam_UpdateDevice(SDL_HIDAPI_Device *device)
|
||||
{
|
||||
SDL_DriverSteam_Context *ctx = (SDL_DriverSteam_Context *)device->context;
|
||||
@ -1232,10 +1257,7 @@ static bool HIDAPI_DriverSteam_UpdateDevice(SDL_HIDAPI_Device *device)
|
||||
if (r <= 0) {
|
||||
if (r < 0) {
|
||||
// Failed to read from controller
|
||||
if (ctx->connected) {
|
||||
HIDAPI_JoystickDisconnected(device, device->joysticks[0]);
|
||||
ctx->connected = false;
|
||||
}
|
||||
ControllerDisconnected(device, &joystick);
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
@ -1251,6 +1273,11 @@ static bool HIDAPI_DriverSteam_UpdateDevice(SDL_HIDAPI_Device *device)
|
||||
if (nPacketLength > 0 && UpdateSteamControllerState(pPacket, nPacketLength, &ctx->m_state)) {
|
||||
Uint64 timestamp = SDL_GetTicksNS();
|
||||
|
||||
if (!ctx->connected) {
|
||||
// Maybe we missed a wireless status packet?
|
||||
ControllerConnected(device, &joystick);
|
||||
}
|
||||
|
||||
if (!joystick) {
|
||||
continue;
|
||||
}
|
||||
@ -1336,21 +1363,9 @@ static bool HIDAPI_DriverSteam_UpdateDevice(SDL_HIDAPI_Device *device)
|
||||
|
||||
ctx->m_last_state = ctx->m_state;
|
||||
} else if (!ctx->connected && D0G_IS_WIRELESS_CONNECT(pPacket, nPacketLength)) {
|
||||
// Controller has connected to the wireless dongle
|
||||
if (!HIDAPI_JoystickConnected(device, NULL)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// We'll automatically accept this controller if we're in pairing mode
|
||||
HIDAPI_DriverSteam_CommitPairing(ctx);
|
||||
|
||||
joystick = SDL_GetJoystickFromID(device->joysticks[0]);
|
||||
ctx->connected = true;
|
||||
ControllerConnected(device, &joystick);
|
||||
} else if (ctx->connected && D0G_IS_WIRELESS_DISCONNECT(pPacket, nPacketLength)) {
|
||||
// Controller has disconnected from the wireless dongle
|
||||
HIDAPI_JoystickDisconnected(device, device->joysticks[0]);
|
||||
joystick = NULL;
|
||||
ctx->connected = false;
|
||||
ControllerDisconnected(device, &joystick);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
Loading…
Reference in New Issue
Block a user