diff --git a/src/Joystick/Joystick.cc b/src/Joystick/Joystick.cc index c5df9fe70433016af9e29b2763256ec02b7099fb..5dbdcb03297aa6ec08c6d427276892b24d876756 100644 --- a/src/Joystick/Joystick.cc +++ b/src/Joystick/Joystick.cc @@ -334,7 +334,7 @@ void Joystick::run(void) _lastButtonBits = newButtonBits; - qCDebug(JoystickValuesLog) << "roll:pitch:yaw:throttle" << roll << -pitch << yaw << throttle; + qCDebug(JoystickValuesLog) << "name:roll:pitch:yaw:throttle" << name() << roll << -pitch << yaw << throttle; emit manualControl(roll, -pitch, yaw, throttle, buttonPressedBits, _activeVehicle->joystickMode()); } diff --git a/src/VehicleSetup/JoystickConfig.qml b/src/VehicleSetup/JoystickConfig.qml index 7b9cdba0f49d10b42bf868f2e7129ee2b1c85799..80cfd128c286ae188ba3bc9b144ebbcd50035490 100644 --- a/src/VehicleSetup/JoystickConfig.qml +++ b/src/VehicleSetup/JoystickConfig.qml @@ -381,7 +381,16 @@ QGCView { width: parent.width - activeJoystickLabel.width - parent.spacing model: joystickManager.joystickNames - onActivated: _activeJoystick.setActiveJoystickName(textAt(index)) + onActivated: joystickManager.activeJoystickName = textAt(index) + + Component.onCompleted: { + var index = joystickCombo.find(joystickManager.activeJoystickName) + if (index == -1) { + console.warn("Active joystick name not in combo", joystickManager.activeJoystickName) + } else { + joystickCombo.currentIndex = index + } + } } } diff --git a/src/VehicleSetup/JoystickConfigController.cc b/src/VehicleSetup/JoystickConfigController.cc index 2a3a66c1b3c6155d0592e1697f816309f5e8f687..0f4a9df6d476d1239a9c0fbdd796afcb066067de 100644 --- a/src/VehicleSetup/JoystickConfigController.cc +++ b/src/VehicleSetup/JoystickConfigController.cc @@ -54,8 +54,6 @@ const char* JoystickConfigController::_imageRollRight = "joystickRollRight.p const char* JoystickConfigController::_imagePitchUp = "joystickPitchUp.png"; const char* JoystickConfigController::_imagePitchDown = "joystickPitchDown.png"; -const char* JoystickConfigController::_settingsGroup = "Joysticks"; - JoystickConfigController::JoystickConfigController(void) : _activeJoystick(NULL) , _currentStep(-1) @@ -71,21 +69,17 @@ JoystickConfigController::JoystickConfigController(void) connect(joystickManager, &JoystickManager::activeJoystickChanged, this, &JoystickConfigController::_activeJoystickChanged); _activeJoystickChanged(joystickManager->activeJoystick()); - _loadSettings(); _resetInternalCalibrationValues(); - _activeJoystick->startCalibrationMode(Joystick::CalibrationModeMonitor); } void JoystickConfigController::start(void) { _stopCalibration(); - _setInternalCalibrationValuesFromSettings(); } JoystickConfigController::~JoystickConfigController() { _activeJoystick->stopCalibrationMode(Joystick::CalibrationModeMonitor); - _storeSettings(); } /// @brief Returns the state machine entry for the specified state. @@ -460,7 +454,7 @@ void JoystickConfigController::_setInternalCalibrationValuesFromSettings(void) info->axisMax = calibration.max; info->reversed = calibration.reversed; - qCDebug(JoystickConfigControllerLog) << "Read settings axis:min:max:trim:reversed" << axis << info->axisMin << info->axisMax << info->axisTrim << info->reversed; + qCDebug(JoystickConfigControllerLog) << "Read settings name:axis:min:max:trim:reversed" << joystick->name() << axis << info->axisMin << info->axisMax << info->axisTrim << info->reversed; } for (int function=0; functionaxisMin > _calValidMinValue || info->axisMax < _calValidMaxValue) { + if (info->axisMin < _calValidMinValue || info->axisMax > _calValidMaxValue) { qCDebug(JoystickConfigControllerLog) << "_validateCalibration resetting axis" << chan; info->axisMin = _calDefaultMinValue; info->axisMax = _calDefaultMaxValue; info->axisTrim = info->axisMin + ((info->axisMax - info->axisMin) / 2); - } else { - switch (_rgAxisInfo[chan].function) { - case Joystick::throttleFunction: - case Joystick::yawFunction: - case Joystick::rollFunction: - case Joystick::pitchFunction: - // Make sure trim is within min/max - if (info->axisTrim < info->axisMin) { - info->axisTrim = info->axisMin; - } else if (info->axisTrim > info->axisMax) { - info->axisTrim = info->axisMax; - } - break; - default: - // Non-attitude control axiss have calculated trim - info->axisTrim = info->axisMin + ((info->axisMax - info->axisMin) / 2); - break; - } - + } + + switch (_rgAxisInfo[chan].function) { + case Joystick::throttleFunction: + case Joystick::yawFunction: + case Joystick::rollFunction: + case Joystick::pitchFunction: + // Make sure trim is within min/max + if (info->axisTrim < info->axisMin) { + info->axisTrim = info->axisMin; + } else if (info->axisTrim > info->axisMax) { + info->axisTrim = info->axisMax; + } + break; + default: + // Non-attitude control axis have calculated trim + info->axisTrim = info->axisMin + ((info->axisMax - info->axisMin) / 2); + break; } } else { // Unavailable axiss are set to defaults @@ -610,20 +603,6 @@ void JoystickConfigController::_calSave(void) _validateCalibration(); } -void JoystickConfigController::_loadSettings(void) -{ - QSettings settings; - - settings.beginGroup(_settingsGroup); -} - -void JoystickConfigController::_storeSettings(void) -{ - QSettings settings; - - settings.beginGroup(_settingsGroup); -} - void JoystickConfigController::_setHelpImage(const char* imageFile) { QString file = _imageFilePrefix; @@ -749,13 +728,20 @@ void JoystickConfigController::_signalAllAttiudeValueChanges(void) void JoystickConfigController::_activeJoystickChanged(Joystick* joystick) { + bool joystickTransition = false; + if (_activeJoystick) { + joystickTransition = true; disconnect(_activeJoystick, &Joystick::rawAxisValueChanged, this, &JoystickConfigController::_axisValueChanged); _activeJoystick = NULL; } if (joystick) { _activeJoystick = joystick; + if (joystickTransition) { + _stopCalibration(); + } + _activeJoystick->startCalibrationMode(Joystick::CalibrationModeMonitor); connect(_activeJoystick, &Joystick::rawAxisValueChanged, this, &JoystickConfigController::_axisValueChanged); } } diff --git a/src/VehicleSetup/JoystickConfigController.h b/src/VehicleSetup/JoystickConfigController.h index 41f2aca3ca53079a59933b7c4b136ede7e5224f5..030fb363a8a923c5b9172b6a9941396c1d27c7cb 100644 --- a/src/VehicleSetup/JoystickConfigController.h +++ b/src/VehicleSetup/JoystickConfigController.h @@ -197,9 +197,6 @@ private: void _setHelpImage(const char* imageFile); - void _loadSettings(void); - void _storeSettings(void); - void _signalAllAttiudeValueChanges(void); // Member variables @@ -216,8 +213,6 @@ private: static const char* _imagePitchUp; static const char* _imagePitchDown; - static const char* _settingsGroup; - static const int _updateInterval; ///< Interval for ui update timer int _rgFunctionAxisMapping[Joystick::maxFunction]; ///< Maps from joystick function to axis index. _axisMax indicates axis not set for this function.