mirror of https://github.com/encounter/SDL.git
Added support for the Kinvoca Joy-Cons
These report their VID/PID as a Nintendo Switch Pro controller, but they are actually left/right Joy-Cons. We'll fix up the joystick GUID so applications can handle them appropriately.
This commit is contained in:
parent
92d3fc4883
commit
b2c3237b75
|
@ -1181,19 +1181,23 @@ ReadJoyConControllerType(SDL_HIDAPI_Device *device)
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
UpdateDeviceName(SDL_HIDAPI_Device *device, ESwitchDeviceInfoControllerType eControllerType)
|
UpdateDeviceIdentity(SDL_HIDAPI_Device *device)
|
||||||
{
|
{
|
||||||
|
ESwitchDeviceInfoControllerType eControllerType = (ESwitchDeviceInfoControllerType)device->guid.data[15];
|
||||||
const char *name = NULL;
|
const char *name = NULL;
|
||||||
|
|
||||||
switch (eControllerType) {
|
switch (eControllerType) {
|
||||||
case k_eSwitchDeviceInfoControllerType_JoyConLeft:
|
case k_eSwitchDeviceInfoControllerType_JoyConLeft:
|
||||||
name = "Nintendo Switch Joy-Con (L)";
|
name = "Nintendo Switch Joy-Con (L)";
|
||||||
|
SDL_SetJoystickGUIDProduct(&device->guid, USB_PRODUCT_NINTENDO_SWITCH_JOYCON_LEFT);
|
||||||
break;
|
break;
|
||||||
case k_eSwitchDeviceInfoControllerType_JoyConRight:
|
case k_eSwitchDeviceInfoControllerType_JoyConRight:
|
||||||
name = "Nintendo Switch Joy-Con (R)";
|
name = "Nintendo Switch Joy-Con (R)";
|
||||||
|
SDL_SetJoystickGUIDProduct(&device->guid, USB_PRODUCT_NINTENDO_SWITCH_JOYCON_RIGHT);
|
||||||
break;
|
break;
|
||||||
case k_eSwitchDeviceInfoControllerType_ProController:
|
case k_eSwitchDeviceInfoControllerType_ProController:
|
||||||
name = "Nintendo Switch Pro Controller";
|
name = "Nintendo Switch Pro Controller";
|
||||||
|
SDL_SetJoystickGUIDProduct(&device->guid, USB_PRODUCT_NINTENDO_SWITCH_PRO);
|
||||||
break;
|
break;
|
||||||
case k_eSwitchDeviceInfoControllerType_NESLeft:
|
case k_eSwitchDeviceInfoControllerType_NESLeft:
|
||||||
name = "Nintendo NES Controller (L)";
|
name = "Nintendo NES Controller (L)";
|
||||||
|
@ -1203,12 +1207,15 @@ UpdateDeviceName(SDL_HIDAPI_Device *device, ESwitchDeviceInfoControllerType eCon
|
||||||
break;
|
break;
|
||||||
case k_eSwitchDeviceInfoControllerType_SNES:
|
case k_eSwitchDeviceInfoControllerType_SNES:
|
||||||
name = "Nintendo SNES Controller";
|
name = "Nintendo SNES Controller";
|
||||||
|
SDL_SetJoystickGUIDProduct(&device->guid, USB_PRODUCT_NINTENDO_SNES_CONTROLLER);
|
||||||
break;
|
break;
|
||||||
case k_eSwitchDeviceInfoControllerType_N64:
|
case k_eSwitchDeviceInfoControllerType_N64:
|
||||||
name = "Nintendo N64 Controller";
|
name = "Nintendo N64 Controller";
|
||||||
|
device->product_id = USB_PRODUCT_NINTENDO_N64_CONTROLLER;
|
||||||
break;
|
break;
|
||||||
case k_eSwitchDeviceInfoControllerType_SEGA_Genesis:
|
case k_eSwitchDeviceInfoControllerType_SEGA_Genesis:
|
||||||
name = "Nintendo SEGA Genesis Controller";
|
name = "Nintendo SEGA Genesis Controller";
|
||||||
|
SDL_SetJoystickGUIDProduct(&device->guid, USB_PRODUCT_NINTENDO_SEGA_GENESIS_CONTROLLER);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
@ -1231,21 +1238,17 @@ HIDAPI_DriverSwitch_InitDevice(SDL_HIDAPI_Device *device)
|
||||||
/* This might be a Joy-Con that's missing from a charging grip slot */
|
/* This might be a Joy-Con that's missing from a charging grip slot */
|
||||||
if (device->product_id == USB_PRODUCT_NINTENDO_SWITCH_JOYCON_GRIP) {
|
if (device->product_id == USB_PRODUCT_NINTENDO_SWITCH_JOYCON_GRIP) {
|
||||||
if (device->interface_number == 1) {
|
if (device->interface_number == 1) {
|
||||||
SDL_free(device->name);
|
|
||||||
device->name = SDL_strdup("Nintendo Switch Joy-Con (L)");
|
|
||||||
device->guid.data[15] = k_eSwitchDeviceInfoControllerType_JoyConLeft;
|
device->guid.data[15] = k_eSwitchDeviceInfoControllerType_JoyConLeft;
|
||||||
} else {
|
} else {
|
||||||
SDL_free(device->name);
|
|
||||||
device->name = SDL_strdup("Nintendo Switch Joy-Con (R)");
|
|
||||||
device->guid.data[15] = k_eSwitchDeviceInfoControllerType_JoyConRight;
|
device->guid.data[15] = k_eSwitchDeviceInfoControllerType_JoyConRight;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
UpdateDeviceName(device, eControllerType);
|
|
||||||
device->guid.data[15] = eControllerType;
|
device->guid.data[15] = eControllerType;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
UpdateDeviceIdentity(device);
|
||||||
}
|
}
|
||||||
return HIDAPI_JoystickConnected(device, NULL);
|
return HIDAPI_JoystickConnected(device, NULL);
|
||||||
}
|
}
|
||||||
|
|
|
@ -712,6 +712,8 @@ HIDAPI_CreateCombinedJoyCons()
|
||||||
}
|
}
|
||||||
|
|
||||||
for (device = SDL_HIDAPI_devices; device; device = device->next) {
|
for (device = SDL_HIDAPI_devices; device; device = device->next) {
|
||||||
|
Uint16 vendor, product;
|
||||||
|
|
||||||
if (!device->driver) {
|
if (!device->driver) {
|
||||||
/* Unsupported device */
|
/* Unsupported device */
|
||||||
continue;
|
continue;
|
||||||
|
@ -721,15 +723,17 @@ HIDAPI_CreateCombinedJoyCons()
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SDL_GetJoystickGUIDInfo(device->guid, &vendor, &product, NULL, NULL);
|
||||||
|
|
||||||
if (!joycons[0] &&
|
if (!joycons[0] &&
|
||||||
(SDL_IsJoystickNintendoSwitchJoyConLeft(device->vendor_id, device->product_id) ||
|
(SDL_IsJoystickNintendoSwitchJoyConLeft(vendor, product) ||
|
||||||
(SDL_IsJoystickNintendoSwitchJoyConGrip(device->vendor_id, device->product_id) &&
|
(SDL_IsJoystickNintendoSwitchJoyConGrip(vendor, product) &&
|
||||||
SDL_strstr(device->name, "(L)") != NULL))) {
|
SDL_strstr(device->name, "(L)") != NULL))) {
|
||||||
joycons[0] = device;
|
joycons[0] = device;
|
||||||
}
|
}
|
||||||
if (!joycons[1] &&
|
if (!joycons[1] &&
|
||||||
(SDL_IsJoystickNintendoSwitchJoyConRight(device->vendor_id, device->product_id) ||
|
(SDL_IsJoystickNintendoSwitchJoyConRight(vendor, product) ||
|
||||||
(SDL_IsJoystickNintendoSwitchJoyConGrip(device->vendor_id, device->product_id) &&
|
(SDL_IsJoystickNintendoSwitchJoyConGrip(vendor, product) &&
|
||||||
SDL_strstr(device->name, "(R)") != NULL))) {
|
SDL_strstr(device->name, "(R)") != NULL))) {
|
||||||
joycons[1] = device;
|
joycons[1] = device;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue