From 3051ab71b2547956a7fab76b8a1ff27f860262ed Mon Sep 17 00:00:00 2001 From: Pierre Kancir Date: Tue, 23 May 2017 17:44:05 +0200 Subject: [PATCH] Joystick: add a button to support negative thrust --- src/Joystick/Joystick.cc | 21 ++++++++++++++++++++- src/Joystick/Joystick.h | 8 ++++++++ src/VehicleSetup/JoystickConfig.qml | 8 ++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/src/Joystick/Joystick.cc b/src/Joystick/Joystick.cc index b1c00e2d8..356ed2fa1 100644 --- a/src/Joystick/Joystick.cc +++ b/src/Joystick/Joystick.cc @@ -55,6 +55,7 @@ Joystick::Joystick(const QString& name, int axisCount, int buttonCount, int hatC , _rgButtonValues(NULL) , _lastButtonBits(0) , _throttleMode(ThrottleModeCenterZero) + , _negativeThrust(false) , _exponential(0) , _accumulator(false) , _deadband(false) @@ -462,7 +463,9 @@ void Joystick::run(void) // Adjust throttle to 0:1 range if (_throttleMode == ThrottleModeCenterZero && _activeVehicle->supportsThrottleModeCenterZero()) { - throttle = std::max(0.0f, throttle); + if (!_negativeThrust) { + throttle = std::max(0.0f, throttle); + } } else { throttle = (throttle + 1.0f) / 2.0f; } @@ -687,6 +690,22 @@ void Joystick::setThrottleMode(int mode) emit throttleModeChanged(_throttleMode); } +bool Joystick::negativeThrust(void) +{ + return _negativeThrust; +} + +void Joystick::setNegativeThrust(bool allowNegative) +{ + if (_negativeThrust == allowNegative) { + return; + } + _negativeThrust = allowNegative; + + _saveSettings(); + emit negativeThrustChanged(_negativeThrust); +} + float Joystick::exponential(void) { return _exponential; diff --git a/src/Joystick/Joystick.h b/src/Joystick/Joystick.h index 2e98c3f8f..89717f715 100644 --- a/src/Joystick/Joystick.h +++ b/src/Joystick/Joystick.h @@ -72,6 +72,7 @@ public: Q_INVOKABLE QString getButtonAction(int button); Q_PROPERTY(int throttleMode READ throttleMode WRITE setThrottleMode NOTIFY throttleModeChanged) + Q_PROPERTY(bool negativeThrust READ negativeThrust WRITE setNegativeThrust NOTIFY negativeThrustChanged) Q_PROPERTY(float exponential READ exponential WRITE setExponential NOTIFY exponentialChanged) Q_PROPERTY(bool accumulator READ accumulator WRITE setAccumulator NOTIFY accumulatorChanged) Q_PROPERTY(bool requiresCalibration READ requiresCalibration CONSTANT) @@ -106,6 +107,9 @@ public: int throttleMode(void); void setThrottleMode(int mode); + bool negativeThrust(void); + void setNegativeThrust(bool allowNegative); + float exponential(void); void setExponential(float expo); @@ -141,6 +145,8 @@ signals: void throttleModeChanged(int mode); + void negativeThrustChanged(bool allowNegative); + void exponentialChanged(float exponential); void accumulatorChanged(bool accumulator); @@ -206,6 +212,8 @@ protected: ThrottleMode_t _throttleMode; + bool _negativeThrust; + float _exponential; bool _accumulator; bool _deadband; diff --git a/src/VehicleSetup/JoystickConfig.qml b/src/VehicleSetup/JoystickConfig.qml index 75c9c58f0..d893ec027 100644 --- a/src/VehicleSetup/JoystickConfig.qml +++ b/src/VehicleSetup/JoystickConfig.qml @@ -453,6 +453,14 @@ SetupPage { onClicked: _activeJoystick.throttleMode = 1 } + + QGCCheckBox { + id: negativeThrust + text: qsTr("Allow negative Thrust") + checked: _activeJoystick ? _activeJoystick.negativeThrust : false + + onClicked: _activeJoystick.negativeThrust = checked + } } Column { -- 2.22.0