Permalink
Show file tree
Hide file tree
1 comment
on commit
sign in to comment.
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Merge pull request #6156 from hackbar/input-fix-trigger
Android: Handle duplicate axis, and ignore known bad axis.
- Loading branch information
Showing
3 changed files
with
105 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| package org.dolphinemu.dolphinemu.utils; | ||
|
|
||
| import android.view.InputDevice; | ||
| import android.view.KeyEvent; | ||
| import android.view.MotionEvent; | ||
|
|
||
| /** Some controllers have incorrect mappings. This class has special-case fixes for them. */ | ||
| public class ControllerMappingHelper | ||
| { | ||
| /** Some controllers report extra button presses that can be ignored. */ | ||
| public boolean shouldKeyBeIgnored(InputDevice inputDevice, int keyCode) | ||
| { | ||
| if (isDualShock4(inputDevice)) { | ||
| // The two analog triggers generate analog motion events as well as a keycode. | ||
| // We always prefer to use the analog values, so throw away the button press | ||
| // Even though the triggers are L/R2, without mappings they generate L/R1 events. | ||
| return keyCode == KeyEvent.KEYCODE_BUTTON_L1 || keyCode == KeyEvent.KEYCODE_BUTTON_R1; | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| /** Scale an axis to be zero-centered with a proper range. */ | ||
| public float scaleAxis(InputDevice inputDevice, int axis, float value) | ||
| { | ||
| if (isDualShock4(inputDevice)) | ||
| { | ||
| // Android doesn't have correct mappings for this controller's triggers. It reports them | ||
| // as RX & RY, centered at -1.0, and with a range of [-1.0, 1.0] | ||
| // Scale them to properly zero-centered with a range of [0.0, 1.0]. | ||
| if (axis == MotionEvent.AXIS_RX || axis == MotionEvent.AXIS_RY) | ||
| { | ||
| return (value + 1) / 2.0f; | ||
| } | ||
| } | ||
| else if (isXboxOneWireless(inputDevice)) | ||
| { | ||
| // Same as the DualShock 4, the mappings are missing. | ||
| if (axis == MotionEvent.AXIS_Z || axis == MotionEvent.AXIS_RZ) | ||
| { | ||
| return (value + 1) / 2.0f; | ||
| } | ||
| if (axis == MotionEvent.AXIS_GENERIC_1) | ||
| { | ||
| // This axis is stuck at ~.5. Ignore it. | ||
| return 0.0f; | ||
| } | ||
| } | ||
| return value; | ||
| } | ||
|
|
||
| private boolean isDualShock4(InputDevice inputDevice) | ||
| { | ||
| // Sony DualShock 4 controller | ||
| return inputDevice.getVendorId() == 0x54c && inputDevice.getProductId() == 0x9cc; | ||
| } | ||
|
|
||
| private boolean isXboxOneWireless(InputDevice inputDevice) | ||
| { | ||
| // Microsoft Xbox One controller | ||
| return inputDevice.getVendorId() == 0x45e && inputDevice.getProductId() == 0x2e0; | ||
| } | ||
| } |
965b5b6There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This Version broken left Stick Dualshok 4 on Android, the analog can be mapped but does not work in game.