Commit 20723799 authored by lm's avatar lm

Added command button

parent bed216dd
......@@ -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
*
......
......@@ -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 */
......
......@@ -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;
......
#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<MAV_CMD>(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";
}
#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
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>QGCCommandButton</class>
<widget class="QWidget" name="QGCCommandButton">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>111</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QGridLayout" name="gridLayout" columnstretch="100,100,50">
<item row="1" column="0" colspan="2">
<widget class="QLabel" name="nameLabel">
<property name="minimumSize">
<size>
<width>50</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>Description</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="2" column="0" colspan="2">
<widget class="QComboBox" name="editCommandComboBox"/>
</item>
<item row="2" column="2">
<widget class="QPushButton" name="editFinishButton">
<property name="text">
<string>Done</string>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QLineEdit" name="editButtonName">
<property name="text">
<string>Unnamed</string>
</property>
</widget>
</item>
<item row="0" column="0" colspan="2">
<widget class="QLineEdit" name="editNameLabel">
<property name="text">
<string>Description</string>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QPushButton" name="commandButton">
<property name="minimumSize">
<size>
<width>30</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>Unnamed</string>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>editNameLabel</sender>
<signal>textChanged(QString)</signal>
<receiver>nameLabel</receiver>
<slot>setText(QString)</slot>
<hints>
<hint type="sourcelabel">
<x>114</x>
<y>22</y>
</hint>
<hint type="destinationlabel">
<x>114</x>
<y>55</y>
</hint>
</hints>
</connection>
</connections>
</ui>
......@@ -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*> 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<QString, QGCToolWidget*>* 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)
......
......@@ -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();
......
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