Commit 3b7e0db1 authored by Lionel Heng's avatar Lionel Heng

Improved custom widget functionality.

parent a9bd26d9
......@@ -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
*
......
......@@ -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 */
......
......@@ -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 **/
......
#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<MAV_ACTION>(
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;
}
......@@ -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
......@@ -21,13 +21,6 @@
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QPushButton" name="actionButton">
<property name="text">
<string>Button name</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QComboBox" name="editActionComboBox"/>
</item>
......@@ -59,26 +52,17 @@
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QPushButton" name="actionButton">
<property name="text">
<string>Button name</string>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>editButtonName</sender>
<signal>textChanged(QString)</signal>
<receiver>actionButton</receiver>
<slot>setWindowTitle(QString)</slot>
<hints>
<hint type="sourcelabel">
<x>310</x>
<y>22</y>
</hint>
<hint type="destinationlabel">
<x>310</x>
<y>55</y>
</hint>
</hints>
</connection>
<connection>
<sender>editNameLabel</sender>
<signal>textChanged(QString)</signal>
......@@ -86,11 +70,11 @@
<slot>setText(QString)</slot>
<hints>
<hint type="sourcelabel">
<x>116</x>
<x>114</x>
<y>22</y>
</hint>
<hint type="destinationlabel">
<x>116</x>
<x>114</x>
<y>55</y>
</hint>
</hints>
......
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