diff --git a/src/uas/UAS.cc b/src/uas/UAS.cc index 7fc1a66aebdf09878ee138b03d2015baf272b3d9..2110411d5cf4c470d0f6d7270f871fee34df2032 100644 --- a/src/uas/UAS.cc +++ b/src/uas/UAS.cc @@ -1290,6 +1290,19 @@ void UAS::setParameter(int component, QString id, float value) sendMessage(msg); } +/** + * Sets an action + * + **/ +void UAS::setAction(MAV_ACTION action) +{ + mavlink_message_t msg; + mavlink_msg_action_pack(mavlink->getSystemId(), mavlink->getComponentId(), &msg, this->getUASID(), 0, action); + // Send message twice to increase chance that it reaches its goal + sendMessage(msg); + sendMessage(msg); +} + /** * Launches the system * diff --git a/src/uas/UAS.h b/src/uas/UAS.h index d246b6772a0cd166e6ecef4276edc96cb9cb71d5..410b15e4a23362a93946744c8972ce72b16979dd 100644 --- a/src/uas/UAS.h +++ b/src/uas/UAS.h @@ -174,6 +174,9 @@ public: void setAutopilotType(int apType) { autopilot = apType;} public slots: + /** @brief Sets an action **/ + void setAction(MAV_ACTION action); + /** @brief Launches the system **/ void launch(); /** @brief Write this waypoint to the list of waypoints */ diff --git a/src/uas/UASInterface.h b/src/uas/UASInterface.h index ae577205ef6297cc118fcbb01f9a561cf146d475..8bbc716b981360663a4592aecf532689384f3a62 100644 --- a/src/uas/UASInterface.h +++ b/src/uas/UASInterface.h @@ -162,6 +162,9 @@ public: public slots: + /** @brief Sets an action **/ + virtual void setAction(MAV_ACTION action) = 0; + /** @brief Launches the system/Liftof **/ virtual void launch() = 0; /** @brief Set a new waypoint **/ diff --git a/src/ui/designer/QGCActionButton.cc b/src/ui/designer/QGCActionButton.cc index 84c5f2f85f6cd6acc97bba56e4d321713ffab005..fe59d62fb8d3872ddcb1d34ed013618f5c749a22 100644 --- a/src/ui/designer/QGCActionButton.cc +++ b/src/ui/designer/QGCActionButton.cc @@ -1,13 +1,66 @@ #include "QGCActionButton.h" #include "ui_QGCActionButton.h" +#include "MAVLinkProtocol.h" +#include "UASManager.h" + +const char* kActionLabels[MAV_ACTION_NB] = +{"HOLD", + "START MOTORS", + "LAUNCH", + "RETURN", + "EMERGENCY LAND", + "EMERGENCY KILL", + "CONFIRM KILL", + "CONTINUE", + "STOP MOTORS", + "HALT", + "SHUTDOWN", + "REBOOT", + "SET MANUAL", + "SET AUTO", + "READ STORAGE", + "WRITE STORAGE", + "CALIBRATE RC", + "CALIBRATE GYRO", + "CALIBRATE MAG", + "CALIBRATE PRESSURE", + "START REC", + "PAUSE REC", + "STOP REC", + "TAKEOFF", + "NAVIGATE", + "LAND", + "LOITER", + "SET ORIGIN", + "RELAY ON", + "RELAY OFF", + "GET IMAGE", + "START VIDEO", + "STOP VIDEO", + "RESET MAP"}; + QGCActionButton::QGCActionButton(QWidget *parent) : QGCToolWidgetItem(parent), - ui(new Ui::QGCActionButton) + ui(new Ui::QGCActionButton), + uas(NULL) { ui->setupUi(this); + + connect(UASManager::instance(), SIGNAL(activeUASSet(UASInterface*)), + this, SLOT(setActiveUAS(UASInterface*))); + + connect(ui->actionButton, SIGNAL(clicked()), this, SLOT(sendAction())); connect(ui->editFinishButton, SIGNAL(clicked()), this, SLOT(endEditMode())); + connect(ui->editButtonName, SIGNAL(textChanged(QString)), this, SLOT(setActionButtonName(QString))); + connect(ui->editActionComboBox, SIGNAL(currentIndexChanged(QString)), ui->nameLabel, SLOT(setText(QString))); endEditMode(); + + // add action labels to combobox + for (int i = 0; i < MAV_ACTION_NB; i++) + { + ui->editActionComboBox->addItem(kActionLabels[i]); + } } QGCActionButton::~QGCActionButton() @@ -15,6 +68,22 @@ QGCActionButton::~QGCActionButton() delete ui; } +void QGCActionButton::sendAction() +{ + if (uas) + { + MAV_ACTION action = static_cast( + ui->editActionComboBox->currentIndex()); + + uas->setAction(action); + } +} + +void QGCActionButton::setActionButtonName(QString text) +{ + ui->actionButton->setText(text); +} + void QGCActionButton::startEditMode() { ui->editActionComboBox->show(); @@ -30,3 +99,8 @@ void QGCActionButton::endEditMode() ui->editFinishButton->hide(); isInEditMode = false; } + +void QGCActionButton::setActiveUAS(UASInterface *uas) +{ + this->uas = uas; +} diff --git a/src/ui/designer/QGCActionButton.h b/src/ui/designer/QGCActionButton.h index 63556d6fef07c219543970c07dc1a82fbf1f4410..9f21b7338a3aca431a4d3ba97384b91fe3536e71 100644 --- a/src/ui/designer/QGCActionButton.h +++ b/src/ui/designer/QGCActionButton.h @@ -7,6 +7,8 @@ namespace Ui { class QGCActionButton; } +class UASInterface; + class QGCActionButton : public QGCToolWidgetItem { Q_OBJECT @@ -16,11 +18,17 @@ public: ~QGCActionButton(); public slots: + void sendAction(); + void setActionButtonName(QString text); void startEditMode(); void endEditMode(); +private slots: + void setActiveUAS(UASInterface* uas); + private: Ui::QGCActionButton *ui; + UASInterface* uas; }; #endif // QGCACTIONBUTTON_H diff --git a/src/ui/designer/QGCActionButton.ui b/src/ui/designer/QGCActionButton.ui index 86224813375e7bbba19927aa7660a41f0389c2cf..2d046937964fd81ea9d85d454032a62e76c602b4 100644 --- a/src/ui/designer/QGCActionButton.ui +++ b/src/ui/designer/QGCActionButton.ui @@ -21,13 +21,6 @@ - - - - Button name - - - @@ -59,26 +52,17 @@ + + + + Button name + + + - - editButtonName - textChanged(QString) - actionButton - setWindowTitle(QString) - - - 310 - 22 - - - 310 - 55 - - - editNameLabel textChanged(QString) @@ -86,11 +70,11 @@ setText(QString) - 116 + 114 22 - 116 + 114 55