Commit 1dfb5e50 authored by lm's avatar lm

Allowed the removal of UAS objects, added aggressive disconnect warning

parent 16ee3c6a
...@@ -151,7 +151,7 @@ void SerialLink::run() ...@@ -151,7 +151,7 @@ void SerialLink::run()
void SerialLink::checkForBytes() void SerialLink::checkForBytes()
{ {
/* Check if bytes are available */ /* Check if bytes are available */
if(port && port->isOpen()) if(port && port->isOpen() && port->isWritable())
{ {
dataMutex.lock(); dataMutex.lock();
qint64 available = port->bytesAvailable(); qint64 available = port->bytesAvailable();
......
...@@ -271,6 +271,12 @@ void UAS::receiveMessage(LinkInterface* link, mavlink_message_t message) ...@@ -271,6 +271,12 @@ void UAS::receiveMessage(LinkInterface* link, mavlink_message_t message)
GAudioOutput::instance()->stopEmergency(); GAudioOutput::instance()->stopEmergency();
GAudioOutput::instance()->say(audiostring); GAudioOutput::instance()->say(audiostring);
} }
if (state.status == MAV_STATE_POWEROFF)
{
emit systemRemoved(this);
emit systemRemoved();
}
} }
break; break;
case MAVLINK_MSG_ID_RAW_IMU: case MAVLINK_MSG_ID_RAW_IMU:
......
...@@ -262,6 +262,9 @@ signals: ...@@ -262,6 +262,9 @@ signals:
* @param description longer textual description. Should be however limited to a short text, e.g. 200 chars. * @param description longer textual description. Should be however limited to a short text, e.g. 200 chars.
*/ */
void statusChanged(UASInterface* uas, QString status, QString description); void statusChanged(UASInterface* uas, QString status, QString description);
/** @brief System has been removed / disconnected / shutdown cleanly, remove */
void systemRemoved(UASInterface* uas);
void systemRemoved();
/** /**
* @brief Received a plain text message from the robot * @brief Received a plain text message from the robot
* This signal should NOT be used for standard communication, but rather for VERY IMPORTANT * This signal should NOT be used for standard communication, but rather for VERY IMPORTANT
......
...@@ -1299,7 +1299,11 @@ void MainWindow::UASCreated(UASInterface* uas) ...@@ -1299,7 +1299,11 @@ void MainWindow::UASCreated(UASInterface* uas)
break; break;
} }
ui.menuConnected_Systems->addAction(icon, tr("Select %1 for control").arg(uas->getUASName()), uas, SLOT(setSelected())); QAction* uasAction = new QAction(icon, tr("Select %1 for control").arg(uas->getUASName()), ui.menuConnected_Systems);
connect(uas, SIGNAL(systemRemoved()), uasAction, SLOT(deleteLater()));
connect(uasAction, SIGNAL(triggered()), uas, SLOT(setSelected()));
ui.menuConnected_Systems->addAction(uasAction);
// FIXME Should be not inside the mainwindow // FIXME Should be not inside the mainwindow
if (debugConsoleDockWidget) if (debugConsoleDockWidget)
......
...@@ -181,7 +181,31 @@ QProgressBar::chunk#speedBar { ...@@ -181,7 +181,31 @@ QProgressBar::chunk#speedBar {
QProgressBar::chunk#thrustBar { QProgressBar::chunk#thrustBar {
background-color: orange; background-color: orange;
}</string> }
QToolTip {
background-color: #090909;
border: 1px solid #379AC3;
border-radius: 3px;
color: #DDDDDF;
}
QMenu {
border: 1px solid #379AC3;
background-color: #050508;
color: #DDDDDF;
background-clip: border;
font-size: 11px;
}
QMenu::separator {
height: 1px;
background: #379AC3;
margin-top: 8px;
margin-bottom: 4px;
margin-left: 5px;
margin-right: 5px;
}</string>
</property> </property>
<layout class="QHBoxLayout" name="horizontalLayout_2"> <layout class="QHBoxLayout" name="horizontalLayout_2">
<property name="spacing"> <property name="spacing">
......
...@@ -31,6 +31,7 @@ This file is part of the PIXHAWK project ...@@ -31,6 +31,7 @@ This file is part of the PIXHAWK project
#include <cmath> #include <cmath>
#include <QDateTime> #include <QDateTime>
#include <QDebug> #include <QDebug>
#include <QMenu>
#include "QGC.h" #include "QGC.h"
#include "MG.h" #include "MG.h"
...@@ -42,6 +43,8 @@ This file is part of the PIXHAWK project ...@@ -42,6 +43,8 @@ This file is part of the PIXHAWK project
UASView::UASView(UASInterface* uas, QWidget *parent) : UASView::UASView(UASInterface* uas, QWidget *parent) :
QWidget(parent), QWidget(parent),
startTime(0), startTime(0),
lastHeartbeat(0),
iconIsRed(true),
timeRemaining(0), timeRemaining(0),
chargeLevel(0), chargeLevel(0),
uas(uas), uas(uas),
...@@ -60,6 +63,7 @@ UASView::UASView(UASInterface* uas, QWidget *parent) : ...@@ -60,6 +63,7 @@ UASView::UASView(UASInterface* uas, QWidget *parent) :
alt(0), alt(0),
groundDistance(0), groundDistance(0),
localFrame(false), localFrame(false),
removeAction(new QAction("Remove this system", this)),
m_ui(new Ui::UASView) m_ui(new Ui::UASView)
{ {
m_ui->setupUi(this); m_ui->setupUi(this);
...@@ -92,6 +96,10 @@ UASView::UASView(UASInterface* uas, QWidget *parent) : ...@@ -92,6 +96,10 @@ UASView::UASView(UASInterface* uas, QWidget *parent) :
connect(m_ui->abortButton, SIGNAL(clicked()), uas, SLOT(emergencySTOP())); connect(m_ui->abortButton, SIGNAL(clicked()), uas, SLOT(emergencySTOP()));
connect(m_ui->killButton, SIGNAL(clicked()), uas, SLOT(emergencyKILL())); connect(m_ui->killButton, SIGNAL(clicked()), uas, SLOT(emergencyKILL()));
connect(m_ui->shutdownButton, SIGNAL(clicked()), uas, SLOT(shutdown())); connect(m_ui->shutdownButton, SIGNAL(clicked()), uas, SLOT(shutdown()));
// Allow to delete this widget
connect(removeAction, SIGNAL(triggered()), this, SLOT(deleteLater()));
connect(uas, SIGNAL(systemRemoved()), this, SLOT(deleteLater()));
// Set static values // Set static values
...@@ -230,12 +238,11 @@ void UASView::hideEvent(QHideEvent* event) ...@@ -230,12 +238,11 @@ void UASView::hideEvent(QHideEvent* event)
void UASView::receiveHeartbeat(UASInterface* uas) void UASView::receiveHeartbeat(UASInterface* uas)
{ {
Q_UNUSED(uas); Q_UNUSED(uas);
QString colorstyle;
heartbeatColor = QColor(20, 200, 20); heartbeatColor = QColor(20, 200, 20);
colorstyle = colorstyle.sprintf("QGroupBox { border: 1px solid #EEEEEE; border-radius: 4px; padding: 0px; margin: 0px; background-color: #%02X%02X%02X;}", QString colorstyle("QGroupBox { border-radius: 5px; padding: 2px; margin: 2px; border: 0px; background-color: %1; }");
heartbeatColor.red(), heartbeatColor.green(), heartbeatColor.blue()); m_ui->heartbeatIcon->setStyleSheet(colorstyle.arg(heartbeatColor.name()));
m_ui->heartbeatIcon->setStyleSheet(colorstyle); lastHeartbeat = QGC::groundTimeUsecs();
m_ui->heartbeatIcon->setAutoFillBackground(true); //m_ui->heartbeatIcon->setAutoFillBackground(true);
} }
/** /**
...@@ -391,6 +398,16 @@ void UASView::updateLoad(UASInterface* uas, double load) ...@@ -391,6 +398,16 @@ void UASView::updateLoad(UASInterface* uas, double load)
} }
} }
void UASView::contextMenuEvent (QContextMenuEvent* event)
{
if (QGC::groundTimeUsecs() - lastHeartbeat > 1500000)
{
QMenu menu(this);
menu.addAction(removeAction);
menu.exec(event->globalPos());
}
}
void UASView::refresh() void UASView::refresh()
{ {
//setUpdatesEnabled(false); //setUpdatesEnabled(false);
...@@ -494,15 +511,44 @@ void UASView::refresh() ...@@ -494,15 +511,44 @@ void UASView::refresh()
} }
generalUpdateCount++; generalUpdateCount++;
QString colorstyle("QGroupBox { border-radius: 5px; padding: 2px; margin: 2px; border: 0px; background-color: %1; }");
if (QGC::groundTimeUsecs() - lastHeartbeat > 1500000)
{
// CRITICAL CONDITION, NO HEARTBEAT
if (iconIsRed)
{
QColor warnColor(Qt::red);
m_ui->heartbeatIcon->setStyleSheet(colorstyle.arg(warnColor.name()));
QString style = QString("QGroupBox { border-radius: 12px; padding: 0px; margin: 0px; background-color: %1; }").arg(warnColor.name());
m_ui->uasViewFrame->setStyleSheet(style);
}
else
{
QColor warnColor(Qt::black);
m_ui->heartbeatIcon->setStyleSheet(colorstyle.arg(warnColor.name()));
QString style = QString("QGroupBox { border-radius: 12px; padding: 0px; margin: 0px; background-color: %1; }").arg(warnColor.name());
m_ui->uasViewFrame->setStyleSheet(style);
}
iconIsRed = !iconIsRed;
}
else
{
// Break alert once everything is back to normal
if (!iconIsRed)
{
setBackgroundColor();
iconIsRed = true;
}
// Fade heartbeat icon // Fade heartbeat icon
// Make color darker // Make color darker
heartbeatColor = heartbeatColor.darker(150); heartbeatColor = heartbeatColor.darker(150);
QString colorstyle; //m_ui->heartbeatIcon->setAutoFillBackground(true);
colorstyle = colorstyle.sprintf("QGroupBox { border: 1px solid #EEEEEE; border-radius: 8px; padding: 0px; margin: 0px; background-color: #%02X%02X%02X;}", m_ui->heartbeatIcon->setStyleSheet(colorstyle.arg(heartbeatColor.name()));
heartbeatColor.red(), heartbeatColor.green(), heartbeatColor.blue()); }
m_ui->heartbeatIcon->setStyleSheet(colorstyle);
m_ui->heartbeatIcon->setAutoFillBackground(true);
//setUpdatesEnabled(true); //setUpdatesEnabled(true);
//setUpdatesEnabled(false); //setUpdatesEnabled(false);
......
...@@ -82,6 +82,8 @@ protected: ...@@ -82,6 +82,8 @@ protected:
QTimer* refreshTimer; QTimer* refreshTimer;
QColor heartbeatColor; QColor heartbeatColor;
quint64 startTime; quint64 startTime;
quint64 lastHeartbeat;
bool iconIsRed;
int timeRemaining; int timeRemaining;
float chargeLevel; float chargeLevel;
UASInterface* uas; UASInterface* uas;
...@@ -100,6 +102,7 @@ protected: ...@@ -100,6 +102,7 @@ protected:
float alt; float alt;
float groundDistance; float groundDistance;
bool localFrame; bool localFrame;
QAction* removeAction;
static const int updateInterval = 300; static const int updateInterval = 300;
...@@ -112,6 +115,7 @@ protected: ...@@ -112,6 +115,7 @@ protected:
void showEvent(QShowEvent* event); void showEvent(QShowEvent* event);
/** @brief Stop widget updating */ /** @brief Stop widget updating */
void hideEvent(QHideEvent* event); void hideEvent(QHideEvent* event);
void contextMenuEvent(QContextMenuEvent* event);
private: private:
Ui::UASView *m_ui; Ui::UASView *m_ui;
......
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