QGCActionButton.cc 3.65 KB
Newer Older
1 2 3
#include "QGCActionButton.h"
#include "ui_QGCActionButton.h"

4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
#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",
27
 "CALIBRATE ACC",
28 29 30 31 32 33 34 35 36 37 38 39 40 41
 "CALIBRATE PRESSURE",
 "START REC",
 "PAUSE REC",
 "STOP REC",
 "TAKEOFF",
 "NAVIGATE",
 "LAND",
 "LOITER",
 "SET ORIGIN",
 "RELAY ON",
 "RELAY OFF",
 "GET IMAGE",
 "START VIDEO",
 "STOP VIDEO",
42 43
 "RESET MAP",
 "RESET PLAN"};
44

45
QGCActionButton::QGCActionButton(QWidget *parent) :
46
    QGCToolWidgetItem("Button", parent),
47 48
    ui(new Ui::QGCActionButton),
    uas(NULL)
49 50
{
    ui->setupUi(this);
51 52

    connect(ui->actionButton, SIGNAL(clicked()), this, SLOT(sendAction()));
53
    connect(ui->editFinishButton, SIGNAL(clicked()), this, SLOT(endEditMode()));
54 55
    connect(ui->editButtonName, SIGNAL(textChanged(QString)), this, SLOT(setActionButtonName(QString)));
    connect(ui->editActionComboBox, SIGNAL(currentIndexChanged(QString)), ui->nameLabel, SLOT(setText(QString)));
lm's avatar
lm committed
56 57 58 59 60 61 62

    // Hide all edit items
    ui->editActionComboBox->hide();
    ui->editActionsRefreshButton->hide();
    ui->editFinishButton->hide();
    ui->editNameLabel->hide();
    ui->editButtonName->hide();
63 64 65 66 67 68

    // add action labels to combobox
    for (int i = 0; i < MAV_ACTION_NB; i++)
    {
        ui->editActionComboBox->addItem(kActionLabels[i]);
    }
69 70 71 72 73 74 75
}

QGCActionButton::~QGCActionButton()
{
    delete ui;
}

76 77
void QGCActionButton::sendAction()
{
78
    if (QGCToolWidgetItem::uas)
79 80 81 82
    {
        MAV_ACTION action = static_cast<MAV_ACTION>(
                ui->editActionComboBox->currentIndex());

83 84 85 86 87
        QGCToolWidgetItem::uas->setAction(action);
    }
    else
    {
        qDebug() << __FILE__ << __LINE__ << "NO UAS SET, DOING NOTHING";
88 89 90 91 92 93 94 95
    }
}

void QGCActionButton::setActionButtonName(QString text)
{
    ui->actionButton->setText(text);
}

96 97 98 99 100
void QGCActionButton::startEditMode()
{
    ui->editActionComboBox->show();
    ui->editActionsRefreshButton->show();
    ui->editFinishButton->show();
101 102
    ui->editNameLabel->show();
    ui->editButtonName->show();
103 104 105 106 107 108 109 110
    isInEditMode = true;
}

void QGCActionButton::endEditMode()
{
    ui->editActionComboBox->hide();
    ui->editActionsRefreshButton->hide();
    ui->editFinishButton->hide();
111 112 113 114
    ui->editNameLabel->hide();
    ui->editButtonName->hide();

    // Write to settings
lm's avatar
lm committed
115
    emit editingFinished();
116

117 118
    isInEditMode = false;
}
lm's avatar
lm committed
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139

void QGCActionButton::writeSettings(QSettings& settings)
{
    settings.setValue("TYPE", "BUTTON");
    settings.setValue("QGC_ACTION_BUTTON_DESCRIPTION", ui->nameLabel->text());
    settings.setValue("QGC_ACTION_BUTTON_BUTTONTEXT", ui->actionButton->text());
    settings.setValue("QGC_ACTION_BUTTON_ACTIONID", ui->editActionComboBox->currentIndex());
    settings.sync();
}

void QGCActionButton::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->editActionComboBox->setCurrentIndex(settings.value("QGC_ACTION_BUTTON_ACTIONID", 0).toInt());

    ui->nameLabel->setText(settings.value("QGC_ACTION_BUTTON_DESCRIPTION", "ERROR LOADING BUTTON").toString());
    ui->actionButton->setText(settings.value("QGC_ACTION_BUTTON_BUTTONTEXT", "UNKNOWN").toString());
    ui->editActionComboBox->setCurrentIndex(settings.value("QGC_ACTION_BUTTON_ACTIONID", 0).toInt());
    qDebug() << "DONE READING SETTINGS";
}