1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-01-29 14:52:12 +01:00

TelemetryMonitorWidget: Alpha version with 12 dots.

This commit is contained in:
Mike LaBranche 2012-08-02 16:11:18 -07:00
parent 4c3c94eba5
commit 63e5fc80ce
8 changed files with 239 additions and 4 deletions

View File

@ -31,9 +31,9 @@
#include <aggregation/aggregate.h>
#include <coreplugin/iconnection.h>
#include <extensionsystem/pluginmanager.h>
#include "qextserialport/src/qextserialenumerator.h"
#include "qextserialport/src/qextserialport.h"
#include <QDebug>
#include <QLabel>
#include <QHBoxLayout>
@ -59,6 +59,10 @@ ConnectionManager::ConnectionManager(Internal::MainWindow *mainWindow, QTabWidge
QHBoxLayout *layout = new QHBoxLayout;
layout->setSpacing(5);
layout->setContentsMargins(5,5,5,5);
m_monitor = new TelemetryMonitorWidget(this);
layout->addWidget(m_monitor);
layout->addWidget(new QLabel(tr("Connections:")));
m_availableDevList = new QComboBox;
@ -140,6 +144,10 @@ bool ConnectionManager::connectDevice()
emit deviceConnected(m_ioDev);
m_connectBtn->setText("Disconnect");
m_availableDevList->setEnabled(false);
// tell the monitor we're connected
m_monitor->connect();
return true;
}
@ -168,6 +176,9 @@ bool ConnectionManager::disconnectDevice()
qDebug() << "Exception: m_connectionDevice.connection->closeDevice(" << m_connectionDevice.devName << ")";
}
//tell the monitor we're disconnected
m_monitor->disconnect();
m_connectionDevice.connection = NULL;
m_ioDev = NULL;
@ -239,6 +250,14 @@ void ConnectionManager::onConnectClicked()
}
}
/**
* Slot called when the telemetry rates are updated
*/
void ConnectionManager::telemetryUpdated(double txRate, double rxRate)
{
m_monitor->updateTelemetry(txRate, rxRate);
}
/**
* Find a device by its displayed (visible on screen) name
*/

View File

