fix(simulator): sample LCD at a fixed cadence so the final frame is always painted (#7504)
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
3d189a901c
commit
f67d1665ea
@@ -71,14 +71,26 @@ void LcdWidget::makeScreenshot(const QString &fileName)
|
||||
|
||||
void LcdWidget::onLcdChanged(uint8_t* lcdBuf, bool light)
|
||||
{
|
||||
// Ingest only: store the latest frame and let frameTimer drive the repaint.
|
||||
// Sampling on a fixed cadence caps the repaint rate without dropping the
|
||||
// final frame of a burst, regardless of how frames are delivered.
|
||||
QMutexLocker locker(&lcdMtx);
|
||||
lightEnable = light;
|
||||
if (lcdBuf) memcpy(localBuf, lcdBuf, lcdSize);
|
||||
if (!redrawTimer.isValid() ||
|
||||
redrawTimer.hasExpired(LCD_WIDGET_REFRESH_PERIOD)) {
|
||||
update();
|
||||
redrawTimer.start();
|
||||
dirty = true;
|
||||
if (!frameTimer.isActive())
|
||||
frameTimer.start();
|
||||
}
|
||||
|
||||
void LcdWidget::onFrameTick()
|
||||
{
|
||||
QMutexLocker locker(&lcdMtx);
|
||||
if (!dirty) { // idle: stop until the next frame arrives
|
||||
frameTimer.stop();
|
||||
return;
|
||||
}
|
||||
dirty = false;
|
||||
update();
|
||||
}
|
||||
|
||||
void LcdWidget::doPaint(QPainter &p)
|
||||
|
||||
@@ -26,15 +26,16 @@
|
||||
#include <QPainter>
|
||||
#include <QClipboard>
|
||||
#include <QDir>
|
||||
#include <QElapsedTimer>
|
||||
#include <QMutex>
|
||||
#include <QMutexLocker>
|
||||
#include <QMouseEvent>
|
||||
#include <QTimer>
|
||||
#include <AppDebugMessageHandler>
|
||||
|
||||
#include "appdata.h"
|
||||
|
||||
#define LCD_WIDGET_REFRESH_PERIOD 16 // [ms] 16 = 62.5fps
|
||||
#define LCD_WIDGET_REFRESH_PERIOD 10 // [ms] 10 = 100fps cap (color is
|
||||
// firmware-limited to ~20fps anyway)
|
||||
|
||||
class LcdWidget : public QWidget
|
||||
{
|
||||
@@ -50,6 +51,8 @@ class LcdWidget : public QWidget
|
||||
bgDefaultColor(QColor(148, 156, 149)),
|
||||
fgDefaultColor(QColor(0, 0, 0))
|
||||
{
|
||||
frameTimer.setInterval(LCD_WIDGET_REFRESH_PERIOD);
|
||||
connect(&frameTimer, &QTimer::timeout, this, &LcdWidget::onFrameTick);
|
||||
}
|
||||
|
||||
~LcdWidget()
|
||||
@@ -84,8 +87,10 @@ class LcdWidget : public QWidget
|
||||
QColor bgDefaultColor;
|
||||
QColor fgDefaultColor;
|
||||
QMutex lcdMtx;
|
||||
QElapsedTimer redrawTimer;
|
||||
QTimer frameTimer;
|
||||
bool dirty = false;
|
||||
|
||||
void onFrameTick();
|
||||
void doPaint(QPainter &p);
|
||||
|
||||
void paintEvent(QPaintEvent *) override;
|
||||
|
||||
Reference in New Issue
Block a user