Rolling back GameCube HIDAPI support

It causes the HIDAPI devices to always be opened on enumeration, which causes crashes in the Windows drivers when multiple applications are reading and writing at the same time. We can revisit this after 2.0.10 release.
This commit is contained in:
Sam Lantinga
2019-06-19 15:54:21 -07:00
parent 56e2b9a4ee
commit be6cda9f95
16 changed files with 176 additions and 826 deletions

View File

@@ -183,7 +183,6 @@ typedef struct
#pragma pack()
typedef struct {
SDL_JoystickID joystickID;
hid_device *dev;
SDL_bool m_bIsUsingBluetooth;
Uint8 m_nCommandNumber;
@@ -571,7 +570,7 @@ static Sint16 ApplyStickCalibration(SDL_DriverSwitch_Context *ctx, int nStick, i
}
static SDL_bool
HIDAPI_DriverSwitch_InitDriver(SDL_HIDAPI_DriverData *context, Uint16 vendor_id, Uint16 product_id, int *num_joysticks)
HIDAPI_DriverSwitch_Init(SDL_Joystick *joystick, hid_device *dev, Uint16 vendor_id, Uint16 product_id, void **context)
{
SDL_DriverSwitch_Context *ctx;
Uint8 input_mode;
@@ -581,9 +580,9 @@ HIDAPI_DriverSwitch_InitDriver(SDL_HIDAPI_DriverData *context, Uint16 vendor_id,
SDL_OutOfMemory();
return SDL_FALSE;
}
ctx->dev = context->device;
ctx->dev = dev;
context->context = ctx;
*context = ctx;
/* Initialize rumble data */
SetNeutralRumble(&ctx->m_RumblePacket.rumbleData[0]);
@@ -628,18 +627,6 @@ HIDAPI_DriverSwitch_InitDriver(SDL_HIDAPI_DriverData *context, Uint16 vendor_id,
}
}
ctx->joystickID = SDL_GetNextJoystickInstanceID();
*num_joysticks += 1;
SDL_PrivateJoystickAdded(ctx->joystickID);
return SDL_TRUE;
}
static SDL_bool
HIDAPI_DriverSwitch_OpenJoystick(SDL_HIDAPI_DriverData *context, SDL_Joystick *joystick)
{
SDL_DriverSwitch_Context *ctx = (SDL_DriverSwitch_Context *)context->context;
/* Set the LED state */
SetHomeLED(ctx, 100);
SetSlotLED(ctx, (joystick->instance_id % 4));
@@ -653,9 +640,9 @@ HIDAPI_DriverSwitch_OpenJoystick(SDL_HIDAPI_DriverData *context, SDL_Joystick *j
}
static int
HIDAPI_DriverSwitch_Rumble(SDL_HIDAPI_DriverData *context, SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble, Uint32 duration_ms)
HIDAPI_DriverSwitch_Rumble(SDL_Joystick *joystick, hid_device *dev, void *context, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble, Uint32 duration_ms)
{
SDL_DriverSwitch_Context *ctx = (SDL_DriverSwitch_Context *)context->context;
SDL_DriverSwitch_Context *ctx = (SDL_DriverSwitch_Context *)context;
/* Experimentally determined rumble values. These will only matter on some controllers as tested ones
* seem to disregard these and just use any non-zero rumble values as a binary flag for constant rumble
@@ -860,16 +847,11 @@ static void HandleFullControllerState(SDL_Joystick *joystick, SDL_DriverSwitch_C
}
static SDL_bool
HIDAPI_DriverSwitch_UpdateDriver(SDL_HIDAPI_DriverData *context, int *num_joysticks)
HIDAPI_DriverSwitch_Update(SDL_Joystick *joystick, hid_device *dev, void *context)
{
SDL_DriverSwitch_Context *ctx = (SDL_DriverSwitch_Context *)context->context;
SDL_Joystick *joystick = SDL_JoystickFromInstanceID(ctx->joystickID);
SDL_DriverSwitch_Context *ctx = (SDL_DriverSwitch_Context *)context;
int size;
if (joystick == NULL) {
return SDL_TRUE; /* Nothing to do right now! */
}
while ((size = ReadInput(ctx)) > 0) {
switch (ctx->m_rgucReadBuffer[0]) {
case k_eSwitchInputReportIDs_SimpleControllerState:
@@ -886,7 +868,7 @@ HIDAPI_DriverSwitch_UpdateDriver(SDL_HIDAPI_DriverData *context, int *num_joysti
if (ctx->m_nRumbleExpiration) {
Uint32 now = SDL_GetTicks();
if (SDL_TICKS_PASSED(now, ctx->m_nRumbleExpiration)) {
HIDAPI_DriverSwitch_Rumble(context, joystick, 0, 0, 0);
HIDAPI_DriverSwitch_Rumble(joystick, dev, context, 0, 0, 0);
}
}
@@ -894,37 +876,14 @@ HIDAPI_DriverSwitch_UpdateDriver(SDL_HIDAPI_DriverData *context, int *num_joysti
}
static void
HIDAPI_DriverSwitch_QuitDriver(SDL_HIDAPI_DriverData *context, SDL_bool send_event, int *num_joysticks)
HIDAPI_DriverSwitch_Quit(SDL_Joystick *joystick, hid_device *dev, void *context)
{
SDL_DriverSwitch_Context *ctx = (SDL_DriverSwitch_Context *)context->context;
SDL_DriverSwitch_Context *ctx = (SDL_DriverSwitch_Context *)context;
/* Restore simple input mode for other applications */
SetInputMode(ctx, k_eSwitchInputReportIDs_SimpleControllerState);
*num_joysticks -= 1;
if (send_event) {
SDL_PrivateJoystickRemoved(ctx->joystickID);
}
SDL_free(context->context);
}
static int
HIDAPI_DriverSwitch_NumJoysticks(SDL_HIDAPI_DriverData *context)
{
return 1;
}
static int
HIDAPI_DriverSwitch_PlayerIndexForIndex(SDL_HIDAPI_DriverData *context, int index)
{
return -1;
}
static SDL_JoystickID
HIDAPI_DriverSwitch_InstanceIDForIndex(SDL_HIDAPI_DriverData *context, int index)
{
SDL_DriverSwitch_Context *ctx = (SDL_DriverSwitch_Context *)context->context;
return ctx->joystickID;
SDL_free(context);
}
SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverSwitch =
@@ -933,14 +892,10 @@ SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverSwitch =
SDL_TRUE,
HIDAPI_DriverSwitch_IsSupportedDevice,
HIDAPI_DriverSwitch_GetDeviceName,
HIDAPI_DriverSwitch_InitDriver,
HIDAPI_DriverSwitch_QuitDriver,
HIDAPI_DriverSwitch_UpdateDriver,
HIDAPI_DriverSwitch_NumJoysticks,
HIDAPI_DriverSwitch_PlayerIndexForIndex,
HIDAPI_DriverSwitch_InstanceIDForIndex,
HIDAPI_DriverSwitch_OpenJoystick,
HIDAPI_DriverSwitch_Rumble
HIDAPI_DriverSwitch_Init,
HIDAPI_DriverSwitch_Rumble,
HIDAPI_DriverSwitch_Update,
HIDAPI_DriverSwitch_Quit
};
#endif /* SDL_JOYSTICK_HIDAPI_SWITCH */