Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Analog and Sensor support for Joy-Cons (Patch) #3998

Closed
SDLBugzilla opened this issue Feb 11, 2021 · 0 comments
Closed

Analog and Sensor support for Joy-Cons (Patch) #3998

SDLBugzilla opened this issue Feb 11, 2021 · 0 comments

Comments

@SDLBugzilla
Copy link
Collaborator

This bug report was migrated from our old Bugzilla tracker.

These attachments are available in the static archive:

Reported in version: 2.0.15
Reported for operating system, platform: Windows 10, x86_64

Comments on the original bug report:

On 2021-01-18 12:29:13 +0000, wrote:

Created attachment 4678
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.

On 2021-01-23 17:41:58 +0000, Sam Lantinga wrote:

Patch added, thanks!
https://hg.libsdl.org/SDL/rev/85625becaca4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant