mirror of https://github.com/encounter/SDL.git
Try up to 20 times to read the controller type
It takes a while for Joy-Cons to initialize when plugged in via the Nintendo Joy-Con Charging Grip.
This commit is contained in:
parent
e5f161bda4
commit
62f2379e4c
|
@ -931,6 +931,9 @@ ReadJoyConControllerType(SDL_HIDAPI_Device *device)
|
|||
|
||||
device->dev = SDL_hid_open_path(device->path, 0);
|
||||
if (device->dev) {
|
||||
const int MAX_ATTEMPTS = 20;
|
||||
int attempts = 0;
|
||||
for (attempts = 0; attempts < MAX_ATTEMPTS; ++attempts) {
|
||||
if (WriteProprietary(ctx, k_eSwitchProprietaryCommandIDs_Status, NULL, 0, SDL_TRUE)) {
|
||||
SwitchProprietaryStatusPacket_t *status = (SwitchProprietaryStatusPacket_t *)&ctx->m_rgucReadBuffer[0];
|
||||
|
||||
|
@ -949,11 +952,21 @@ ReadJoyConControllerType(SDL_HIDAPI_Device *device)
|
|||
eControllerType = (ESwitchDeviceInfoControllerType)reply->deviceInfo.ucDeviceType;
|
||||
}
|
||||
}
|
||||
if (eControllerType == k_eSwitchDeviceInfoControllerType_Unknown) {
|
||||
/* Wait a bit and try again */
|
||||
SDL_Delay(100);
|
||||
continue;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
printf("Attempts: %d\n", attempts);
|
||||
SDL_hid_close(device->dev);
|
||||
device->dev = NULL;
|
||||
}
|
||||
SDL_free(ctx);
|
||||
}
|
||||
printf("Controller type %d\n", eControllerType);
|
||||
return eControllerType;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue