Commit 3051ab71 authored by Pierre Kancir's avatar Pierre Kancir Committed by khancyr

Joystick: add a button to support negative thrust

parent 54780e15
...@@ -55,6 +55,7 @@ Joystick::Joystick(const QString& name, int axisCount, int buttonCount, int hatC ...@@ -55,6 +55,7 @@ Joystick::Joystick(const QString& name, int axisCount, int buttonCount, int hatC
, _rgButtonValues(NULL) , _rgButtonValues(NULL)
, _lastButtonBits(0) , _lastButtonBits(0)
, _throttleMode(ThrottleModeCenterZero) , _throttleMode(ThrottleModeCenterZero)
, _negativeThrust(false)
, _exponential(0) , _exponential(0)
, _accumulator(false) , _accumulator(false)
, _deadband(false) , _deadband(false)
...@@ -462,7 +463,9 @@ void Joystick::run(void) ...@@ -462,7 +463,9 @@ void Joystick::run(void)
// Adjust throttle to 0:1 range // Adjust throttle to 0:1 range
if (_throttleMode == ThrottleModeCenterZero && _activeVehicle->supportsThrottleModeCenterZero()) { if (_throttleMode == ThrottleModeCenterZero && _activeVehicle->supportsThrottleModeCenterZero()) {
throttle = std::max(0.0f, throttle); if (!_negativeThrust) {
throttle = std::max(0.0f, throttle);
}
} else { } else {
throttle = (throttle + 1.0f) / 2.0f; throttle = (throttle + 1.0f) / 2.0f;
} }
...@@ -687,6 +690,22 @@ void Joystick::setThrottleMode(int mode) ...@@ -687,6 +690,22 @@ void Joystick::setThrottleMode(int mode)
emit throttleModeChanged(_throttleMode); 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) float Joystick::exponential(void)
{ {
return _exponential; return _exponential;
......
...@@ -72,6 +72,7 @@ public: ...@@ -72,6 +72,7 @@ public:
Q_INVOKABLE QString getButtonAction(int button); Q_INVOKABLE QString getButtonAction(int button);
Q_PROPERTY(int throttleMode READ throttleMode WRITE setThrottleMode NOTIFY throttleModeChanged) 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(float exponential READ exponential WRITE setExponential NOTIFY exponentialChanged)
Q_PROPERTY(bool accumulator READ accumulator WRITE setAccumulator NOTIFY accumulatorChanged) Q_PROPERTY(bool accumulator READ accumulator WRITE setAccumulator NOTIFY accumulatorChanged)
Q_PROPERTY(bool requiresCalibration READ requiresCalibration CONSTANT) Q_PROPERTY(bool requiresCalibration READ requiresCalibration CONSTANT)
...@@ -106,6 +107,9 @@ public: ...@@ -106,6 +107,9 @@ public:
int throttleMode(void); int throttleMode(void);
void setThrottleMode(int mode); void setThrottleMode(int mode);
bool negativeThrust(void);
void setNegativeThrust(bool allowNegative);
float exponential(void); float exponential(void);
void setExponential(float expo); void setExponential(float expo);
...@@ -141,6 +145,8 @@ signals: ...@@ -141,6 +145,8 @@ signals:
void throttleModeChanged(int mode); void throttleModeChanged(int mode);
void negativeThrustChanged(bool allowNegative);
void exponentialChanged(float exponential); void exponentialChanged(float exponential);
void accumulatorChanged(bool accumulator); void accumulatorChanged(bool accumulator);
...@@ -206,6 +212,8 @@ protected: ...@@ -206,6 +212,8 @@ protected:
ThrottleMode_t _throttleMode; ThrottleMode_t _throttleMode;
bool _negativeThrust;
float _exponential; float _exponential;
bool _accumulator; bool _accumulator;
bool _deadband; bool _deadband;
......
...@@ -453,6 +453,14 @@ SetupPage { ...@@ -453,6 +453,14 @@ SetupPage {
onClicked: _activeJoystick.throttleMode = 1 onClicked: _activeJoystick.throttleMode = 1
} }
QGCCheckBox {
id: negativeThrust
text: qsTr("Allow negative Thrust")
checked: _activeJoystick ? _activeJoystick.negativeThrust : false
onClicked: _activeJoystick.negativeThrust = checked
}
} }
Column { Column {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment