From 1dfb5e50213cbaffd386fa9c246b0b67ce5036a5 Mon Sep 17 00:00:00 2001 From: lm Date: Thu, 13 Jan 2011 20:06:04 +0100 Subject: [PATCH] Allowed the removal of UAS objects, added aggressive disconnect warning --- src/comm/SerialLink.cc | 2 +- src/uas/UAS.cc | 6 ++++ src/uas/UASInterface.h | 3 ++ src/ui/MainWindow.cc | 6 +++- src/ui/UASView.ui | 26 ++++++++++++++++- src/ui/uas/UASView.cc | 66 +++++++++++++++++++++++++++++++++++------- src/ui/uas/UASView.h | 4 +++ 7 files changed, 100 insertions(+), 13 deletions(-) diff --git a/src/comm/SerialLink.cc b/src/comm/SerialLink.cc index d6bc78ccf..3cb705466 100644 --- a/src/comm/SerialLink.cc +++ b/src/comm/SerialLink.cc @@ -151,7 +151,7 @@ void SerialLink::run() void SerialLink::checkForBytes() { /* Check if bytes are available */ - if(port && port->isOpen()) + if(port && port->isOpen() && port->isWritable()) { dataMutex.lock(); qint64 available = port->bytesAvailable(); diff --git a/src/uas/UAS.cc b/src/uas/UAS.cc index 1dfb06803..112f31996 100644 --- a/src/uas/UAS.cc +++ b/src/uas/UAS.cc @@ -271,6 +271,12 @@ void UAS::receiveMessage(LinkInterface* link, mavlink_message_t message) GAudioOutput::instance()->stopEmergency(); GAudioOutput::instance()->say(audiostring); } + + if (state.status == MAV_STATE_POWEROFF) + { + emit systemRemoved(this); + emit systemRemoved(); + } } break; case MAVLINK_MSG_ID_RAW_IMU: diff --git a/src/uas/UASInterface.h b/src/uas/UASInterface.h index a35dd96d5..97b1f85a4 100644 --- a/src/uas/UASInterface.h +++ b/src/uas/UASInterface.h @@ -262,6 +262,9 @@ signals: * @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); + /** @brief System has been removed / disconnected / shutdown cleanly, remove */ + void systemRemoved(UASInterface* uas); + void systemRemoved(); /** * @brief Received a plain text message from the robot * This signal should NOT be used for standard communication, but rather for VERY IMPORTANT diff --git a/src/ui/MainWindow.cc b/src/ui/MainWindow.cc index 8be801da3..c1d160e96 100644 --- a/src/ui/MainWindow.cc +++ b/src/ui/MainWindow.cc @@ -1299,7 +1299,11 @@ void MainWindow::UASCreated(UASInterface* uas) 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 if (debugConsoleDockWidget) diff --git a/src/ui/UASView.ui b/src/ui/UASView.ui index 1b0cdea4a..eecc77b37 100644 --- a/src/ui/UASView.ui +++ b/src/ui/UASView.ui @@ -181,7 +181,31 @@ QProgressBar::chunk#speedBar { QProgressBar::chunk#thrustBar { background-color: orange; -} +} + +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; + } diff --git a/src/ui/uas/UASView.cc b/src/ui/uas/UASView.cc index afb1fb0e5..d76b1c7cb 100644 --- a/src/ui/uas/UASView.cc +++ b/src/ui/uas/UASView.cc @@ -31,6 +31,7 @@ This file is part of the PIXHAWK project #include #include #include +#include #include "QGC.h" #include "MG.h" @@ -42,6 +43,8 @@ This file is part of the PIXHAWK project UASView::UASView(UASInterface* uas, QWidget *parent) : QWidget(parent), startTime(0), + lastHeartbeat(0), + iconIsRed(true), timeRemaining(0), chargeLevel(0), uas(uas), @@ -60,6 +63,7 @@ UASView::UASView(UASInterface* uas, QWidget *parent) : alt(0), groundDistance(0), localFrame(false), + removeAction(new QAction("Remove this system", this)), m_ui(new Ui::UASView) { m_ui->setupUi(this); @@ -92,6 +96,10 @@ UASView::UASView(UASInterface* uas, QWidget *parent) : connect(m_ui->abortButton, SIGNAL(clicked()), uas, SLOT(emergencySTOP())); connect(m_ui->killButton, SIGNAL(clicked()), uas, SLOT(emergencyKILL())); 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 @@ -230,12 +238,11 @@ void UASView::hideEvent(QHideEvent* event) void UASView::receiveHeartbeat(UASInterface* uas) { Q_UNUSED(uas); - QString colorstyle; 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;}", - heartbeatColor.red(), heartbeatColor.green(), heartbeatColor.blue()); - m_ui->heartbeatIcon->setStyleSheet(colorstyle); - m_ui->heartbeatIcon->setAutoFillBackground(true); + QString colorstyle("QGroupBox { border-radius: 5px; padding: 2px; margin: 2px; border: 0px; background-color: %1; }"); + m_ui->heartbeatIcon->setStyleSheet(colorstyle.arg(heartbeatColor.name())); + lastHeartbeat = QGC::groundTimeUsecs(); + //m_ui->heartbeatIcon->setAutoFillBackground(true); } /** @@ -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() { //setUpdatesEnabled(false); @@ -494,15 +511,44 @@ void UASView::refresh() } 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 // Make color darker heartbeatColor = heartbeatColor.darker(150); - QString colorstyle; - colorstyle = colorstyle.sprintf("QGroupBox { border: 1px solid #EEEEEE; border-radius: 8px; padding: 0px; margin: 0px; background-color: #%02X%02X%02X;}", - heartbeatColor.red(), heartbeatColor.green(), heartbeatColor.blue()); - m_ui->heartbeatIcon->setStyleSheet(colorstyle); - m_ui->heartbeatIcon->setAutoFillBackground(true); + //m_ui->heartbeatIcon->setAutoFillBackground(true); + m_ui->heartbeatIcon->setStyleSheet(colorstyle.arg(heartbeatColor.name())); + } //setUpdatesEnabled(true); //setUpdatesEnabled(false); diff --git a/src/ui/uas/UASView.h b/src/ui/uas/UASView.h index b96103d16..0f6ca11c1 100644 --- a/src/ui/uas/UASView.h +++ b/src/ui/uas/UASView.h @@ -82,6 +82,8 @@ protected: QTimer* refreshTimer; QColor heartbeatColor; quint64 startTime; + quint64 lastHeartbeat; + bool iconIsRed; int timeRemaining; float chargeLevel; UASInterface* uas; @@ -100,6 +102,7 @@ protected: float alt; float groundDistance; bool localFrame; + QAction* removeAction; static const int updateInterval = 300; @@ -112,6 +115,7 @@ protected: void showEvent(QShowEvent* event); /** @brief Stop widget updating */ void hideEvent(QHideEvent* event); + void contextMenuEvent(QContextMenuEvent* event); private: Ui::UASView *m_ui; -- 2.22.0