Commit ed323bbe authored by Alejandro's avatar Alejandro
Browse files

white space

parent 8d32f1da
This diff is collapsed.
/*===================================================================== /*=====================================================================
QGroundControl Open Source Ground Control Station QGroundControl Open Source Ground Control Station
(c) 2009, 2010 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org> (c) 2009, 2010 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
This file is part of the QGROUNDCONTROL project This file is part of the QGROUNDCONTROL project
QGROUNDCONTROL is free software: you can redistribute it and/or modify QGROUNDCONTROL is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or
(at your option) any later version. (at your option) any later version.
QGROUNDCONTROL is distributed in the hope that it will be useful, QGROUNDCONTROL is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with QGROUNDCONTROL. If not, see <http://www.gnu.org/licenses/>. along with QGROUNDCONTROL. If not, see <http://www.gnu.org/licenses/>.
======================================================================*/ ======================================================================*/
/** /**
* @file * @file
* @brief Implementation of class UASManager * @brief Implementation of class UASManager
* @author Lorenz Meier <mavteam@student.ethz.ch> * @author Lorenz Meier <mavteam@student.ethz.ch>
* *
*/ */
#include <QList> #include <QList>
#include <QApplication> #include <QApplication>
#include <QMessageBox> #include <QMessageBox>
#include <QTimer> #include <QTimer>
#include "UAS.h" #include "UAS.h"
#include "UASInterface.h" #include "UASInterface.h"
#include "UASManager.h" #include "UASManager.h"
#include "QGC.h" #include "QGC.h"
UASManager* UASManager::instance() UASManager* UASManager::instance()
{ {
static UASManager* _instance = 0; static UASManager* _instance = 0;
if(_instance == 0) { if(_instance == 0) {
_instance = new UASManager(); _instance = new UASManager();
// Set the application as parent to ensure that this object // Set the application as parent to ensure that this object
// will be destroyed when the main application exits // will be destroyed when the main application exits
_instance->setParent(qApp); _instance->setParent(qApp);
} }
return _instance; return _instance;
} }
/** /**
* @brief Private singleton constructor * @brief Private singleton constructor
* *
* This class implements the singleton design pattern and has therefore only a private constructor. * This class implements the singleton design pattern and has therefore only a private constructor.
**/ **/
UASManager::UASManager() : UASManager::UASManager() :
activeUAS(NULL) activeUAS(NULL)
{ {
systems = QList<UASInterface*>(); systems = QList<UASInterface*>();
start(QThread::LowPriority); start(QThread::LowPriority);
} }
UASManager::~UASManager() UASManager::~UASManager()
{ {
} }
void UASManager::run() void UASManager::run()
{ {
forever forever
{ {
QGC::SLEEP::msleep(5000); QGC::SLEEP::msleep(5000);
} }
} }
void UASManager::addUAS(UASInterface* uas) void UASManager::addUAS(UASInterface* uas)
{ {
// WARNING: The active uas is set here // WARNING: The active uas is set here
// and then announced below. This is necessary // and then announced below. This is necessary
// to make sure the getActiveUAS() function // to make sure the getActiveUAS() function
// returns the UAS once the UASCreated() signal // returns the UAS once the UASCreated() signal
// is emitted. The code is thus NOT redundant. // is emitted. The code is thus NOT redundant.
bool firstUAS = false; bool firstUAS = false;
if (activeUAS == NULL) if (activeUAS == NULL)
{ {
firstUAS = true; firstUAS = true;
activeUAS = uas; activeUAS = uas;
} }
// Only execute if there is no UAS at this index // Only execute if there is no UAS at this index
if (!systems.contains(uas)) if (!systems.contains(uas))
{ {
systems.append(uas); systems.append(uas);
connect(uas, SIGNAL(destroyed(QObject*)), this, SLOT(removeUAS(QObject*))); connect(uas, SIGNAL(destroyed(QObject*)), this, SLOT(removeUAS(QObject*)));
emit UASCreated(uas); emit UASCreated(uas);
} }
// If there is no active UAS yet, set the first one as the active UAS // If there is no active UAS yet, set the first one as the active UAS
if (firstUAS) if (firstUAS)
{ {
setActiveUAS(uas); setActiveUAS(uas);
} }
} }
void UASManager::removeUAS(QObject* uas) void UASManager::removeUAS(QObject* uas)
{ {
UASInterface* mav = qobject_cast<UASInterface*>(uas); UASInterface* mav = qobject_cast<UASInterface*>(uas);
if (mav) if (mav)
{ {
int listindex = systems.indexOf(mav); int listindex = systems.indexOf(mav);
if (mav == activeUAS) if (mav == activeUAS)
{ {
if (systems.count() > 1) if (systems.count() > 1)
{ {
// We only set a new UAS if more than one is present // We only set a new UAS if more than one is present
if (listindex != 0) if (listindex != 0)
{ {
// The system to be removed is not at position 1 // The system to be removed is not at position 1
// set position one as new active system // set position one as new active system
setActiveUAS(systems.first()); setActiveUAS(systems.first());
} }
else else
{ {
// The system to be removed is at position 1, // The system to be removed is at position 1,
// select the next system // select the next system
setActiveUAS(systems.at(1)); setActiveUAS(systems.at(1));
} }
} }
else else
{ {
// TODO send a null pointer if no UAS is present any more // TODO send a null pointer if no UAS is present any more
// This has to be proberly tested however, since it might // This has to be proberly tested however, since it might
// crash code parts not handling null pointers correctly. // crash code parts not handling null pointers correctly.
} }
} }
systems.removeAt(listindex); systems.removeAt(listindex);
} }
} }
QList<UASInterface*> UASManager::getUASList() QList<UASInterface*> UASManager::getUASList()
{ {
return systems; return systems;
} }
UASInterface* UASManager::getActiveUAS() UASInterface* UASManager::getActiveUAS()
{ {
return activeUAS; ///< Return zero pointer if no UAS has been loaded return activeUAS; ///< Return zero pointer if no UAS has been loaded
} }
UASInterface* UASManager::silentGetActiveUAS() UASInterface* UASManager::silentGetActiveUAS()
{ {
return activeUAS; ///< Return zero pointer if no UAS has been loaded return activeUAS; ///< Return zero pointer if no UAS has been loaded
} }
bool UASManager::launchActiveUAS() bool UASManager::launchActiveUAS()
{ {
// If the active UAS is set, execute command // If the active UAS is set, execute command
if (getActiveUAS()) activeUAS->launch(); if (getActiveUAS()) activeUAS->launch();
return (activeUAS); ///< Returns true if the UAS exists, false else return (activeUAS); ///< Returns true if the UAS exists, false else
} }
bool UASManager::haltActiveUAS() bool UASManager::haltActiveUAS()
{ {
// If the active UAS is set, execute command // If the active UAS is set, execute command
if (getActiveUAS()) activeUAS->halt(); if (getActiveUAS()) activeUAS->halt();
return (activeUAS); ///< Returns true if the UAS exists, false else return (activeUAS); ///< Returns true if the UAS exists, false else
} }
bool UASManager::continueActiveUAS() bool UASManager::continueActiveUAS()
{ {
// If the active UAS is set, execute command // If the active UAS is set, execute command
if (getActiveUAS()) activeUAS->go(); if (getActiveUAS()) activeUAS->go();
return (activeUAS); ///< Returns true if the UAS exists, false else return (activeUAS); ///< Returns true if the UAS exists, false else
} }
bool UASManager::returnActiveUAS() bool UASManager::returnActiveUAS()
{ {
// If the active UAS is set, execute command // If the active UAS is set, execute command
if (getActiveUAS()) activeUAS->home(); if (getActiveUAS()) activeUAS->home();
return (activeUAS); ///< Returns true if the UAS exists, false else return (activeUAS); ///< Returns true if the UAS exists, false else
} }
bool UASManager::stopActiveUAS() bool UASManager::stopActiveUAS()
{ {
// If the active UAS is set, execute command // If the active UAS is set, execute command
if (getActiveUAS()) activeUAS->emergencySTOP(); if (getActiveUAS()) activeUAS->emergencySTOP();
return (activeUAS); ///< Returns true if the UAS exists, false else return (activeUAS); ///< Returns true if the UAS exists, false else
} }
bool UASManager::killActiveUAS() bool UASManager::killActiveUAS()
{ {
if (getActiveUAS()) activeUAS->emergencyKILL(); if (getActiveUAS()) activeUAS->emergencyKILL();
return (activeUAS); return (activeUAS);
} }
bool UASManager::shutdownActiveUAS() bool UASManager::shutdownActiveUAS()
{ {
if (getActiveUAS()) activeUAS->shutdown(); if (getActiveUAS()) activeUAS->shutdown();
return (activeUAS); return (activeUAS);
} }
void UASManager::configureActiveUAS() void UASManager::configureActiveUAS()
{ {
UASInterface* actUAS = getActiveUAS(); UASInterface* actUAS = getActiveUAS();
if(actUAS) if(actUAS)
{ {
// Do something // Do something
} }
} }
UASInterface* UASManager::getUASForId(int id) UASInterface* UASManager::getUASForId(int id)
{ {
UASInterface* system = NULL; UASInterface* system = NULL;
foreach(UASInterface* sys, systems) foreach(UASInterface* sys, systems)
{ {
if (sys->getUASID() == id) if (sys->getUASID() == id)
{ {
system = sys; system = sys;
} }
} }
// Return NULL if not found // Return NULL if not found
return system; return system;
} }
void UASManager::setActiveUAS(UASInterface* uas) void UASManager::setActiveUAS(UASInterface* uas)
{ {
if (uas != NULL) if (uas != NULL)
{ {
activeUASMutex.lock(); activeUASMutex.lock();
if (activeUAS != NULL) if (activeUAS != NULL)
{ {
emit activeUASStatusChanged(activeUAS, false); emit activeUASStatusChanged(activeUAS, false);
emit activeUASStatusChanged(activeUAS->getUASID(), false); emit activeUASStatusChanged(activeUAS->getUASID(), false);
} }
activeUAS = uas; activeUAS = uas;
activeUASMutex.unlock(); activeUASMutex.unlock();
activeUAS->setSelected(); activeUAS->setSelected();
emit activeUASSet(uas); emit activeUASSet(uas);
emit activeUASSet(uas->getUASID()); emit activeUASSet(uas->getUASID());
emit activeUASSetListIndex(systems.indexOf(uas)); emit activeUASSetListIndex(systems.indexOf(uas));
emit activeUASStatusChanged(uas, true); emit activeUASStatusChanged(uas, true);
emit activeUASStatusChanged(uas->getUASID(), true); emit activeUASStatusChanged(uas->getUASID(), true);
} }
} }
This diff is collapsed.
This diff is collapsed.
#include "QGCActionButton.h" #include "QGCActionButton.h"
#include "ui_QGCActionButton.h" #include "ui_QGCActionButton.h"
#include "MAVLinkProtocol.h" #include "MAVLinkProtocol.h"
#include "UASManager.h" #include "UASManager.h"
const char* kActionLabels[MAV_ACTION_NB] = const char* kActionLabels[MAV_ACTION_NB] =
{"HOLD", {"HOLD",
"START MOTORS", "START MOTORS",
"LAUNCH", "LAUNCH",
"RETURN", "RETURN",
"EMERGENCY LAND", "EMERGENCY LAND",
"EMERGENCY KILL", "EMERGENCY KILL",
"CONFIRM KILL", "CONFIRM KILL",
"CONTINUE", "CONTINUE",
"STOP MOTORS", "STOP MOTORS",
"HALT", "HALT",
"SHUTDOWN", "SHUTDOWN",
"REBOOT", "REBOOT",
"SET MANUAL", "SET MANUAL",
"SET AUTO", "SET AUTO",
"READ STORAGE", "READ STORAGE",
"WRITE STORAGE", "WRITE STORAGE",
"CALIBRATE RC", "CALIBRATE RC",
"CALIBRATE GYRO", "CALIBRATE GYRO",
"CALIBRATE MAG", "CALIBRATE MAG",
"CALIBRATE ACC", "CALIBRATE ACC",
"CALIBRATE PRESSURE", "CALIBRATE PRESSURE",
"START REC", "START REC",
"PAUSE REC", "PAUSE REC",
"STOP REC", "STOP REC",
"TAKEOFF", "TAKEOFF",
"NAVIGATE", "NAVIGATE",
"LAND", "LAND",
"LOITER", "LOITER",
"SET ORIGIN", "SET ORIGIN",
"RELAY ON", "RELAY ON",
//"RELAY OFF", //"RELAY OFF",
//"GET IMAGE", //"GET IMAGE",
//"START VIDEO", //"START VIDEO",
//"STOP VIDEO", //"STOP VIDEO",
"RESET MAP", "RESET MAP",
"RESET PLAN"}; "RESET PLAN"};
QGCActionButton::QGCActionButton(QWidget *parent) : QGCActionButton::QGCActionButton(QWidget *parent) :
QGCToolWidgetItem("Button", parent), QGCToolWidgetItem("Button", parent),
ui(new Ui::QGCActionButton), ui(new Ui::QGCActionButton),
uas(NULL) uas(NULL)
{ {
ui->setupUi(this); ui->setupUi(this);
connect(ui->actionButton, SIGNAL(clicked()), this, SLOT(sendAction())); connect(ui->actionButton, SIGNAL(clicked()), this, SLOT(sendAction()));
connect(ui->editFinishButton, SIGNAL(clicked()), this, SLOT(endEditMode())); connect(ui->editFinishButton, SIGNAL(clicked()), this, SLOT(endEditMode()));
connect(ui->editButtonName, SIGNAL(textChanged(QString)), this, SLOT(setActionButtonName(QString))); connect(ui->editButtonName, SIGNAL(textChanged(QString)), this, SLOT(setActionButtonName(QString)));
connect(ui->editActionComboBox, SIGNAL(currentIndexChanged(QString)), ui->nameLabel, SLOT(setText(QString))); connect(ui->editActionComboBox, SIGNAL(currentIndexChanged(QString)), ui->nameLabel, SLOT(setText(QString)));
// Hide all edit items // Hide all edit items
ui->editActionComboBox->hide(); ui->editActionComboBox->hide();
ui->editActionsRefreshButton->hide(); ui->editActionsRefreshButton->hide();
ui->editFinishButton->hide(); ui->editFinishButton->hide();
ui->editNameLabel->hide(); ui->editNameLabel->hide();
ui->editButtonName->hide(); ui->editButtonName->hide();
// add action labels to combobox // add action labels to combobox
for (int i = 0; i < MAV_ACTION_NB; i++) for (int i = 0; i < MAV_ACTION_NB; i++)
{ {
ui->editActionComboBox->addItem(kActionLabels[i]); ui->editActionComboBox->addItem(kActionLabels[i]);
} }
} }
QGCActionButton::~QGCActionButton() QGCActionButton::~QGCActionButton()
{ {
delete ui; delete ui;
} }
void QGCActionButton::sendAction() void QGCActionButton::sendAction()
{ {
if (QGCToolWidgetItem::uas) if (QGCToolWidgetItem::uas)
{ {
MAV_ACTION action = static_cast<MAV_ACTION>( MAV_ACTION action = static_cast<MAV_ACTION>(
ui->editActionComboBox->currentIndex()); ui->editActionComboBox->currentIndex());
QGCToolWidgetItem::uas->setAction(action); QGCToolWidgetItem::uas->setAction(action);
} }
else else
{ {
qDebug() << __FILE__ << __LINE__ << "NO UAS SET, DOING NOTHING"; qDebug() << __FILE__ << __LINE__ << "NO UAS SET, DOING NOTHING";
} }
} }
void QGCActionButton::setActionButtonName(QString text) void QGCActionButton::setActionButtonName(QString text)
{ {
ui->actionButton->setText(text); ui->actionButton->setText(text);
} }
void QGCActionButton::startEditMode() void QGCActionButton::startEditMode()
{ {
ui->editActionComboBox->show(); ui->editActionComboBox->show();
ui->editActionsRefreshButton->show(); ui->editActionsRefreshButton->show();
ui->editFinishButton->show(); ui->editFinishButton->show();
ui->editNameLabel->show(); ui->editNameLabel->show();
ui->editButtonName->show(); ui->editButtonName->show();
isInEditMode = true; isInEditMode = true;
} }
void QGCActionButton::endEditMode() void QGCActionButton::endEditMode()
{ {
ui->editActionComboBox->hide(); ui->editActionComboBox->hide();
ui->editActionsRefreshButton->hide(); ui->editActionsRefreshButton->hide();
ui->editFinishButton->hide(); ui->editFinishButton->hide();
ui->editNameLabel->hide(); ui->editNameLabel->hide();
ui->editButtonName->hide(); ui->editButtonName->hide();
// Write to settings // Write to settings
emit editingFinished(); emit editingFinished();
isInEditMode = false; isInEditMode = false;
} }
void QGCActionButton::writeSettings(QSettings& settings) void QGCActionButton::writeSettings(QSettings& settings)
{ {
settings.setValue("TYPE", "BUTTON"); settings.setValue("TYPE", "BUTTON");
settings.setValue("QGC_ACTION_BUTTON_DESCRIPTION", ui->nameLabel->text()); settings.setValue("QGC_ACTION_BUTTON_DESCRIPTION", ui->nameLabel->text());
settings.setValue("QGC_ACTION_BUTTON_BUTTONTEXT", ui->actionButton->text()); settings.setValue("QGC_ACTION_BUTTON_BUTTONTEXT", ui->actionButton->text());
settings.setValue("QGC_ACTION_BUTTON_ACTIONID", ui->editActionComboBox->currentIndex()); settings.setValue("QGC_ACTION_BUTTON_ACTIONID", ui->editActionComboBox->currentIndex());
settings.sync(); settings.sync();
} }
void QGCActionButton::readSettings(const QSettings& settings) void QGCActionButton::readSettings(const QSettings& settings)
{ {
ui->editNameLabel->setText(settings.value("QGC_ACTION_BUTTON_DESCRIPTION", "ERROR LOADING BUTTON").toString()); 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->editButtonName->setText(settings.value("QGC_ACTION_BUTTON_BUTTONTEXT", "UNKNOWN").toString());
ui->editActionComboBox->setCurrentIndex(settings.value("QGC_ACTION_BUTTON_ACTIONID", 0).toInt()); 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->nameLabel->setText(settings.value("QGC_ACTION_BUTTON_DESCRIPTION", "ERROR LOADING BUTTON").toString());
ui->actionButton->setText(settings.value("QGC_ACTION_BUTTON_BUTTONTEXT", "UNKNOWN").toString()); ui->actionButton->setText(settings.value("QGC_ACTION_BUTTON_BUTTONTEXT", "UNKNOWN").toString());
ui->editActionComboBox->setCurrentIndex(settings.value("QGC_ACTION_BUTTON_ACTIONID", 0).toInt()); ui->editActionComboBox->setCurrentIndex(settings.value("QGC_ACTION_BUTTON_ACTIONID", 0).toInt());
qDebug() << "DONE READING SETTINGS"; qDebug() << "DONE READING SETTINGS";
} }
This diff is collapsed.
Supports Markdown
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