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

Switch Joy-Con (Left / Right) support on macOS #6269

Open
terhechte opened this issue Oct 16, 2022 · 3 comments
Open

Switch Joy-Con (Left / Right) support on macOS #6269

terhechte opened this issue Oct 16, 2022 · 3 comments
Labels
A-Input Player input via keyboard, mouse, gamepad, and more C-Bug An unexpected or incorrect behavior O-MacOS Specific to the MacOS (Apple) desktop operating system

Comments

@terhechte
Copy link

Bevy version

6b75589

[Optional] Relevant system information

macOS 12.6

What you did

When I connect a single Switch Joy-Con (either left or right) to my Mac via bluetooth the D-Pad (left right up down) is not being registered. E.g. moving it doesn't generate any events in Bevy. The buttons (a, b, x, y) work fine.

What went wrong

I tracked the issue down to two places:

When I use my gilrs fork and when I change the bevy_gilrs/converter.rs locally to:

        gilrs::Axis::DPadX => Some(GamepadAxisType::LeftStickX),
        gilrs::Axis::DPadY => Some(GamepadAxisType::LeftStickY),
        // The `axis_dpad_to_button` gilrs filter should filter out all DPadX and DPadY events. If
        // it doesn't then we probably need an entry added to the following repo and an update to
        // GilRs to use the updated database: https://github.com/gabomdq/SDL_GameControllerDB
        gilrs::Axis::Unknown => None,

Then I get the correct events and I can use my Joy-Con's for controlling a Bevy game. However I don't have enough knowledge about this code to know why the filter for D-Pad events existed in the first place. I'll happily create a PR with these changes if somebody who understands this can confirm that this is indeed a useful solution.

@terhechte terhechte added C-Bug An unexpected or incorrect behavior S-Needs-Triage This issue needs to be labelled labels Oct 16, 2022
@alice-i-cecile alice-i-cecile added A-Input Player input via keyboard, mouse, gamepad, and more O-MacOS Specific to the MacOS (Apple) desktop operating system and removed S-Needs-Triage This issue needs to be labelled labels Oct 16, 2022
@mockersf
Copy link
Member

DPadX and DPadY were removed in #5220

You should receive events for DPadUp / DPad... instead

@rparrett
Copy link
Contributor

rparrett commented Jan 19, 2023

Just checking on the current state of this. I tested JoyCon on macOS with bevy main and gamepad_input_events.

If I connect one JoyCon at a time, I get some events, but the mapping doesn't seem to make sense with any controller orientation.

If I connect the matching JoyCon, I see a connection event for that particular JoyCon, but afterwards I get no events at all when pressing buttons. (This behavior is the same in gilrs master branch)

Testing with L JoyCon

button event
up GamepadButtonChangedEvent { gamepad: Gamepad { id: 0 }, button_type: North, value: 1.0 }
left GamepadButtonChangedEvent { gamepad: Gamepad { id: 0 }, button_type: South, value: 1.0 }
down GamepadButtonChangedEvent { gamepad: Gamepad { id: 0 }, button_type: East, value: 1.0 }
right GamepadButtonChangedEvent { gamepad: Gamepad { id: 0 }, button_type: West, value: 1.0 }
L1 GamepadButtonChangedEvent { gamepad: Gamepad { id: 0 }, button_type: DPadRight, value: 1.0 }
L2 GamepadButtonChangedEvent { gamepad: Gamepad { id: 0 }, button_type: C, value: 1.0 }
stick (press) GamepadButtonChangedEvent { gamepad: Gamepad { id: 0 }, button_type: Mode, value: 1.0 }
stick Nothing
- GamepadButtonChangedEvent { gamepad: Gamepad { id: 0 }, button_type: Start, value: 1.0 }
Home GamepadButtonChangedEvent { gamepad: Gamepad { id: 0 }, button_type: DPadLeft, value: 1.0 }
SL GamepadButtonChangedEvent { gamepad: Gamepad { id: 0 }, button_type: LeftTrigger, value: 1.0 }
SR GamepadButtonChangedEvent { gamepad: Gamepad { id: 0 }, button_type: RightTrigger, value: 1.0 }

Testing with R JoyCon

button event
X GamepadButtonChangedEvent { gamepad: Gamepad { id: 3 }, button_type: East, value: 1.0 }
Y GamepadButtonChangedEvent { gamepad: Gamepad { id: 3 }, button_type: West, value: 1.0 }
B GamepadButtonChangedEvent { gamepad: Gamepad { id: 3 }, button_type: North, value: 1.0 }
A GamepadButtonChangedEvent { gamepad: Gamepad { id: 3 }, button_type: South, value: 1.0 }
R1 GamepadButtonChangedEvent { gamepad: Gamepad { id: 3 }, button_type: DPadRight, value: 1.0 }
R2 GamepadButtonChangedEvent { gamepad: Gamepad { id: 3 }, button_type: C, value: 1.0 }
stick(press) GamepadButtonChangedEvent { gamepad: Gamepad { id: 3 }, button_type: DPadUp, value: 1.0 }
stick Nothing
+ GamepadButtonChangedEvent { gamepad: Gamepad { id: 3 }, button_type: Select, value: 1.0 }
Home GamepadButtonChangedEvent { gamepad: Gamepad { id: 3 }, button_type: DPadDown, value: 1.0 }
SL GamepadButtonChangedEvent { gamepad: Gamepad { id: 3 }, button_type: LeftTrigger, value: 1.0 }
SR GamepadButtonChangedEvent { gamepad: Gamepad { id: 3 }, button_type: RightTrigger, value: 1.0 }

I didn't test as thoroughly on the gilrs master branch, but moving sticks there results in dpad events like:

Event { id: GamepadId(0), event: AxisChanged(DPadX, 1.0, Code(EvCode(EvCode { page: 1, usage: 57 }))), time: SystemTime { tv_sec: 1674092067, tv_nsec: 727176000 } }

and the mapping for directional buttons seems similar.

@rparrett
Copy link
Contributor

rparrett commented Jan 19, 2023

I don't know if I am going to keep working on this, so to summarize my findings:

  • Adding "proper" support for analog values from an individual Joy-Con's stick would be difficult. I think this would require some major work in the platform-specific HID code and down the chain from there.

  • The current mapping for Joy-Con (L) and JoyCon (R) in SDL_GameControllerDB is attempting to map the "hat" to an axis, but gilrs does not support this.

    This causes the entire mapping to fail to parse and be thrown out. gilrs#96

    Consequently, axis_dpad_to_button fails to turn the resulting AxisChanged events into ButtonChanged events.

    Bevy is relying on that filter working, so it intentionally ignores the the dpad in AxisChanged events.

    This seems much easier to fix, and we would probably want to fix this upstream in gilrs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Input Player input via keyboard, mouse, gamepad, and more C-Bug An unexpected or incorrect behavior O-MacOS Specific to the MacOS (Apple) desktop operating system
Projects
None yet
Development

No branches or pull requests

4 participants