Commit d6bcee73 authored by Don Gagne's avatar Don Gagne

Delay creation of MAVLinkDecoder until it is needed

Helps battery life
parent 257fc085
......@@ -108,10 +108,11 @@ void MainWindow::deleteInstance(void)
/// by MainWindow::_create method. Hence no other code should have access to
/// constructor.
MainWindow::MainWindow()
: _lowPowerMode(false)
, _showStatusBar(false)
, _mainQmlWidgetHolder(NULL)
, _forceClose(false)
: _mavlinkDecoder (NULL)
, _lowPowerMode (false)
, _showStatusBar (false)
, _mainQmlWidgetHolder (NULL)
, _forceClose (false)
{
_instance = this;
......@@ -272,10 +273,13 @@ MainWindow::MainWindow()
MainWindow::~MainWindow()
{
// Enforce thread-safe shutdown of the mavlink decoder
mavlinkDecoder->finish();
mavlinkDecoder->wait(1000);
mavlinkDecoder->deleteLater();
if (_mavlinkDecoder) {
// Enforce thread-safe shutdown of the mavlink decoder
_mavlinkDecoder->finish();
_mavlinkDecoder->wait(1000);
_mavlinkDecoder->deleteLater();
_mavlinkDecoder = NULL;
}
// This needs to happen before we get into the QWidget dtor
// otherwise the QML engine reads freed data and tries to
......@@ -290,12 +294,18 @@ QString MainWindow::_getWindowGeometryKey()
}
#ifndef __mobile__
void MainWindow::_buildCommonWidgets(void)
MAVLinkDecoder* MainWindow::_mavLinkDecoderInstance(void)
{
// Add generic MAVLink decoder
mavlinkDecoder = new MAVLinkDecoder(qgcApp()->toolbox()->mavlinkProtocol());
connect(mavlinkDecoder.data(), &MAVLinkDecoder::valueChanged, this, &MainWindow::valueChanged);
if (_mavlinkDecoder) {
_mavlinkDecoder = new MAVLinkDecoder(qgcApp()->toolbox()->mavlinkProtocol());
connect(_mavlinkDecoder, &MAVLinkDecoder::valueChanged, this, &MainWindow::valueChanged);
}
return _mavlinkDecoder;
}
void MainWindow::_buildCommonWidgets(void)
{
// Log player
// TODO: Make this optional with a preferences setting or under a "View" menu
logPlayer = new QGCMAVLinkLogPlayer(statusBar());
......@@ -363,7 +373,7 @@ bool MainWindow::_createInnerDockWidget(const QString& widgetName)
widget = new HILDockWidget(widgetName, action, this);
break;
case ANALYZE:
widget = new Linecharts(widgetName, action, mavlinkDecoder, this);
widget = new Linecharts(widgetName, action, _mavLinkDecoderInstance(), this);
break;
}
if(widget) {
......
......@@ -127,7 +127,6 @@ protected:
QSettings settings;
QPointer<MAVLinkDecoder> mavlinkDecoder;
QGCMAVLinkLogPlayer* logPlayer;
#ifdef QGC_MOUSE_ENABLED_WIN
/** @brief 3d Mouse support (WIN only) */
......@@ -181,7 +180,9 @@ private:
void _showDockWidget(const QString &name, bool show);
void _loadVisibleWidgetsSettings(void);
void _storeVisibleWidgetsSettings(void);
MAVLinkDecoder* _mavLinkDecoderInstance(void);
MAVLinkDecoder* _mavlinkDecoder;
bool _lowPowerMode; ///< If enabled, QGC reduces the update rates of all widgets
bool _showStatusBar;
QVBoxLayout* _centralLayout;
......
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