Browse Source

Allowed the removal of UAS objects, added aggressive disconnect warning

QGC4.4
lm 14 years ago
parent
commit
1dfb5e5021
  1. 2
      src/comm/SerialLink.cc
  2. 6
      src/uas/UAS.cc
  3. 3
      src/uas/UASInterface.h
  4. 6
      src/ui/MainWindow.cc
  5. 26
      src/ui/UASView.ui
  6. 66
      src/ui/uas/UASView.cc
  7. 4
      src/ui/uas/UASView.h

2
src/comm/SerialLink.cc

@ -151,7 +151,7 @@ void SerialLink::run() @@ -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();

6
src/uas/UAS.cc

@ -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()->say(audiostring);
}
if (state.status == MAV_STATE_POWEROFF)
{
emit systemRemoved(this);
emit systemRemoved();
}
}
break;
case MAVLINK_MSG_ID_RAW_IMU:

3
src/uas/UASInterface.h

@ -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.
*/
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

6
src/ui/MainWindow.cc

@ -1299,7 +1299,11 @@ void MainWindow::UASCreated(UASInterface* uas) @@ -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)

26
src/ui/UASView.ui

@ -181,7 +181,31 @@ QProgressBar::chunk#speedBar { @@ -181,7 +181,31 @@ QProgressBar::chunk#speedBar {
QProgressBar::chunk#thrustBar {
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>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<property name="spacing">

66
src/ui/uas/UASView.cc

@ -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 <QDateTime>
#include <QDebug>
#include <QMenu>
#include "QGC.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) :
QWidget(parent),
startTime(0),
lastHeartbeat(0),
iconIsRed(true),
timeRemaining(0),
chargeLevel(0),
uas(uas),
@ -60,6 +63,7 @@ UASView::UASView(UASInterface* uas, QWidget *parent) : @@ -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) : @@ -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) @@ -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) @@ -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() @@ -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);

4
src/ui/uas/UASView.h

@ -82,6 +82,8 @@ protected: @@ -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: @@ -100,6 +102,7 @@ protected:
float alt;
float groundDistance;
bool localFrame;
QAction* removeAction;
static const int updateInterval = 300;
@ -112,6 +115,7 @@ protected: @@ -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;

Loading…
Cancel
Save