Skip to content

Commit b833c61

Browse files
committed
Improved reliability detecting FlyDigi Vader controllers
1 parent 0e262df commit b833c61

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

src/joystick/hidapi/SDL_hidapi_flydigi.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,19 +95,18 @@ static void UpdateDeviceIdentity(SDL_HIDAPI_Device *device)
9595
{
9696
SDL_DriverFlydigi_Context *ctx = (SDL_DriverFlydigi_Context *)device->context;
9797

98-
for (int attempt = 0; ctx->deviceID == 0 && attempt < 3; ++attempt) {
98+
// Detecting the Vader 2 can take over 1000 read retries, so be generous here
99+
for (int attempt = 0; ctx->deviceID == 0 && attempt < 30; ++attempt) {
99100
const Uint8 request[] = { FLYDIGI_CMD_REPORT_ID, FLYDIGI_GET_INFO_COMMAND, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
100-
int size = SDL_hid_write(device->dev, request, sizeof(request));
101-
if (size < 0) {
102-
break;
103-
}
101+
// This write will occasionally return -1, so ignore failure here and try again
102+
(void)SDL_hid_write(device->dev, request, sizeof(request));
104103

105104
// Read the reply
106105
for (int i = 0; i < 100; ++i) {
107106
SDL_Delay(1);
108107

109108
Uint8 data[USB_PACKET_LENGTH];
110-
size = SDL_hid_read_timeout(device->dev, data, sizeof(data), 0);
109+
int size = SDL_hid_read_timeout(device->dev, data, sizeof(data), 0);
111110
if (size < 0) {
112111
break;
113112
}

0 commit comments

Comments
 (0)