From 3bcc1c84bb46094f9262666c8deeba635f69a5f0 Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Wed, 16 Oct 2019 19:02:51 -0700 Subject: [PATCH] Fix crash on controllers with RX and RY but no Z and RZ axes --- .../com/limelight/binding/input/ControllerHandler.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/limelight/binding/input/ControllerHandler.java b/app/src/main/java/com/limelight/binding/input/ControllerHandler.java index ed13f092..9081f5c4 100644 --- a/app/src/main/java/com/limelight/binding/input/ControllerHandler.java +++ b/app/src/main/java/com/limelight/binding/input/ControllerHandler.java @@ -502,8 +502,14 @@ public class ControllerHandler implements InputManager.InputDeviceListener, UsbD // other sane controller that uses RX and RY for right stick and Z and RZ for triggers. context.rightStickXAxis = MotionEvent.AXIS_RX; context.rightStickYAxis = MotionEvent.AXIS_RY; - context.leftTriggerAxis = MotionEvent.AXIS_Z; - context.rightTriggerAxis = MotionEvent.AXIS_RZ; + + // While it's likely that Z and RZ are triggers, we may have digital trigger buttons + // instead. We must check that we actually have Z and RZ axes before assigning them. + if (getMotionRangeForJoystickAxis(dev, MotionEvent.AXIS_Z) != null && + getMotionRangeForJoystickAxis(dev, MotionEvent.AXIS_RZ) != null) { + context.leftTriggerAxis = MotionEvent.AXIS_Z; + context.rightTriggerAxis = MotionEvent.AXIS_RZ; + } } // Triggers always idle negative on axes that are centered at zero