diff options
| author | 2023-03-11 00:35:51 -0500 | |
|---|---|---|
| committer | 2023-06-03 00:05:40 -0700 | |
| commit | b9f1f70688e6a37fc3ad558586fabbf522cb892e (patch) | |
| tree | da6f1330b1407e56474dfb631eaaee2d9dcb9149 /src/android | |
| parent | android: Convert BiMap to Kotlin (diff) | |
| download | yuzu-b9f1f70688e6a37fc3ad558586fabbf522cb892e.tar.gz yuzu-b9f1f70688e6a37fc3ad558586fabbf522cb892e.tar.xz yuzu-b9f1f70688e6a37fc3ad558586fabbf522cb892e.zip | |
android: Convert ControllerMappingHelper to Kotlin
Diffstat (limited to 'src/android')
| -rw-r--r-- | src/android/app/src/main/java/org/yuzu/yuzu_emu/utils/ControllerMappingHelper.kt (renamed from src/android/app/src/main/java/org/yuzu/yuzu_emu/utils/ControllerMappingHelper.java) | 49 |
1 files changed, 24 insertions, 25 deletions
diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/utils/ControllerMappingHelper.java b/src/android/app/src/main/java/org/yuzu/yuzu_emu/utils/ControllerMappingHelper.kt index 92fa50edf..a0b8cccf7 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/utils/ControllerMappingHelper.java +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/utils/ControllerMappingHelper.kt | |||
| @@ -1,66 +1,65 @@ | |||
| 1 | package org.yuzu.yuzu_emu.utils; | 1 | package org.yuzu.yuzu_emu.utils |
| 2 | 2 | ||
| 3 | import android.view.InputDevice; | 3 | import android.view.InputDevice |
| 4 | import android.view.KeyEvent; | 4 | import android.view.KeyEvent |
| 5 | import android.view.MotionEvent; | 5 | import android.view.MotionEvent |
| 6 | 6 | ||
| 7 | /** | 7 | /** |
| 8 | * Some controllers have incorrect mappings. This class has special-case fixes for them. | 8 | * Some controllers have incorrect mappings. This class has special-case fixes for them. |
| 9 | */ | 9 | */ |
| 10 | public class ControllerMappingHelper { | 10 | class ControllerMappingHelper { |
| 11 | /** | 11 | /** |
| 12 | * Some controllers report extra button presses that can be ignored. | 12 | * Some controllers report extra button presses that can be ignored. |
| 13 | */ | 13 | */ |
| 14 | public boolean shouldKeyBeIgnored(InputDevice inputDevice, int keyCode) { | 14 | fun shouldKeyBeIgnored(inputDevice: InputDevice, keyCode: Int): Boolean { |
| 15 | if (isDualShock4(inputDevice)) { | 15 | return if (isDualShock4(inputDevice)) { |
| 16 | // The two analog triggers generate analog motion events as well as a keycode. | 16 | // The two analog triggers generate analog motion events as well as a keycode. |
| 17 | // We always prefer to use the analog values, so throw away the button press | 17 | // We always prefer to use the analog values, so throw away the button press |
| 18 | return keyCode == KeyEvent.KEYCODE_BUTTON_L2 || keyCode == KeyEvent.KEYCODE_BUTTON_R2; | 18 | keyCode == KeyEvent.KEYCODE_BUTTON_L2 || keyCode == KeyEvent.KEYCODE_BUTTON_R2 |
| 19 | } | 19 | } else false |
| 20 | return false; | ||
| 21 | } | 20 | } |
| 22 | 21 | ||
| 23 | /** | 22 | /** |
| 24 | * Scale an axis to be zero-centered with a proper range. | 23 | * Scale an axis to be zero-centered with a proper range. |
| 25 | */ | 24 | */ |
| 26 | public float scaleAxis(InputDevice inputDevice, int axis, float value) { | 25 | fun scaleAxis(inputDevice: InputDevice, axis: Int, value: Float): Float { |
| 27 | if (isDualShock4(inputDevice)) { | 26 | if (isDualShock4(inputDevice)) { |
| 28 | // Android doesn't have correct mappings for this controller's triggers. It reports them | 27 | // Android doesn't have correct mappings for this controller's triggers. It reports them |
| 29 | // as RX & RY, centered at -1.0, and with a range of [-1.0, 1.0] | 28 | // as RX & RY, centered at -1.0, and with a range of [-1.0, 1.0] |
| 30 | // Scale them to properly zero-centered with a range of [0.0, 1.0]. | 29 | // Scale them to properly zero-centered with a range of [0.0, 1.0]. |
| 31 | if (axis == MotionEvent.AXIS_RX || axis == MotionEvent.AXIS_RY) { | 30 | if (axis == MotionEvent.AXIS_RX || axis == MotionEvent.AXIS_RY) { |
| 32 | return (value + 1) / 2.0f; | 31 | return (value + 1) / 2.0f |
| 33 | } | 32 | } |
| 34 | } else if (isXboxOneWireless(inputDevice)) { | 33 | } else if (isXboxOneWireless(inputDevice)) { |
| 35 | // Same as the DualShock 4, the mappings are missing. | 34 | // Same as the DualShock 4, the mappings are missing. |
| 36 | if (axis == MotionEvent.AXIS_Z || axis == MotionEvent.AXIS_RZ) { | 35 | if (axis == MotionEvent.AXIS_Z || axis == MotionEvent.AXIS_RZ) { |
| 37 | return (value + 1) / 2.0f; | 36 | return (value + 1) / 2.0f |
| 38 | } | 37 | } |
| 39 | if (axis == MotionEvent.AXIS_GENERIC_1) { | 38 | if (axis == MotionEvent.AXIS_GENERIC_1) { |
| 40 | // This axis is stuck at ~.5. Ignore it. | 39 | // This axis is stuck at ~.5. Ignore it. |
| 41 | return 0.0f; | 40 | return 0.0f |
| 42 | } | 41 | } |
| 43 | } else if (isMogaPro2Hid(inputDevice)) { | 42 | } else if (isMogaPro2Hid(inputDevice)) { |
| 44 | // This controller has a broken axis that reports a constant value. Ignore it. | 43 | // This controller has a broken axis that reports a constant value. Ignore it. |
| 45 | if (axis == MotionEvent.AXIS_GENERIC_1) { | 44 | if (axis == MotionEvent.AXIS_GENERIC_1) { |
| 46 | return 0.0f; | 45 | return 0.0f |
| 47 | } | 46 | } |
| 48 | } | 47 | } |
| 49 | return value; | 48 | return value |
| 50 | } | 49 | } |
| 51 | 50 | ||
| 52 | private boolean isDualShock4(InputDevice inputDevice) { | 51 | // Sony DualShock 4 controller |
| 53 | // Sony DualShock 4 controller | 52 | private fun isDualShock4(inputDevice: InputDevice): Boolean { |
| 54 | return inputDevice.getVendorId() == 0x54c && inputDevice.getProductId() == 0x9cc; | 53 | return inputDevice.vendorId == 0x54c && inputDevice.productId == 0x9cc |
| 55 | } | 54 | } |
| 56 | 55 | ||
| 57 | private boolean isXboxOneWireless(InputDevice inputDevice) { | 56 | // Microsoft Xbox One controller |
| 58 | // Microsoft Xbox One controller | 57 | private fun isXboxOneWireless(inputDevice: InputDevice): Boolean { |
| 59 | return inputDevice.getVendorId() == 0x45e && inputDevice.getProductId() == 0x2e0; | 58 | return inputDevice.vendorId == 0x45e && inputDevice.productId == 0x2e0 |
| 60 | } | 59 | } |
| 61 | 60 | ||
| 62 | private boolean isMogaPro2Hid(InputDevice inputDevice) { | 61 | // Moga Pro 2 HID |
| 63 | // Moga Pro 2 HID | 62 | private fun isMogaPro2Hid(inputDevice: InputDevice): Boolean { |
| 64 | return inputDevice.getVendorId() == 0x20d6 && inputDevice.getProductId() == 0x6271; | 63 | return inputDevice.vendorId == 0x20d6 && inputDevice.productId == 0x6271 |
| 65 | } | 64 | } |
| 66 | } | 65 | } |