diff options
author | Charles Lombardo <clombardo169@gmail.com> | 2023-03-11 06:35:51 +0100 |
---|---|---|
committer | bunnei <bunneidev@gmail.com> | 2023-06-03 09:05:40 +0200 |
commit | b9f1f70688e6a37fc3ad558586fabbf522cb892e (patch) | |
tree | da6f1330b1407e56474dfb631eaaee2d9dcb9149 /src | |
parent | android: Convert BiMap to Kotlin (diff) | |
download | yuzu-b9f1f70688e6a37fc3ad558586fabbf522cb892e.tar yuzu-b9f1f70688e6a37fc3ad558586fabbf522cb892e.tar.gz yuzu-b9f1f70688e6a37fc3ad558586fabbf522cb892e.tar.bz2 yuzu-b9f1f70688e6a37fc3ad558586fabbf522cb892e.tar.lz yuzu-b9f1f70688e6a37fc3ad558586fabbf522cb892e.tar.xz yuzu-b9f1f70688e6a37fc3ad558586fabbf522cb892e.tar.zst yuzu-b9f1f70688e6a37fc3ad558586fabbf522cb892e.zip |
Diffstat (limited to 'src')
-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 @@ -package org.yuzu.yuzu_emu.utils; +package org.yuzu.yuzu_emu.utils -import android.view.InputDevice; -import android.view.KeyEvent; -import android.view.MotionEvent; +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 { +class ControllerMappingHelper { /** * Some controllers report extra button presses that can be ignored. */ - public boolean shouldKeyBeIgnored(InputDevice inputDevice, int keyCode) { - if (isDualShock4(inputDevice)) { + fun shouldKeyBeIgnored(inputDevice: InputDevice, keyCode: Int): Boolean { + return 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 - return keyCode == KeyEvent.KEYCODE_BUTTON_L2 || keyCode == KeyEvent.KEYCODE_BUTTON_R2; - } - return false; + keyCode == KeyEvent.KEYCODE_BUTTON_L2 || keyCode == KeyEvent.KEYCODE_BUTTON_R2 + } else false } /** * Scale an axis to be zero-centered with a proper range. */ - public float scaleAxis(InputDevice inputDevice, int axis, float value) { + fun scaleAxis(inputDevice: InputDevice, axis: Int, value: Float): Float { 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; + 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; + return (value + 1) / 2.0f } if (axis == MotionEvent.AXIS_GENERIC_1) { // This axis is stuck at ~.5. Ignore it. - return 0.0f; + return 0.0f } } else if (isMogaPro2Hid(inputDevice)) { // This controller has a broken axis that reports a constant value. Ignore it. if (axis == MotionEvent.AXIS_GENERIC_1) { - return 0.0f; + return 0.0f } } - return value; + return value } - private boolean isDualShock4(InputDevice inputDevice) { - // Sony DualShock 4 controller - return inputDevice.getVendorId() == 0x54c && inputDevice.getProductId() == 0x9cc; + // Sony DualShock 4 controller + private fun isDualShock4(inputDevice: InputDevice): Boolean { + return inputDevice.vendorId == 0x54c && inputDevice.productId == 0x9cc } - private boolean isXboxOneWireless(InputDevice inputDevice) { - // Microsoft Xbox One controller - return inputDevice.getVendorId() == 0x45e && inputDevice.getProductId() == 0x2e0; + // Microsoft Xbox One controller + private fun isXboxOneWireless(inputDevice: InputDevice): Boolean { + return inputDevice.vendorId == 0x45e && inputDevice.productId == 0x2e0 } - private boolean isMogaPro2Hid(InputDevice inputDevice) { - // Moga Pro 2 HID - return inputDevice.getVendorId() == 0x20d6 && inputDevice.getProductId() == 0x6271; + // Moga Pro 2 HID + private fun isMogaPro2Hid(inputDevice: InputDevice): Boolean { + return inputDevice.vendorId == 0x20d6 && inputDevice.productId == 0x6271 } } |