Browse Source

Merge pull request #6288 from nanthony21/fixJoystickActivation

Fix joystick activation
QGC4.4
Don Gagne 7 years ago committed by GitHub
parent
commit
3fae664487
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 12
      src/Joystick/Joystick.cc
  2. 4
      src/Joystick/Joystick.h
  3. 7
      src/Vehicle/Vehicle.cc
  4. 11
      src/VehicleSetup/JoystickConfig.qml

12
src/Joystick/Joystick.cc

@ -445,7 +445,7 @@ void Joystick::run(void) @@ -445,7 +445,7 @@ void Joystick::run(void)
}
}
if (_outputEnabled && _calibrated) {
if (_activeVehicle->joystickEnabled() && !_calibrationMode && _calibrated) {
int axis = _rgFunctionAxis[rollFunction];
float roll = _adjustRange(_rgAxisValues[axis], _rgCalibration[axis], _deadband);
@ -798,18 +798,8 @@ void Joystick::setCalibrationMode(bool calibrating) @@ -798,18 +798,8 @@ void Joystick::setCalibrationMode(bool calibrating)
else 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)
{

4
src/Joystick/Joystick.h

@ -61,7 +61,6 @@ public: @@ -61,7 +61,6 @@ 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)
@ -129,11 +128,9 @@ public: @@ -129,11 +128,9 @@ public:
/// Set the current calibration 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);
@ -202,7 +199,6 @@ protected: @@ -202,7 +199,6 @@ protected:
static int _transmitterMode;
bool _calibrationMode;
bool _outputEnabled;
int* _rgAxisValues;
Calibration_t* _rgCalibration;

7
src/Vehicle/Vehicle.cc

@ -1823,6 +1823,7 @@ void Vehicle::_loadSettings(void) @@ -1823,6 +1823,7 @@ void Vehicle::_loadSettings(void)
// Joystick enabled is a global setting so first make sure there are any joysticks connected
if (_toolbox->joystickManager()->joysticks().count()) {
setJoystickEnabled(settings.value(_joystickEnabledSettingsKey, false).toBool());
_startJoystick(true);
}
}
@ -1875,7 +1876,6 @@ bool Vehicle::joystickEnabled(void) @@ -1875,7 +1876,6 @@ bool Vehicle::joystickEnabled(void)
void Vehicle::setJoystickEnabled(bool enabled)
{
_joystickEnabled = enabled;
_startJoystick(_joystickEnabled);
_saveSettings();
emit joystickEnabledChanged(_joystickEnabled);
}
@ -1885,9 +1885,7 @@ void Vehicle::_startJoystick(bool start) @@ -1885,9 +1885,7 @@ void Vehicle::_startJoystick(bool start)
Joystick* joystick = _joystickManager->activeJoystick();
if (joystick) {
if (start) {
if (_joystickEnabled) {
joystick->startPolling(this);
}
joystick->startPolling(this);
} else {
joystick->stopPolling();
}
@ -1903,6 +1901,7 @@ void Vehicle::setActive(bool active) @@ -1903,6 +1901,7 @@ void Vehicle::setActive(bool active)
{
if (_active != active) {
_active = active;
_startJoystick(false);
emit activeChanged(_active);
}
}

11
src/VehicleSetup/JoystickConfig.qml

@ -366,13 +366,14 @@ SetupPage { @@ -366,13 +366,14 @@ SetupPage {
id: enabledCheckBox
enabled: _activeJoystick ? _activeJoystick.calibrated : false
text: _activeJoystick ? _activeJoystick.calibrated ? qsTr("Enable joystick input") : qsTr("Enable not allowed (Calibrate First)") : ""
onClicked: _activeJoystick.outputEnabled = checked
onClicked: _activeVehicle.joystickEnabled = checked
Component.onCompleted: checked = _activeVehicle.joystickEnabled
Connections {
target: _activeJoystick
onOutputEnabledChanged: {
enabledCheckBox.checked=enabled
target: _activeVehicle
onJoystickEnabledChanged: {
enabledCheckBox.checked = _activeVehicle.joystickEnabled
}
}

Loading…
Cancel
Save