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