Fixed rare case of wireless Steam Controller not being detected at startup
This commit is contained in:
parent
572cc7af63
commit
2b10a040ff
1 changed files with 33 additions and 18 deletions
|
@ -1214,6 +1214,31 @@ static bool HIDAPI_DriverSteam_SetSensorsEnabled(SDL_HIDAPI_Device *device, SDL_
|
||||||
return true;
|
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)
|
static bool HIDAPI_DriverSteam_UpdateDevice(SDL_HIDAPI_Device *device)
|
||||||
{
|
{
|
||||||
SDL_DriverSteam_Context *ctx = (SDL_DriverSteam_Context *)device->context;
|
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) {
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
// Failed to read from controller
|
// Failed to read from controller
|
||||||
if (ctx->connected) {
|
ControllerDisconnected(device, &joystick);
|
||||||
HIDAPI_JoystickDisconnected(device, device->joysticks[0]);
|
|
||||||
ctx->connected = false;
|
|
||||||
}
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -1251,6 +1273,11 @@ static bool HIDAPI_DriverSteam_UpdateDevice(SDL_HIDAPI_Device *device)
|
||||||
if (nPacketLength > 0 && UpdateSteamControllerState(pPacket, nPacketLength, &ctx->m_state)) {
|
if (nPacketLength > 0 && UpdateSteamControllerState(pPacket, nPacketLength, &ctx->m_state)) {
|
||||||
Uint64 timestamp = SDL_GetTicksNS();
|
Uint64 timestamp = SDL_GetTicksNS();
|
||||||
|
|
||||||
|
if (!ctx->connected) {
|
||||||
|
// Maybe we missed a wireless status packet?
|
||||||
|
ControllerConnected(device, &joystick);
|
||||||
|
}
|
||||||
|
|
||||||
if (!joystick) {
|
if (!joystick) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -1336,21 +1363,9 @@ static bool HIDAPI_DriverSteam_UpdateDevice(SDL_HIDAPI_Device *device)
|
||||||
|
|
||||||
ctx->m_last_state = ctx->m_state;
|
ctx->m_last_state = ctx->m_state;
|
||||||
} else if (!ctx->connected && D0G_IS_WIRELESS_CONNECT(pPacket, nPacketLength)) {
|
} else if (!ctx->connected && D0G_IS_WIRELESS_CONNECT(pPacket, nPacketLength)) {
|
||||||
// Controller has connected to the wireless dongle
|
ControllerConnected(device, &joystick);
|
||||||
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;
|
|
||||||
} else if (ctx->connected && D0G_IS_WIRELESS_DISCONNECT(pPacket, nPacketLength)) {
|
} else if (ctx->connected && D0G_IS_WIRELESS_DISCONNECT(pPacket, nPacketLength)) {
|
||||||
// Controller has disconnected from the wireless dongle
|
ControllerDisconnected(device, &joystick);
|
||||||
HIDAPI_JoystickDisconnected(device, device->joysticks[0]);
|
|
||||||
joystick = NULL;
|
|
||||||
ctx->connected = false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue