| Summary: | Analog and Sensor support for Joy-Cons (Patch) | ||
|---|---|---|---|
| Product: | SDL | Reporter: | jibb |
| Component: | joystick | Assignee: | Sam Lantinga <slouken> |
| Status: | RESOLVED FIXED | QA Contact: | Sam Lantinga <slouken> |
| Severity: | normal | ||
| Priority: | P2 | ||
| Version: | 2.0.15 | ||
| Hardware: | x86_64 | ||
| OS: | Windows 10 | ||
| Attachments: | Partially-complete patch for Joy-Con analog/sensor support | ||
Patch added, thanks! https://hg.libsdl.org/SDL/rev/85625becaca4 |
Created attachment 4678 [details] Partially-complete patch for Joy-Con analog/sensor support This is a mostly functional patch that adds the hint SDL_JOYSTICK_HIDAPI_JOY_CONS to recognize Joy-Cons as Switch Pro Controllers (mostly) when SDL_JOYSTICK_HIDAPI_SWITCH is also enabled. But I'm not seeking to have it merged in yet -- I'm seeking help to get it working properly, but I think I've gotten it most of the way there with this patch. When SDL_JOYSTICK_HIDAPI_JOY_CONS is enabled, this works exactly as I'd hoped -- Joy-Con home button lights up, sensor axes are changed to match other controllers, analog inputs are detected, buttons are mapped correctly, etc. In order to detect Joy-Cons as HIDAPI controllers, I've uncommented these lines in controller_type.h and then treating them as Switch Pro Controllers if this hint is enabled (with some device-specifics handled in SDL_hidapi_switch.c), but it seems Joy-Cons are just not working at all with this patch if the hint is not enabled, so I'm looking for some input/direction. { MAKE_CONTROLLER_ID( 0x057e, 0x2006 ), k_eControllerType_SwitchJoyConLeft, NULL }, // Nintendo Switch Joy-Con (Left) { MAKE_CONTROLLER_ID( 0x057e, 0x2007 ), k_eControllerType_SwitchJoyConRight, NULL }, // Nintendo Switch Joy-Con (Right) In SDL_GetJoystickGameControllerType I check SDL_HINT_JOYSTICK_HIDAPI_JOY_CONS. If it is enabled and the controller is a Joy-Con, I have it return SDL_CONTROLLER_TYPE_NINTENDO_SWITCH_PRO and everything works fine and dandy from there. If the hint is not enabled, I return SDL_CONTROLLER_TYPE_UNKNOWN instead. This was in the hopes that the default behaviour of a Joy-Con would be restored in this case. However, in my tests, no input is detected from the Joy-Cons anymore when the hint is disabled. I suspect including Joy-Cons in the list in controller_type.h at all is flagging it as a HIDAPI controller and default behaviour is being skipped. As far as I can tell, including them in that array in controller_type.h at all is the only difference visible to anything else when that hint is disabled, so that's my best guess. If that's the case, I can't think of a way to only include the Joy-Cons in this list of controller types on the condition of this hint being enabled. Is there a better way to do this? And is this generally a good way to go about doing this (adding a hint so we can take advantage of Joy-Cons without changing the default behaviour for whomever is used to the more limited live behaviour)? If we can support the Joy-Cons properly with sensor support like I have working in this patch, SDL covers all the device-specific behaviour of my library and I can encourage my users to use SDL for wider controller support.