@ -32,6 +32,8 @@
#include <QWidget>
#include "mainwindow.h"
#include "generalsettings.h"
#include "telemetrymonitorwidget.h"
#include <QtCore/QVector>
#include <QtCore/QIODevice>
#include <QtCore/QLinkedList>
@ -63,7 +65,6 @@ struct devListItem
QString displayName;
};
class CORE_EXPORT ConnectionManager : public QWidget
{
Q_OBJECT
@ -89,6 +90,9 @@ signals:
void deviceConnected(QIODevice *dev);
void deviceAboutToDisconnect();
public slots:
void telemetryUpdated(double txRate, double rxRate);
private slots:
void objectAdded(QObject *obj);
void aboutToRemoveObject(QObject *obj);
@ -105,6 +109,9 @@ protected:
QLinkedList<devListItem> m_devList;
QList<IConnection*> m_connectionsList;
//tx/rx telemetry monitor
TelemetryMonitorWidget* m_monitor;
//currently connected connection plugin
devListItem m_connectionDevice;

View File

@ -62,5 +62,6 @@
<file>OpenPilotGCS.xml</file>
<file>images/helpicon.svg</file>
<file>images/cpu.png</file>
<file>images/tx-rx.svg</file>
</qresource>
</RCC>

View File

@ -62,7 +62,8 @@ SOURCES += mainwindow.cpp \
uavgadgetdecorator.cpp \
workspacesettings.cpp \
uavconfiginfo.cpp \
authorsdialog.cpp
authorsdialog.cpp \
telemetrymonitorwidget.cpp
HEADERS += mainwindow.h \
tabpositionindicator.h \
fancyactionbar.h \
@ -122,7 +123,8 @@ HEADERS += mainwindow.h \
workspacesettings.h \
uavconfiginfo.h \
authorsdialog.h \
iconfigurableplugin.h
iconfigurableplugin.h \
telemetrymonitorwidget.h
FORMS += dialogs/settingsdialog.ui \
dialogs/shortcutsettings.ui \
generalsettings.ui \

View File

@ -0,0 +1,145 @@
#include "telemetrymonitorwidget.h"
#include <QObject>
#include <QtGui>
#include <QDebug>
TelemetryMonitorWidget::TelemetryMonitorWidget(QWidget *parent) : QGraphicsView(parent)
{
setMinimumSize(160,60);
setMaximumSize(160,60);
setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setFrameStyle(QFrame::NoFrame);
setBackgroundBrush(Qt::transparent);
QGraphicsScene *scene = new QGraphicsScene(0,0,160,60, this);
scene->setBackgroundBrush(Qt::transparent);
QSvgRenderer *renderer = new QSvgRenderer();
if (renderer->load(QString(":/core/images/tx-rx.svg"))) {
graph = new QGraphicsSvgItem();
graph->setSharedRenderer(renderer);
graph->setElementId("txrxBackground");
QString name;
QGraphicsSvgItem* pt;
for (int i=0; i<NODE_NUMELEM; i++) {
name = QString("tx%0").arg(i);
if (renderer->elementExists(name)) {
pt = new QGraphicsSvgItem();
pt->setSharedRenderer(renderer);
pt->setElementId(name);
pt->setParentItem(graph);
txNodes.append(pt);
}
name = QString("rx%0").arg(i);
if (renderer->elementExists(name)) {
pt = new QGraphicsSvgItem();
pt->setSharedRenderer(renderer);
pt->setElementId(name);
pt->setParentItem(graph);
rxNodes.append(pt);
}
}
scene->addItem(graph);
scene->setSceneRect(graph->boundingRect());
setScene(scene);
}
connected = false;
txValue = 0.0;
rxValue = 0.0;
setMin(0.0);
setMax(1200.0);
showTelemetry();
}
TelemetryMonitorWidget::~TelemetryMonitorWidget()
{
while (!txNodes.isEmpty())
delete txNodes.takeFirst();
while (!rxNodes.isEmpty())
delete rxNodes.takeFirst();
}
void TelemetryMonitorWidget::connect()
{
connected = true;
//flash the lights
updateTelemetry(maxValue, maxValue);
}
void TelemetryMonitorWidget::disconnect()
{
//flash the lights
updateTelemetry(maxValue, maxValue);
connected = false;
updateTelemetry(0.0,0.0);
}
/*!
\brief Called by the UAVObject which got updated
Updates the numeric value and/or the icon if the dial wants this.
*/
void TelemetryMonitorWidget::updateTelemetry(double txRate, double rxRate)
{
txValue = txRate;
rxValue = rxRate;
showTelemetry();
}
// Converts the value into an percentage:
// this enables smooth movement in moveIndex below
void TelemetryMonitorWidget::showTelemetry()
{
txIndex = (txValue-minValue)/(maxValue-minValue) * NODE_NUMELEM;
rxIndex = (rxValue-minValue)/(maxValue-minValue) * NODE_NUMELEM;
if (connected)
this->setToolTip(QString("Tx: %0 bytes/sec\nRx: %1 bytes/sec").arg(txValue).arg(rxValue));
else
this->setToolTip(QString("Disconnected"));
QGraphicsItem* txNode;
QGraphicsItem* rxNode;
for (int i=0; i < NODE_NUMELEM; i++) {
txNode = txNodes.at(i);
txNode->setPos((i*(txNode->boundingRect().width() + 8)) + 8, (txNode->boundingRect().height()/2) - 2);
txNode->setVisible(connected && i < txIndex);
txNode->update();
rxNode = rxNodes.at(i);
rxNode->setPos((i*(rxNode->boundingRect().width() + 8)) + 8, (rxNode->boundingRect().height()*2) - 2);
rxNode->setVisible(connected && i < rxIndex);
rxNode->update();
}
update();
}
void TelemetryMonitorWidget::showEvent(QShowEvent *event)
{
Q_UNUSED(event);
fitInView(graph, Qt::KeepAspectRatio);
}
void TelemetryMonitorWidget::resizeEvent(QResizeEvent* event)
{
Q_UNUSED(event);
graph->setPos(0,-90);
fitInView(graph, Qt::KeepAspectRatio);
}

View File

@ -0,0 +1,53 @@
#ifndef TELEMETRYMONITORWIDGET_H
#define TELEMETRYMONITORWIDGET_H
#include <QWidget>
#include <QObject>
#include <QGraphicsView>
#include <QtSvg/QSvgRenderer>
#include <QtSvg/QGraphicsSvgItem>
#include <QtCore/QPointer>
class TelemetryMonitorWidget : public QGraphicsView
{
Q_OBJECT
public:
explicit TelemetryMonitorWidget(QWidget *parent = 0);
~TelemetryMonitorWidget();
void setMin(double min) { minValue = min;}
double getMin() { return minValue; }
void setMax(double max) { maxValue = max;}
double getMax() { return maxValue; }
//number of tx/rx nodes in the graph
static const int NODE_NUMELEM = 12;
signals:
public slots:
void connect();
void disconnect();
void updateTelemetry(double txRate, double rxRate);
void showTelemetry();
protected:
void showEvent(QShowEvent *event);
void resizeEvent(QResizeEvent *event);
private:
QGraphicsSvgItem *graph;
QList<QGraphicsSvgItem*> txNodes;
QList<QGraphicsSvgItem*> rxNodes;
bool connected;
double txIndex;
double txValue;
double rxIndex;
double rxValue;
double minValue;
double maxValue;
};
#endif // TELEMETRYMONITORWIDGET_H

View File

@ -27,6 +27,8 @@
#include "telemetrymonitor.h"
#include "qxtlogger.h"
#include "coreplugin/connectionmanager.h"
#include "coreplugin/icore.h"
/**
* Constructor
@ -52,6 +54,9 @@ TelemetryMonitor::TelemetryMonitor(UAVObjectManager* objMngr, Telemetry* tel)
statsTimer = new QTimer(this);
connect(statsTimer, SIGNAL(timeout()), this, SLOT(processStatsUpdates()));
statsTimer->start(STATS_CONNECT_PERIOD_MS);
Core::ConnectionManager *cm = Core::ICore::instance()->connectionManager();
connect(this,SIGNAL(telemetryUpdated(double,double)),cm,SLOT(telemetryUpdated(double,double)));
}
TelemetryMonitor::~TelemetryMonitor() {
@ -232,6 +237,8 @@ void TelemetryMonitor::processStatsUpdates()
}
}
emit telemetryUpdated((double)gcsStats.TxDataRate, (double)gcsStats.RxDataRate);
// Set data
gcsStatsObj->setData(gcsStats);

View File

@ -51,6 +51,7 @@ public:
signals:
void connected();
void disconnected();
void telemetryUpdated(double txRate, double rxRate);
public slots:
void transactionCompleted(UAVObject* obj, bool success);