From b255b841cfb8b7b834e2f86b563050b58fc6581d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Fran=C4=8De=C5=A1kin?= Date: Sat, 8 Dec 2018 17:40:14 +0100 Subject: [PATCH] Bugfix: Android joystick had two axis mapped on the same button --- src/Joystick/JoystickAndroid.cc | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/Joystick/JoystickAndroid.cc b/src/Joystick/JoystickAndroid.cc index b96582032..7ec59a477 100644 --- a/src/Joystick/JoystickAndroid.cc +++ b/src/Joystick/JoystickAndroid.cc @@ -39,17 +39,23 @@ JoystickAndroid::JoystickAndroid(const QString& name, int axisCount, int buttonC env->ReleaseBooleanArrayElements(jSupportedButtons, supportedButtons, 0); - //set axis mapping (number->code) + // set axis mapping (number->code) axisValue = new int[_axisCount]; axisCode = new int[_axisCount]; QAndroidJniObject rangeListNative = inputDevice.callObjectMethod("getMotionRanges", "()Ljava/util/List;"); - for (i=0;i<_axisCount;i++) { + for (i = 0; i < _axisCount; i++) { QAndroidJniObject range = rangeListNative.callObjectMethod("get", "(I)Ljava/lang/Object;",i); axisCode[i] = range.callMethod("getAxis"); + // Don't allow two axis with the same code + for (int j = 0; j < i; j++) { + if (axisCode[i] == axisCode[j]) { + axisCode[i] = -1; + break; + } + } axisValue[i] = 0; } - qCDebug(JoystickLog) << "axis:" <<_axisCount << "buttons:" <<_buttonCount; QtAndroidPrivate::registerGenericMotionEventListener(this); QtAndroidPrivate::registerKeyEventListener(this); -- 2.22.0