mirror of
https://github.com/Relintai/sdl2_frt.git
synced 2024-12-25 09:17:12 +01:00
joystick: Ensure HIDAPI is initialized before calling it
This commit is contained in:
parent
e149f4c4b0
commit
c172f36bf4
@ -99,6 +99,7 @@ static SDL_HIDAPI_DeviceDriver *SDL_HIDAPI_drivers[] = {
|
|||||||
static int SDL_HIDAPI_numdrivers = 0;
|
static int SDL_HIDAPI_numdrivers = 0;
|
||||||
static SDL_HIDAPI_Device *SDL_HIDAPI_devices;
|
static SDL_HIDAPI_Device *SDL_HIDAPI_devices;
|
||||||
static int SDL_HIDAPI_numjoysticks = 0;
|
static int SDL_HIDAPI_numjoysticks = 0;
|
||||||
|
static SDL_bool initialized = SDL_FALSE;
|
||||||
|
|
||||||
#if defined(SDL_USE_LIBUDEV)
|
#if defined(SDL_USE_LIBUDEV)
|
||||||
static const SDL_UDEV_Symbols * usyms = NULL;
|
static const SDL_UDEV_Symbols * usyms = NULL;
|
||||||
@ -696,6 +697,10 @@ HIDAPI_JoystickInit(void)
|
|||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
if (initialized) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (hid_init() < 0) {
|
if (hid_init() < 0) {
|
||||||
SDL_SetError("Couldn't initialize hidapi");
|
SDL_SetError("Couldn't initialize hidapi");
|
||||||
return -1;
|
return -1;
|
||||||
@ -709,6 +714,9 @@ HIDAPI_JoystickInit(void)
|
|||||||
SDL_HIDAPIDriverHintChanged, NULL);
|
SDL_HIDAPIDriverHintChanged, NULL);
|
||||||
HIDAPI_InitializeDiscovery();
|
HIDAPI_InitializeDiscovery();
|
||||||
HIDAPI_JoystickDetect();
|
HIDAPI_JoystickDetect();
|
||||||
|
|
||||||
|
initialized = SDL_TRUE;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1059,6 +1067,8 @@ HIDAPI_JoystickQuit(void)
|
|||||||
SDL_HIDAPI_numjoysticks = 0;
|
SDL_HIDAPI_numjoysticks = 0;
|
||||||
|
|
||||||
hid_exit();
|
hid_exit();
|
||||||
|
|
||||||
|
initialized = SDL_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_JoystickDriver SDL_HIDAPI_JoystickDriver =
|
SDL_JoystickDriver SDL_HIDAPI_JoystickDriver =
|
||||||
|
@ -120,6 +120,8 @@ IsJoystick(int fd, char *namebuf, const size_t namebuflen, SDL_JoystickGUID *gui
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef SDL_JOYSTICK_HIDAPI
|
#ifdef SDL_JOYSTICK_HIDAPI
|
||||||
|
SDL_HIDAPI_JoystickDriver.Init();
|
||||||
|
|
||||||
if (HIDAPI_IsDevicePresent(inpid.vendor, inpid.product, inpid.version)) {
|
if (HIDAPI_IsDevicePresent(inpid.vendor, inpid.product, inpid.version)) {
|
||||||
/* The HIDAPI driver is taking care of this device */
|
/* The HIDAPI driver is taking care of this device */
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user