diff --git a/src/uas/UAS.cc b/src/uas/UAS.cc index f47e7823d5d03dc1b17fbf65f456da946b2cbadd..0d0dc90088402aae90657867c7d72d6b43b55ff0 100644 --- a/src/uas/UAS.cc +++ b/src/uas/UAS.cc @@ -1766,6 +1766,15 @@ void UAS::setUASName(const QString& name) emit systemSpecsChanged(uasId); } +void UAS::executeCommand(MAV_CMD command) +{ + mavlink_message_t msg; + mavlink_command_t cmd; + //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); +} + /** * Sets an action * diff --git a/src/uas/UAS.h b/src/uas/UAS.h index 251d9fab9f588898fd0717cb207950d00770b8e2..b38db988d7d6a7e4e3f2e1d09b57e101a5cfd970 100644 --- a/src/uas/UAS.h +++ b/src/uas/UAS.h @@ -214,6 +214,8 @@ public slots: void setUASName(const QString& name); /** @brief Executes an action **/ void setAction(MAV_ACTION action); + /** @brief Executes a command **/ + void executeCommand(MAV_CMD command); /** @brief Set the current battery type and voltages */ void setBatterySpecs(const QString& specs); /** @brief Get the current battery type and specs */ diff --git a/src/uas/UASInterface.h b/src/uas/UASInterface.h index 9cffc708511efeabb942fd774ec395490c422a53..4399314400b07cb4149ac7f98abae70bac055504 100644 --- a/src/uas/UASInterface.h +++ b/src/uas/UASInterface.h @@ -189,6 +189,8 @@ public slots: virtual void setUASName(const QString& name) = 0; /** @brief Sets an action **/ virtual void setAction(MAV_ACTION action) = 0; + /** @brief Execute command immediately **/ + virtual void executeCommand(MAV_CMD command) = 0; /** @brief Selects the airframe */ virtual void setAirframe(int airframe) = 0; diff --git a/src/ui/designer/QGCCommandButton.cc b/src/ui/designer/QGCCommandButton.cc new file mode 100644 index 0000000000000000000000000000000000000000..00bd443a247a4b48c57081775e1b5f67ff8d4806 --- /dev/null +++ b/src/ui/designer/QGCCommandButton.cc @@ -0,0 +1,97 @@ +#include "QGCCommandButton.h" +#include "ui_QGCCommandButton.h" + +#include "MAVLinkProtocol.h" +#include "UASManager.h" + +QGCCommandButton::QGCCommandButton(QWidget *parent) : + QGCToolWidgetItem("CommandButton", parent), + ui(new Ui::QGCCommandButton), + uas(NULL) +{ + ui->setupUi(this); + + connect(ui->commandButton, SIGNAL(clicked()), this, SLOT(sendCommand())); + connect(ui->editFinishButton, SIGNAL(clicked()), this, SLOT(endEditMode())); + connect(ui->editButtonName, SIGNAL(textChanged(QString)), this, SLOT(setCommandButtonName(QString))); + connect(ui->editCommandComboBox, SIGNAL(currentIndexChanged(QString)), ui->nameLabel, SLOT(setText(QString))); + + // Hide all edit items + ui->editCommandComboBox->hide(); + ui->editFinishButton->hide(); + ui->editNameLabel->hide(); + ui->editButtonName->hide(); + + // Add commands to combo box + ui->editCommandComboBox->addItem("DO: Control Video", MAV_CMD_DO_CONTROL_VIDEO); + ui->editCommandComboBox->addItem("PREFLIGHT: Calibration", MAV_CMD_PREFLIGHT_CALIBRATION); +} + +QGCCommandButton::~QGCCommandButton() +{ + delete ui; +} + +void QGCCommandButton::sendCommand() +{ + if (QGCToolWidgetItem::uas) + { + // FIXME + int index = 0;//ui->editCommandComboBox->userData() + MAV_CMD command = static_cast(index); + + QGCToolWidgetItem::uas->executeCommand(command); + } + else + { + qDebug() << __FILE__ << __LINE__ << "NO UAS SET, DOING NOTHING"; + } +} + +void QGCCommandButton::setCommandButtonName(QString text) +{ + ui->commandButton->setText(text); +} + +void QGCCommandButton::startEditMode() +{ + ui->editCommandComboBox->show(); + ui->editFinishButton->show(); + ui->editNameLabel->show(); + ui->editButtonName->show(); + isInEditMode = true; +} + +void QGCCommandButton::endEditMode() +{ + ui->editCommandComboBox->hide(); + ui->editFinishButton->hide(); + ui->editNameLabel->hide(); + ui->editButtonName->hide(); + + // Write to settings + emit editingFinished(); + + isInEditMode = false; +} + +void QGCCommandButton::writeSettings(QSettings& settings) +{ + settings.setValue("TYPE", "COMMANDBUTTON"); + settings.setValue("QGC_ACTION_BUTTON_DESCRIPTION", ui->nameLabel->text()); + settings.setValue("QGC_ACTION_BUTTON_BUTTONTEXT", ui->commandButton->text()); + settings.setValue("QGC_ACTION_BUTTON_ACTIONID", ui->editCommandComboBox->currentIndex()); + settings.sync(); +} + +void QGCCommandButton::readSettings(const QSettings& settings) +{ + ui->editNameLabel->setText(settings.value("QGC_ACTION_BUTTON_DESCRIPTION", "ERROR LOADING BUTTON").toString()); + ui->editButtonName->setText(settings.value("QGC_ACTION_BUTTON_BUTTONTEXT", "UNKNOWN").toString()); + ui->editCommandComboBox->setCurrentIndex(settings.value("QGC_ACTION_BUTTON_ACTIONID", 0).toInt()); + + ui->nameLabel->setText(settings.value("QGC_ACTION_BUTTON_DESCRIPTION", "ERROR LOADING BUTTON").toString()); + ui->commandButton->setText(settings.value("QGC_ACTION_BUTTON_BUTTONTEXT", "UNKNOWN").toString()); + ui->editCommandComboBox->setCurrentIndex(settings.value("QGC_ACTION_BUTTON_ACTIONID", 0).toInt()); + qDebug() << "DONE READING SETTINGS"; +} diff --git a/src/ui/designer/QGCCommandButton.h b/src/ui/designer/QGCCommandButton.h new file mode 100644 index 0000000000000000000000000000000000000000..99cc285ef97ab4e277a9e551260063ae8671eb03 --- /dev/null +++ b/src/ui/designer/QGCCommandButton.h @@ -0,0 +1,33 @@ +#ifndef QGCCOMMANDBUTTON_H +#define QGCCOMMANDBUTTON_H + +#include "QGCToolWidgetItem.h" + +namespace Ui { + class QGCCommandButton; +} + +class UASInterface; + +class QGCCommandButton : public QGCToolWidgetItem +{ + Q_OBJECT + +public: + explicit QGCCommandButton(QWidget *parent = 0); + ~QGCCommandButton(); + +public slots: + void sendCommand(); + void setCommandButtonName(QString text); + void startEditMode(); + void endEditMode(); + void writeSettings(QSettings& settings); + void readSettings(const QSettings& settings); + +private: + Ui::QGCCommandButton *ui; + UASInterface* uas; +}; + +#endif // QGCCOMMANDBUTTON_H diff --git a/src/ui/designer/QGCCommandButton.ui b/src/ui/designer/QGCCommandButton.ui new file mode 100644 index 0000000000000000000000000000000000000000..3476c96ab8c72df9c3a8d7986d99ebbc4a47323f --- /dev/null +++ b/src/ui/designer/QGCCommandButton.ui @@ -0,0 +1,91 @@ + + + QGCCommandButton + + + + 0 + 0 + 400 + 111 + + + + Form + + + + + + + 50 + 0 + + + + Description + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + + Done + + + + + + + Unnamed + + + + + + + Description + + + + + + + + 30 + 0 + + + + Unnamed + + + + + + + + + editNameLabel + textChanged(QString) + nameLabel + setText(QString) + + + 114 + 22 + + + 114 + 55 + + + + + diff --git a/src/ui/designer/QGCToolWidget.cc b/src/ui/designer/QGCToolWidget.cc index 83bded202f66f6510da93f550a2090327058282c..b5de182a24959c11c4149ddf32a4949ace68a341 100644 --- a/src/ui/designer/QGCToolWidget.cc +++ b/src/ui/designer/QGCToolWidget.cc @@ -10,6 +10,7 @@ #include "QGCParamSlider.h" #include "QGCActionButton.h" +#include "QGCCommandButton.h" #include "UASManager.h" QGCToolWidget::QGCToolWidget(const QString& title, QWidget *parent) : @@ -106,6 +107,11 @@ QList QGCToolWidget::createWidgetsFromSettings(QWidget* parent) item = new QGCActionButton(newWidgets.at(i)); qDebug() << "CREATED BUTTON"; } + else if (type == "COMMANDBUTTON") + { + item = new QGCCommandButton(newWidgets.at(i)); + qDebug() << "CREATED COMMANDBUTTON"; + } else if (type == "SLIDER") { item = new QGCParamSlider(newWidgets.at(i)); @@ -182,9 +188,11 @@ void QGCToolWidget::contextMenuEvent (QContextMenuEvent* event) { QMenu menu(this); menu.addAction(addParamAction); - menu.addAction(addButtonAction); + menu.addAction(addCommandAction); menu.addAction(setTitleAction); menu.addAction(deleteAction); + menu.addSeparator(); + menu.addAction(addButtonAction); menu.exec(event->globalPos()); } @@ -194,9 +202,9 @@ void QGCToolWidget::createActions() addParamAction->setStatusTip(tr("Add a parameter setting slider widget to the tool")); connect(addParamAction, SIGNAL(triggered()), this, SLOT(addParam())); - addButtonAction = new QAction(tr("New MAV &Command Button"), this); - addButtonAction->setStatusTip(tr("Add a new action button to the tool")); - connect(addButtonAction, SIGNAL(triggered()), this, SLOT(addAction())); + addCommandAction = new QAction(tr("New MAV &Command Button"), this); + addCommandAction->setStatusTip(tr("Add a new action button to the tool")); + connect(addCommandAction, SIGNAL(triggered()), this, SLOT(addCommand())); setTitleAction = new QAction(tr("Set Widget Title"), this); setTitleAction->setStatusTip(tr("Set the title caption of this tool widget")); @@ -213,6 +221,10 @@ void QGCToolWidget::createActions() importAction = new QAction(tr("Import widget"), this); importAction->setStatusTip(tr("Import this widget from a file (current content will be removed)")); connect(exportAction, SIGNAL(triggered()), this, SLOT(importWidget())); + + addButtonAction = new QAction(tr("New MAV Action Button (Deprecated)"), this); + addButtonAction->setStatusTip(tr("Add a new action button to the tool")); + connect(addButtonAction, SIGNAL(triggered()), this, SLOT(addAction())); } QMap* QGCToolWidget::instances() @@ -253,6 +265,18 @@ void QGCToolWidget::addAction() button->startEditMode(); } +void QGCToolWidget::addCommand() +{ + QGCCommandButton* button = new QGCCommandButton(this); + if (ui->hintLabel) + { + ui->hintLabel->deleteLater(); + ui->hintLabel = NULL; + } + toolLayout->addWidget(button); + button->startEditMode(); +} + void QGCToolWidget::addToolWidget(QGCToolWidgetItem* widget) { if (ui->hintLabel) diff --git a/src/ui/designer/QGCToolWidget.h b/src/ui/designer/QGCToolWidget.h index 3a14b3ae03d93eefa7e53cfa5f6ce6b1fa4ce3c9..ba21de4a8b2a3548120a01344ba24ad764c556b1 100644 --- a/src/ui/designer/QGCToolWidget.h +++ b/src/ui/designer/QGCToolWidget.h @@ -45,6 +45,7 @@ signals: protected: QAction* addParamAction; QAction* addButtonAction; + QAction* addCommandAction; QAction* setTitleAction; QAction* deleteAction; QAction* exportAction; @@ -62,7 +63,9 @@ protected: protected slots: void addParam(); + /** @deprecated */ void addAction(); + void addCommand(); void setTitle();