Skip to content

Commit

Permalink
Fixed duplicate controllers showing up on the Steam Controller wirele…
Browse files Browse the repository at this point in the history
…ss dongle
  • Loading branch information
slouken committed Nov 14, 2024
1 parent fe3566c commit f0b61c6
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/joystick/hidapi/SDL_hidapi_steam.c
Original file line number Diff line number Diff line change
Expand Up @@ -967,6 +967,7 @@ static bool UpdateSteamControllerState(const uint8_t *pData, int nDataSize, Stea

typedef struct
{
bool connected;
bool report_sensors;
uint32_t update_rate_in_us;
Uint64 sensor_timestamp;
Expand Down Expand Up @@ -1028,10 +1029,11 @@ static bool HIDAPI_DriverSteam_InitDevice(SDL_HIDAPI_Device *device)
return SDL_SetError("Failed to send ID_DONGLE_GET_WIRELESS_STATE request");
}

// We will enumerate any attached controllers in UpdateDevices()
// We will enumerate any attached controllers in UpdateDevice()
return true;
} else {
// Wired and BLE controllers are always connected if HIDAPI can see them
ctx->connected = true;
return HIDAPI_JoystickConnected(device, NULL);
}
}
Expand Down Expand Up @@ -1242,22 +1244,24 @@ static bool HIDAPI_DriverSteam_UpdateDevice(SDL_HIDAPI_Device *device)
}

ctx->m_last_state = ctx->m_state;
} else if (joystick && D0G_IS_WIRELESS_DISCONNECT(pPacket, nPacketLength)) {
} 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;
} else if (!joystick && D0G_IS_WIRELESS_CONNECT(pPacket, nPacketLength)) {
ctx->connected = false;
} else if (!ctx->connected && D0G_IS_WIRELESS_CONNECT(pPacket, nPacketLength)) {
// Controller has connected to the wireless dongle
if (!HIDAPI_JoystickConnected(device, NULL)) {
return false;
}

joystick = SDL_GetJoystickFromID(device->joysticks[0]);
ctx->connected = true;
}

if (r <= 0) {
// Failed to read from controller
if (joystick) {
if (ctx->connected) {
HIDAPI_JoystickDisconnected(device, device->joysticks[0]);
}
return false;
Expand Down

0 comments on commit f0b61c6

Please sign in to comment.