Browse Source

Merge pull request #7081 from mavlink/androidJoystick

Some Android joysticks have axis mapped to multiple channels.
QGC4.4
Gus Grubba 7 years ago committed by GitHub
parent
commit
351cff6d3f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 12
      src/Joystick/JoystickAndroid.cc

12
src/Joystick/JoystickAndroid.cc

@ -39,17 +39,23 @@ JoystickAndroid::JoystickAndroid(const QString& name, int axisCount, int buttonC
env->ReleaseBooleanArrayElements(jSupportedButtons, supportedButtons, 0); env->ReleaseBooleanArrayElements(jSupportedButtons, supportedButtons, 0);
//set axis mapping (number->code) // set axis mapping (number->code)
axisValue = new int[_axisCount]; axisValue = new int[_axisCount];
axisCode = new int[_axisCount]; axisCode = new int[_axisCount];
QAndroidJniObject rangeListNative = inputDevice.callObjectMethod("getMotionRanges", "()Ljava/util/List;"); 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); QAndroidJniObject range = rangeListNative.callObjectMethod("get", "(I)Ljava/lang/Object;",i);
axisCode[i] = range.callMethod<jint>("getAxis"); axisCode[i] = range.callMethod<jint>("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; axisValue[i] = 0;
} }
qCDebug(JoystickLog) << "axis:" <<_axisCount << "buttons:" <<_buttonCount; qCDebug(JoystickLog) << "axis:" <<_axisCount << "buttons:" <<_buttonCount;
QtAndroidPrivate::registerGenericMotionEventListener(this); QtAndroidPrivate::registerGenericMotionEventListener(this);
QtAndroidPrivate::registerKeyEventListener(this); QtAndroidPrivate::registerKeyEventListener(this);

Loading…
Cancel
Save