From 02a8b5b1d0fc9551f319553bd4f36e7257fdfbf8 Mon Sep 17 00:00:00 2001 From: nanthony21 Date: Sat, 27 Jan 2018 00:30:34 -0600 Subject: [PATCH 1/2] Replaced tristate calibration mode with two boolean values. Joystick axes and buttons can now be monitored even when the joystick input is disabled. --- src/Joystick/Joystick.cc | 42 +++++++++++----------------- src/Joystick/Joystick.h | 17 ++++------- src/VehicleSetup/JoystickConfig.qml | 4 +-- src/VehicleSetup/JoystickConfigController.cc | 9 +++--- 4 files changed, 29 insertions(+), 43 deletions(-) diff --git a/src/Joystick/Joystick.cc b/src/Joystick/Joystick.cc index a7d4f73..04d51cc 100644 --- a/src/Joystick/Joystick.cc +++ b/src/Joystick/Joystick.cc @@ -49,7 +49,7 @@ Joystick::Joystick(const QString& name, int axisCount, int buttonCount, int hatC , _hatCount(hatCount) , _hatButtonCount(4*hatCount) , _totalButtonCount(_buttonCount+_hatButtonCount) - , _calibrationMode(CalibrationModeOff) + , _calibrationMode(false) , _rgAxisValues(NULL) , _rgCalibration(NULL) , _rgButtonValues(NULL) @@ -431,7 +431,7 @@ void Joystick::run(void) } } - if (_calibrationMode != CalibrationModeCalibrating && _calibrated) { + if (_outputEnabled && _calibrated) { int axis = _rgFunctionAxis[rollFunction]; float roll = _adjustRange(_rgAxisValues[axis], _rgCalibration[axis], _deadband); @@ -757,36 +757,28 @@ void Joystick::setDeadband(bool deadband) _saveSettings(); } -void Joystick::startCalibrationMode(CalibrationMode_t mode) +void Joystick::setCalibrationMode(bool calibrating) { - if (mode == CalibrationModeOff) { - qWarning() << "Incorrect mode CalibrationModeOff"; - return; - } + _calibrationMode = calibrating; - _calibrationMode = mode; - - if (!isRunning()) { + if (calibrating && !isRunning()) { _pollingStartedForCalibration = true; startPolling(_multiVehicleManager->activeVehicle()); } -} - -void Joystick::stopCalibrationMode(CalibrationMode_t mode) -{ - if (mode == CalibrationModeOff) { - qWarning() << "Incorrect mode: CalibrationModeOff"; - return; + else if (_pollingStartedForCalibration) { + stopPolling(); } - - if (mode == CalibrationModeCalibrating) { - _calibrationMode = CalibrationModeMonitor; - } else { - _calibrationMode = CalibrationModeOff; - if (_pollingStartedForCalibration) { - stopPolling(); - } + if (calibrating){ + setOutputEnabled(false); //Disable the joystick output before calibrating } + else if (!calibrating && _calibrated){ + setOutputEnabled(true); //Enable joystick output after calibration + } +} + +void Joystick::setOutputEnabled(bool enabled){ + _outputEnabled = enabled; + emit outputEnabledChanged(_outputEnabled); } void Joystick::_buttonAction(const QString& action) diff --git a/src/Joystick/Joystick.h b/src/Joystick/Joystick.h index d6f15ed..f90b816 100644 --- a/src/Joystick/Joystick.h +++ b/src/Joystick/Joystick.h @@ -61,6 +61,7 @@ public: Q_PROPERTY(QString name READ name CONSTANT) Q_PROPERTY(bool calibrated MEMBER _calibrated NOTIFY calibratedChanged) + Q_PROPERTY(bool outputEnabled MEMBER _outputEnabled WRITE setOutputEnabled NOTIFY outputEnabledChanged) Q_PROPERTY(int totalButtonCount READ totalButtonCount CONSTANT) Q_PROPERTY(int axisCount READ axisCount CONSTANT) @@ -122,20 +123,13 @@ public: void setTXMode(int mode); int getTXMode(void) { return _transmitterMode; } - typedef enum { - CalibrationModeOff, // Not calibrating - CalibrationModeMonitor, // Monitors are active, continue to send to vehicle if already polling - CalibrationModeCalibrating, // Calibrating, stop sending joystick to vehicle - } CalibrationMode_t; - /// Set the current calibration mode - void startCalibrationMode(CalibrationMode_t mode); - - /// Clear the current calibration mode - void stopCalibrationMode(CalibrationMode_t mode); + void setCalibrationMode(bool calibrating); + void setOutputEnabled(bool enabled); signals: void calibratedChanged(bool calibrated); + void outputEnabledChanged(bool enabled); // The raw signals are only meant for use by calibration void rawAxisValueChanged(int index, int value); @@ -201,7 +195,8 @@ protected: int _totalButtonCount; static int _transmitterMode; - CalibrationMode_t _calibrationMode; + bool _calibrationMode; + bool _outputEnabled; int* _rgAxisValues; Calibration_t* _rgCalibration; diff --git a/src/VehicleSetup/JoystickConfig.qml b/src/VehicleSetup/JoystickConfig.qml index c4bc843..3826d94 100644 --- a/src/VehicleSetup/JoystickConfig.qml +++ b/src/VehicleSetup/JoystickConfig.qml @@ -366,9 +366,9 @@ SetupPage { id: enabledCheckBox enabled: _activeJoystick ? _activeJoystick.calibrated : false text: _activeJoystick ? _activeJoystick.calibrated ? qsTr("Enable joystick input") : qsTr("Enable not allowed (Calibrate First)") : "" - checked: _activeVehicle.joystickEnabled + checked: _activeJoystick.outputEnabled - onClicked: _activeVehicle.joystickEnabled = checked + onClicked: _activeJoystick.outputEnabled = checked Connections { target: joystickManager diff --git a/src/VehicleSetup/JoystickConfigController.cc b/src/VehicleSetup/JoystickConfigController.cc index 8b4f0b6..3ee4119 100644 --- a/src/VehicleSetup/JoystickConfigController.cc +++ b/src/VehicleSetup/JoystickConfigController.cc @@ -82,7 +82,7 @@ void JoystickConfigController::setDeadbandValue(int axis, int value) JoystickConfigController::~JoystickConfigController() { if(_activeJoystick) { - _activeJoystick->stopCalibrationMode(Joystick::CalibrationModeMonitor); + _activeJoystick->setCalibrationMode(false); } } @@ -582,7 +582,7 @@ void JoystickConfigController::_writeCalibration(void) /// @brief Starts the calibration process void JoystickConfigController::_startCalibration(void) { - _activeJoystick->startCalibrationMode(Joystick::CalibrationModeCalibrating); + _activeJoystick->setCalibrationMode(true); _resetInternalCalibrationValues(); _nextButton->setProperty("text", "Next"); @@ -598,7 +598,7 @@ void JoystickConfigController::_stopCalibration(void) { _currentStep = -1; - _activeJoystick->stopCalibrationMode(Joystick::CalibrationModeCalibrating); + _activeJoystick->setCalibrationMode(false); _setInternalCalibrationValuesFromSettings(); _statusText->setProperty("text", ""); @@ -763,7 +763,6 @@ void JoystickConfigController::_signalAllAttitudeValueChanges(void) void JoystickConfigController::_activeJoystickChanged(Joystick* joystick) { bool joystickTransition = false; - if (_activeJoystick) { joystickTransition = true; disconnect(_activeJoystick, &Joystick::rawAxisValueChanged, this, &JoystickConfigController::_axisValueChanged); @@ -781,7 +780,7 @@ void JoystickConfigController::_activeJoystickChanged(Joystick* joystick) if (joystickTransition) { _stopCalibration(); } - _activeJoystick->startCalibrationMode(Joystick::CalibrationModeMonitor); + _activeJoystick->setCalibrationMode(false); _axisCount = _activeJoystick->axisCount(); _rgAxisInfo = new struct AxisInfo[_axisCount]; _axisValueSave = new int[_axisCount]; From 27f61a757777b775d007565d4c53f177eb29702d Mon Sep 17 00:00:00 2001 From: Nick Anthony Date: Tue, 6 Feb 2018 13:24:58 -0600 Subject: [PATCH 2/2] Implemented workaround for bug with qml property binding. Now the state of the checkbox will always match up with the state of the outputEnabled. --- src/VehicleSetup/JoystickConfig.qml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/VehicleSetup/JoystickConfig.qml b/src/VehicleSetup/JoystickConfig.qml index 3826d94..df9a8d2 100644 --- a/src/VehicleSetup/JoystickConfig.qml +++ b/src/VehicleSetup/JoystickConfig.qml @@ -366,11 +366,17 @@ SetupPage { id: enabledCheckBox enabled: _activeJoystick ? _activeJoystick.calibrated : false text: _activeJoystick ? _activeJoystick.calibrated ? qsTr("Enable joystick input") : qsTr("Enable not allowed (Calibrate First)") : "" - checked: _activeJoystick.outputEnabled onClicked: _activeJoystick.outputEnabled = checked Connections { + target: _activeJoystick + onOutputEnabledChanged: { + enabledCheckBox.checked=enabled + } + } + + Connections { target: joystickManager onActiveJoystickChanged: {