From 94f84a56af61f97080c318ad7be3e2c7a8d44a8e Mon Sep 17 00:00:00 2001 From: DoinLakeFlyer Date: Thu, 2 Jan 2020 15:15:39 -0800 Subject: [PATCH] Allow plugin to add flight modes to joystick button actions --- src/FirmwarePlugin/FirmwarePlugin.h | 11 ++++++----- src/Joystick/Joystick.cc | 6 +++++- src/Vehicle/Vehicle.cc | 5 +++++ src/Vehicle/Vehicle.h | 10 ++++++---- 4 files changed, 22 insertions(+), 10 deletions(-) diff --git a/src/FirmwarePlugin/FirmwarePlugin.h b/src/FirmwarePlugin/FirmwarePlugin.h index 888ac2e09..8960968dd 100644 --- a/src/FirmwarePlugin/FirmwarePlugin.h +++ b/src/FirmwarePlugin/FirmwarePlugin.h @@ -81,12 +81,13 @@ public: /// free when no longer needed. virtual QList componentsForVehicle(AutoPilotPlugin* vehicle); - /// Returns the list of available flight modes. Flight modes can be different in normal/advanced ui mode. + /// Returns the list of available flight modes for the Fly View dropdown. This may or may not be the full + /// list available from the firmware. Call will be made again if advanced mode changes. + virtual QStringList flightModes(Vehicle* /*vehicle*/) { return QStringList(); } + + /// Returns the list of additional flight modes to add to the list for joystick button actions. /// Call will be made again if advanced mode changes. - virtual QStringList flightModes(Vehicle* vehicle) { - Q_UNUSED(vehicle); - return QStringList(); - } + virtual QStringList extraJoystickFlightModes(Vehicle* /*vehicle*/) { return QStringList(); } /// Returns the name for this flight mode. Flight mode names must be human readable as well as audio speakable. /// @param base_mode Base mode from mavlink HEARTBEAT message diff --git a/src/Joystick/Joystick.cc b/src/Joystick/Joystick.cc index bae1d221f..315beabbc 100644 --- a/src/Joystick/Joystick.cc +++ b/src/Joystick/Joystick.cc @@ -972,7 +972,7 @@ void Joystick::_executeButtonAction(const QString& action, bool buttonDown) if (buttonDown) emit setVtolInFwdFlight(true); } else if (action == _buttonActionVTOLMultiRotor) { if (buttonDown) emit setVtolInFwdFlight(false); - } else if (_activeVehicle->flightModes().contains(action)) { + } else if (_activeVehicle->flightModes().contains(action) || _activeVehicle->extraJoystickFlightModes().contains(action)) { if (buttonDown) emit setFlightMode(action); } else if(action == _buttonActionContinuousZoomIn || action == _buttonActionContinuousZoomOut) { if (buttonDown) { @@ -1072,6 +1072,10 @@ void Joystick::_buildActionList(Vehicle* activeVehicle) foreach(auto mode, list) { _assignableButtonActions.append(new AssignableButtonAction(this, mode)); } + list = activeVehicle->extraJoystickFlightModes(); + foreach(auto mode, list) { + _assignableButtonActions.append(new AssignableButtonAction(this, mode)); + } } _assignableButtonActions.append(new AssignableButtonAction(this, _buttonActionVTOLFixedWing)); _assignableButtonActions.append(new AssignableButtonAction(this, _buttonActionVTOLMultiRotor)); diff --git a/src/Vehicle/Vehicle.cc b/src/Vehicle/Vehicle.cc index 0a8a6db83..7d8a87f76 100644 --- a/src/Vehicle/Vehicle.cc +++ b/src/Vehicle/Vehicle.cc @@ -2375,6 +2375,11 @@ QStringList Vehicle::flightModes(void) return _firmwarePlugin->flightModes(this); } +QStringList Vehicle::extraJoystickFlightModes(void) +{ + return _firmwarePlugin->extraJoystickFlightModes(this); +} + QString Vehicle::flightMode(void) const { return _firmwarePlugin->flightMode(_base_mode, _custom_mode); diff --git a/src/Vehicle/Vehicle.h b/src/Vehicle/Vehicle.h index ed395f1bb..460aa434d 100644 --- a/src/Vehicle/Vehicle.h +++ b/src/Vehicle/Vehicle.h @@ -542,6 +542,7 @@ public: Q_PROPERTY(bool autoDisarm READ autoDisarm NOTIFY autoDisarmChanged) Q_PROPERTY(bool flightModeSetAvailable READ flightModeSetAvailable CONSTANT) Q_PROPERTY(QStringList flightModes READ flightModes NOTIFY flightModesChanged) + Q_PROPERTY(QStringList extraJoystickFlightModes READ extraJoystickFlightModes NOTIFY flightModesChanged) Q_PROPERTY(QString flightMode READ flightMode WRITE setFlightMode NOTIFY flightModeChanged) Q_PROPERTY(bool hilMode READ hilMode WRITE setHilMode NOTIFY hilModeChanged) Q_PROPERTY(TrajectoryPoints* trajectoryPoints MEMBER _trajectoryPoints CONSTANT) @@ -851,10 +852,11 @@ public: bool armed () { return _armed; } void setArmed (bool armed); - bool flightModeSetAvailable(void); - QStringList flightModes(void); - QString flightMode(void) const; - void setFlightMode(const QString& flightMode); + bool flightModeSetAvailable (void); + QStringList flightModes (void); + QStringList extraJoystickFlightModes (void); + QString flightMode (void) const; + void setFlightMode (const QString& flightMode); QString priorityLinkName(void) const; QVariantList links(void) const; -- 2.22.0