From c37403a4800f24d0c2ea93ca3c8864edf9a481e3 Mon Sep 17 00:00:00 2001 From: edouard Date: Thu, 20 Jan 2011 22:30:49 +0000 Subject: [PATCH] OP-263 Scopes now only run when telemetry is connected. git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@2495 ebee16cc-31ac-478f-84a7-5cbb03baadba --- .../src/plugins/scope/ScopeGadget.pluginspec | 2 + ground/src/plugins/scope/scope.pro | 45 +++++++++--------- .../src/plugins/scope/scopegadgetwidget.cpp | 46 ++++++++++++++++--- ground/src/plugins/scope/scopegadgetwidget.h | 6 +-- 4 files changed, 67 insertions(+), 32 deletions(-) diff --git a/ground/src/plugins/scope/ScopeGadget.pluginspec b/ground/src/plugins/scope/ScopeGadget.pluginspec index 9f6ae0947..d0c0b9dc1 100644 --- a/ground/src/plugins/scope/ScopeGadget.pluginspec +++ b/ground/src/plugins/scope/ScopeGadget.pluginspec @@ -6,5 +6,7 @@ http://www.openpilot.org + + diff --git a/ground/src/plugins/scope/scope.pro b/ground/src/plugins/scope/scope.pro index 85c485fa1..c3e023d7a 100644 --- a/ground/src/plugins/scope/scope.pro +++ b/ground/src/plugins/scope/scope.pro @@ -1,22 +1,23 @@ -TEMPLATE = lib -TARGET = ScopeGadget -include(../../openpilotgcsplugin.pri) -include(../../plugins/coreplugin/coreplugin.pri) -include(../../plugins/uavobjects/uavobjects.pri) -include(../../libs/qwt/qwt.pri) -HEADERS += scopeplugin.h \ - plotdata.h -HEADERS += scopegadgetoptionspage.h -HEADERS += scopegadgetconfiguration.h -HEADERS += scopegadget.h -HEADERS += scopegadgetwidget.h -HEADERS += scopegadgetfactory.h -SOURCES += scopeplugin.cpp \ - plotdata.cpp -SOURCES += scopegadgetoptionspage.cpp -SOURCES += scopegadgetconfiguration.cpp -SOURCES += scopegadget.cpp -SOURCES += scopegadgetfactory.cpp -SOURCES += scopegadgetwidget.cpp -OTHER_FILES += ScopeGadget.pluginspec -FORMS += scopegadgetoptionspage.ui +TEMPLATE = lib +TARGET = ScopeGadget +include(../../openpilotgcsplugin.pri) +include(../../plugins/coreplugin/coreplugin.pri) +include(../../plugins/uavobjects/uavobjects.pri) +include(../../plugins/uavtalk/uavtalk.pri) +include(../../libs/qwt/qwt.pri) +HEADERS += scopeplugin.h \ + plotdata.h +HEADERS += scopegadgetoptionspage.h +HEADERS += scopegadgetconfiguration.h +HEADERS += scopegadget.h +HEADERS += scopegadgetwidget.h +HEADERS += scopegadgetfactory.h +SOURCES += scopeplugin.cpp \ + plotdata.cpp +SOURCES += scopegadgetoptionspage.cpp +SOURCES += scopegadgetconfiguration.cpp +SOURCES += scopegadget.cpp +SOURCES += scopegadgetfactory.cpp +SOURCES += scopegadgetwidget.cpp +OTHER_FILES += ScopeGadget.pluginspec +FORMS += scopegadgetoptionspage.ui diff --git a/ground/src/plugins/scope/scopegadgetwidget.cpp b/ground/src/plugins/scope/scopegadgetwidget.cpp index 4ebe424f4..f76228b79 100644 --- a/ground/src/plugins/scope/scopegadgetwidget.cpp +++ b/ground/src/plugins/scope/scopegadgetwidget.cpp @@ -26,11 +26,16 @@ */ -#include "uavobjects/uavobjectmanager.h" -#include "extensionsystem/pluginmanager.h" #include "scopegadgetwidget.h" #include "utils/stylehelper.h" +#include "uavtalk/telemetrymanager.h" +#include "extensionsystem/pluginmanager.h" +#include "uavobjects/uavobjectmanager.h" +#include "uavobjects/uavobject.h" +#include "coreplugin/icore.h" +#include "coreplugin/connectionmanager.h" + #include "qwt/src/qwt_plot_curve.h" #include "qwt/src/qwt_legend.h" #include "qwt/src/qwt_legend_item.h" @@ -45,6 +50,7 @@ #include #include +using namespace Core; TestDataGen* ScopeGadgetWidget::testDataGen; @@ -56,6 +62,28 @@ ScopeGadgetWidget::ScopeGadgetWidget(QWidget *parent) : QwtPlot(parent) //Setup the timer that replots data replotTimer = new QTimer(this); connect(replotTimer, SIGNAL(timeout()), this, SLOT(replotNewData())); + + // Listen to telemetry connection/disconnection events, no point + // running the scopes if we are not connected and not replaying logs + // Also listen to disconnect actions from the user + Core::ConnectionManager *cm = Core::ICore::instance()->connectionManager(); + connect(cm, SIGNAL(deviceDisconnected()), this, SLOT(onTelemetryDisconnected())); + connect(cm, SIGNAL(deviceConnected(QIODevice*)), this, SLOT(onTelemetryConnected())); + +} + +/** + * Starts/stops telemetry + */ +void ScopeGadgetWidget::onTelemetryConnected() +{ + if(!replotTimer->isActive()) + replotTimer->start(m_refreshInterval); +} + +void ScopeGadgetWidget::onTelemetryDisconnected() +{ + replotTimer->stop(); } void ScopeGadgetWidget::preparePlot(PlotType plotType) @@ -87,11 +115,15 @@ void ScopeGadgetWidget::preparePlot(PlotType plotType) connect(this, SIGNAL(legendChecked(QwtPlotItem *, bool)),this, SLOT(showCurve(QwtPlotItem *, bool))); - if(!replotTimer->isActive()) - replotTimer->start(m_refreshInterval); - else - { - replotTimer->setInterval(m_refreshInterval); + // Only start the timer if we are already connected + Core::ConnectionManager *cm = Core::ICore::instance()->connectionManager(); + if (cm->getCurrentConnection()) { + if(!replotTimer->isActive()) + replotTimer->start(m_refreshInterval); + else + { + replotTimer->setInterval(m_refreshInterval); + } } } diff --git a/ground/src/plugins/scope/scopegadgetwidget.h b/ground/src/plugins/scope/scopegadgetwidget.h index 7bddb1aab..936addd0d 100644 --- a/ground/src/plugins/scope/scopegadgetwidget.h +++ b/ground/src/plugins/scope/scopegadgetwidget.h @@ -29,9 +29,6 @@ #define SCOPEGADGETWIDGET_H_ #include "plotdata.h" -#include "uavobjects/uavobject.h" -#include "uavobjects/baroaltitude.h" -#include "uavobjects/positionactual.h" #include "qwt/src/qwt.h" @@ -44,6 +41,7 @@ #include #include + /*! \brief This class is used to render the time values on the horizontal axis for the ChronoPlot. @@ -122,6 +120,8 @@ private slots: void uavObjectReceived(UAVObject*); void replotNewData(); void showCurve(QwtPlotItem *item, bool on); + void onTelemetryConnected(); + void onTelemetryDisconnected(); private: