Commit c8e0d3b5 authored by Lorenz Meier's avatar Lorenz Meier

Merge pull request #2257 from mavlink/joystick_fix

Joystick fix: Enable joystick right after calibration & do not send anything to vehicle if not configured
parents 5be2eb53 6efac729
...@@ -367,27 +367,30 @@ void Joystick::run(void) ...@@ -367,27 +367,30 @@ void Joystick::run(void)
void Joystick::startPolling(Vehicle* vehicle) void Joystick::startPolling(Vehicle* vehicle)
{ {
if (isRunning()) { if (vehicle) {
if (vehicle != _activeVehicle) {
// Joystick was previously disabled, but now enabled from config screen // If a vehicle is connected, disconnect it
if (_activeVehicle) {
if (_calibrationMode == CalibrationModeOff) { UAS* uas = _activeVehicle->uas();
qWarning() << "Incorrect usage pattern"; disconnect(this, &Joystick::manualControl, uas, &UAS::setExternalControlSetpoint);
return;
}
_activeVehicle = vehicle;
_pollingStartedForCalibration = false;
} }
} else {
// Always set up the new vehicle
_activeVehicle = vehicle; _activeVehicle = vehicle;
UAS* uas = _activeVehicle->uas(); // Only connect the new vehicle if it wants joystick data
if (vehicle->joystickEnabled()) {
connect(this, &Joystick::manualControl, uas, &UAS::setExternalControlSetpoint); _pollingStartedForCalibration = false;
// FIXME: ****
//connect(this, &Joystick::buttonActionTriggered, uas, &UAS::triggerAction); UAS* uas = _activeVehicle->uas();
connect(this, &Joystick::manualControl, uas, &UAS::setExternalControlSetpoint);
// FIXME: ****
//connect(this, &Joystick::buttonActionTriggered, uas, &UAS::triggerAction);
}
}
if (!isRunning()) {
_exitThread = false; _exitThread = false;
start(); start();
} }
...@@ -396,9 +399,12 @@ void Joystick::startPolling(Vehicle* vehicle) ...@@ -396,9 +399,12 @@ void Joystick::startPolling(Vehicle* vehicle)
void Joystick::stopPolling(void) void Joystick::stopPolling(void)
{ {
if (isRunning()) { if (isRunning()) {
UAS* uas = _activeVehicle->uas();
if (_activeVehicle && _activeVehicle->joystickEnabled()) {
disconnect(this, &Joystick::manualControl, uas, &UAS::setExternalControlSetpoint); UAS* uas = _activeVehicle->uas();
disconnect(this, &Joystick::manualControl, uas, &UAS::setExternalControlSetpoint);
}
// FIXME: **** // FIXME: ****
//disconnect(this, &Joystick::buttonActionTriggered, uas, &UAS::triggerAction); //disconnect(this, &Joystick::buttonActionTriggered, uas, &UAS::triggerAction);
...@@ -544,6 +550,10 @@ void Joystick::stopCalibrationMode(CalibrationMode_t mode) ...@@ -544,6 +550,10 @@ void Joystick::stopCalibrationMode(CalibrationMode_t mode)
void Joystick::_buttonAction(const QString& action) void Joystick::_buttonAction(const QString& action)
{ {
if (!_activeVehicle || !_activeVehicle->joystickEnabled()) {
return;
}
if (action == "Arm") { if (action == "Arm") {
_activeVehicle->setArmed(true); _activeVehicle->setArmed(true);
} else if (action == "Disarm") { } else if (action == "Disarm") {
......
...@@ -838,6 +838,7 @@ void Vehicle::setJoystickEnabled(bool enabled) ...@@ -838,6 +838,7 @@ void Vehicle::setJoystickEnabled(bool enabled)
_joystickEnabled = enabled; _joystickEnabled = enabled;
_startJoystick(_joystickEnabled); _startJoystick(_joystickEnabled);
_saveSettings(); _saveSettings();
emit joystickEnabledChanged(_joystickEnabled);
} }
void Vehicle::_startJoystick(bool start) void Vehicle::_startJoystick(bool start)
......
...@@ -355,12 +355,10 @@ QGCView { ...@@ -355,12 +355,10 @@ QGCView {
QGCCheckBox { QGCCheckBox {
enabled: allowEnableDisable enabled: _activeJoystick.calibrated
text: _activeJoystick.calibrated ? "Enable joystick input" : "Enable/Disable not allowed (Calibrate First)" text: _activeJoystick.calibrated ? "Enable joystick input" : "Enable/Disable not allowed (Calibrate First)"
checked: _activeVehicle.joystickEnabled checked: _activeVehicle.joystickEnabled
property bool allowEnableDisable: _activeJoystick.calibrated
onClicked: _activeVehicle.joystickEnabled = checked onClicked: _activeVehicle.joystickEnabled = checked
} }
......
...@@ -99,7 +99,7 @@ const JoystickConfigController::stateMachineEntry* JoystickConfigController::_ge ...@@ -99,7 +99,7 @@ const JoystickConfigController::stateMachineEntry* JoystickConfigController::_ge
static const char* msgPitchDown = "Move the Pitch stick all the way down and hold it there..."; static const char* msgPitchDown = "Move the Pitch stick all the way down and hold it there...";
static const char* msgPitchUp = "Move the Pitch stick all the way up and hold it there..."; static const char* msgPitchUp = "Move the Pitch stick all the way up and hold it there...";
static const char* msgPitchCenter = "Allow the Pitch stick to move back to center..."; static const char* msgPitchCenter = "Allow the Pitch stick to move back to center...";
static const char* msgComplete = "All settings have been captured. Click Next to Save."; static const char* msgComplete = "All settings have been captured. Click Next to enable the joystick.";
static const stateMachineEntry rgStateMachine[] = { static const stateMachineEntry rgStateMachine[] = {
//Function //Function
...@@ -564,6 +564,11 @@ void JoystickConfigController::_writeCalibration(void) ...@@ -564,6 +564,11 @@ void JoystickConfigController::_writeCalibration(void)
_stopCalibration(); _stopCalibration();
_setInternalCalibrationValuesFromSettings(); _setInternalCalibrationValuesFromSettings();
Vehicle* vehicle = qgcApp()->toolbox()->multiVehicleManager()->activeVehicle();
if (vehicle) {
vehicle->setJoystickEnabled(true);
}
} }
/// @brief Starts the calibration process /// @brief Starts the calibration process
......
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