JoystickAndroid: Implement acquiring hat button values similar to existing implementation in JoystickSDL #11266
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.