Avoid locking application event loop with queued events

This commit is contained in:
Alex Spataru 2024-10-14 00:46:17 -05:00
parent df9044108c
commit def9f91fb8
14 changed files with 18 additions and 33 deletions

View File

@ -133,9 +133,6 @@ Misc::ModuleManager::ModuleManager()
// Stop modules when application is about to quit // Stop modules when application is about to quit
connect(&m_engine, &QQmlApplicationEngine::quit, this, connect(&m_engine, &QQmlApplicationEngine::quit, this,
&Misc::ModuleManager::onQuit); &Misc::ModuleManager::onQuit);
// Use software rendering to avoid crashes
QQuickWindow::setGraphicsApi(QSGRendererInterface::Software);
} }
/** /**

View File

@ -25,7 +25,6 @@
#include "UI/Dashboard.h" #include "UI/Dashboard.h"
#include "MQTT/Client.h" #include "MQTT/Client.h"
#include "Misc/CommonFonts.h" #include "Misc/CommonFonts.h"
#include "Misc/TimerEvents.h"
#include "JSON/FrameBuilder.h" #include "JSON/FrameBuilder.h"
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
@ -50,16 +49,6 @@ UI::Dashboard::Dashboard()
connect(&JSON::FrameBuilder::instance(), connect(&JSON::FrameBuilder::instance(),
&JSON::FrameBuilder::jsonFileMapChanged, this, &JSON::FrameBuilder::jsonFileMapChanged, this,
&UI::Dashboard::resetData); &UI::Dashboard::resetData);
// Update widgets at 20 Hz (max)
connect(&Misc::TimerEvents::instance(), &Misc::TimerEvents::timeout24Hz, this,
[=] {
if (m_updateRequired)
{
m_updateRequired = false;
Q_EMIT updated();
}
});
} }
/** /**
@ -826,7 +815,6 @@ void UI::Dashboard::processFrame(const JSON::Frame &frame)
// Copy frame data // Copy frame data
m_currentFrame = frame; m_currentFrame = frame;
m_updateRequired = true;
// Regenerate plot data // Regenerate plot data
updatePlots(); updatePlots();
@ -908,6 +896,7 @@ void UI::Dashboard::processFrame(const JSON::Frame &frame)
} }
// Share the frame with other models // Share the frame with other models
Q_EMIT updated();
Q_EMIT frameReceived(m_currentFrame); Q_EMIT frameReceived(m_currentFrame);
} }

View File

@ -326,7 +326,6 @@ private:
private: private:
int m_points; int m_points;
int m_precision; int m_precision;
bool m_updateRequired;
AxisVisibility m_axisVisibility; AxisVisibility m_axisVisibility;
QVector<qreal> m_xData; QVector<qreal> m_xData;

View File

@ -54,7 +54,7 @@ Widgets::Accelerometer::Accelerometer(const int index)
// React to dashboard events // React to dashboard events
connect(dash, SIGNAL(updated()), this, SLOT(updateData()), connect(dash, SIGNAL(updated()), this, SLOT(updateData()),
Qt::QueuedConnection); Qt::DirectConnection);
} }
/** /**

View File

@ -59,9 +59,9 @@ Widgets::Bar::Bar(const int index)
// React to dashboard events // React to dashboard events
connect(this, SIGNAL(resized()), this, SLOT(onResized()), connect(this, SIGNAL(resized()), this, SLOT(onResized()),
Qt::QueuedConnection); Qt::DirectConnection);
connect(dash, SIGNAL(updated()), this, SLOT(updateData()), connect(dash, SIGNAL(updated()), this, SLOT(updateData()),
Qt::QueuedConnection); Qt::DirectConnection);
} }
/** /**

View File

@ -67,7 +67,7 @@ Widgets::Compass::Compass(const int index)
// Connect update signal // Connect update signal
connect(dash, &UI::Dashboard::updated, this, &Compass::update, connect(dash, &UI::Dashboard::updated, this, &Compass::update,
Qt::QueuedConnection); Qt::DirectConnection);
} }
/** /**

View File

@ -140,7 +140,7 @@ Widgets::DataGrid::DataGrid(const int index)
// React to dashboard events // React to dashboard events
connect(dash, SIGNAL(updated()), this, SLOT(updateData()), connect(dash, SIGNAL(updated()), this, SLOT(updateData()),
Qt::QueuedConnection); Qt::DirectConnection);
} }
/** /**

View File

@ -82,9 +82,9 @@ Widgets::FFTPlot::FFTPlot(int index)
// Connect update signal // Connect update signal
onAxisOptionsChanged(); onAxisOptionsChanged();
connect(dash, &UI::Dashboard::updated, this, &FFTPlot::updateData, connect(dash, &UI::Dashboard::updated, this, &FFTPlot::updateData,
Qt::QueuedConnection); Qt::DirectConnection);
connect(dash, &UI::Dashboard::axisVisibilityChanged, this, connect(dash, &UI::Dashboard::axisVisibilityChanged, this,
&FFTPlot::onAxisOptionsChanged, Qt::QueuedConnection); &FFTPlot::onAxisOptionsChanged, Qt::DirectConnection);
} }
/** /**

View File

@ -47,7 +47,7 @@ Widgets::GPS::GPS(const int index)
// React to Qt signals // React to Qt signals
connect(dash, SIGNAL(updated()), this, SLOT(updateData()), connect(dash, SIGNAL(updated()), this, SLOT(updateData()),
Qt::QueuedConnection); Qt::DirectConnection);
} }
/** /**

View File

@ -51,7 +51,7 @@ Widgets::Gauge::Gauge(const int index)
// React to dashboard events // React to dashboard events
connect(dash, SIGNAL(updated()), this, SLOT(updateData()), connect(dash, SIGNAL(updated()), this, SLOT(updateData()),
Qt::QueuedConnection); Qt::DirectConnection);
} }
/** /**

View File

@ -55,7 +55,7 @@ Widgets::Gyroscope::Gyroscope(const int index)
// React to dashboard events // React to dashboard events
connect(dash, SIGNAL(updated()), this, SLOT(updateData()), connect(dash, SIGNAL(updated()), this, SLOT(updateData()),
Qt::QueuedConnection); Qt::DirectConnection);
} }
/** /**

View File

@ -119,7 +119,7 @@ Widgets::LEDPanel::LEDPanel(const int index)
// React to dashboard events // React to dashboard events
connect(dash, SIGNAL(updated()), this, SLOT(updateData()), connect(dash, SIGNAL(updated()), this, SLOT(updateData()),
Qt::QueuedConnection); Qt::DirectConnection);
} }
/** /**

View File

@ -88,11 +88,11 @@ Widgets::MultiPlot::MultiPlot(const int index)
// React to dashboard events // React to dashboard events
onAxisOptionsChanged(); onAxisOptionsChanged();
connect(dash, &UI::Dashboard::updated, this, &MultiPlot::updateData, connect(dash, &UI::Dashboard::updated, this, &MultiPlot::updateData,
Qt::QueuedConnection); Qt::DirectConnection);
connect(dash, &UI::Dashboard::pointsChanged, this, &MultiPlot::updateRange, connect(dash, &UI::Dashboard::pointsChanged, this, &MultiPlot::updateRange,
Qt::QueuedConnection); Qt::DirectConnection);
connect(dash, &UI::Dashboard::axisVisibilityChanged, this, connect(dash, &UI::Dashboard::axisVisibilityChanged, this,
&MultiPlot::onAxisOptionsChanged, Qt::QueuedConnection); &MultiPlot::onAxisOptionsChanged, Qt::DirectConnection);
} }
/** /**

View File

@ -84,11 +84,11 @@ Widgets::Plot::Plot(const int index)
// React to dashboard events // React to dashboard events
onAxisOptionsChanged(); onAxisOptionsChanged();
connect(dash, &UI::Dashboard::updated, this, &Plot::updateData, connect(dash, &UI::Dashboard::updated, this, &Plot::updateData,
Qt::QueuedConnection); Qt::DirectConnection);
connect(dash, &UI::Dashboard::pointsChanged, this, &Plot::updateRange, connect(dash, &UI::Dashboard::pointsChanged, this, &Plot::updateRange,
Qt::QueuedConnection); Qt::DirectConnection);
connect(dash, &UI::Dashboard::axisVisibilityChanged, this, connect(dash, &UI::Dashboard::axisVisibilityChanged, this,
&Plot::onAxisOptionsChanged, Qt::QueuedConnection); &Plot::onAxisOptionsChanged, Qt::DirectConnection);
} }
/** /**