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

JoystickAndroid: Implement acquiring hat button values similar to existing implementation in JoystickSDL #11266

Merged
merged 2 commits into from May 18, 2024

Conversation

ivanzivotic
Copy link
Contributor

Implement _getHat function in the JoystickAndroid implementation of base Joystick class

Description

This pull request implements the _getHat(int hat, int i) function of JoystickAndroid class (inherited from Joystick class). Although this function is not called directly from anywhere in the code, my main motivation for this was to implement the same behavior on all supported platforms. It was driven by an existing implementation in the JoystickSDL class, where the hat variable represents a choice of which hat device is being used and i variable signifies one of four buttons available on hat.
Since there is support for only one hat button on Android operating system (explained here), only value 0 of hat parameter is accepted in the function. The second parameter is interpreted by following the implementation order of the buttons in the JoystickSDL class (up, down, left, right). All other values are considered invalid.
Since the hat values are represented by Android OS as axes, we have to read the values of X and Y Hat axis and check if they are -1 or 1, as described on this link. To achieve that, AXIS_HAT_X and AXIS_HAT_Y values are added as static integers to JoystickAndroid class and are read as part of static init function of the same class (similar to ACTION_DOWN and ACTION_UP android constants, except that they are part of the KeyEvent and not the MotionEvent android class).

Test Steps

Try calling the _getHat(int, int) function from a custom app on Android devices. Before this change, the behavior was not the same for devices running SDL library comparing to Android.

Checklist:

Related Issue

None.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@julianoes
Copy link
Contributor

@Davidsastresas you might be best at reviewing this.

@HTRamsey HTRamsey self-assigned this Apr 11, 2024
@HTRamsey HTRamsey merged commit af1df02 into mavlink:master May 18, 2024
10 checks passed
@HTRamsey
Copy link
Collaborator

Working through Joystick code now and came across this

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

Successfully merging this pull request may close these issues.

None yet

3 participants