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)
|
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);
|
QMutexLocker locker(&lcdMtx);
|
||||||
lightEnable = light;
|
lightEnable = light;
|
||||||
if (lcdBuf) memcpy(localBuf, lcdBuf, lcdSize);
|
if (lcdBuf) memcpy(localBuf, lcdBuf, lcdSize);
|
||||||
if (!redrawTimer.isValid() ||
|
dirty = true;
|
||||||
redrawTimer.hasExpired(LCD_WIDGET_REFRESH_PERIOD)) {
|
if (!frameTimer.isActive())
|
||||||
update();
|
frameTimer.start();
|
||||||
redrawTimer.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)
|
void LcdWidget::doPaint(QPainter &p)
|
||||||
|
|||||||
@@ -26,15 +26,16 @@
|
|||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QClipboard>
|
#include <QClipboard>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QElapsedTimer>
|
|
||||||
#include <QMutex>
|
#include <QMutex>
|
||||||
#include <QMutexLocker>
|
#include <QMutexLocker>
|
||||||
#include <QMouseEvent>
|
#include <QMouseEvent>
|
||||||
|
#include <QTimer>
|
||||||
#include <AppDebugMessageHandler>
|
#include <AppDebugMessageHandler>
|
||||||
|
|
||||||
#include "appdata.h"
|
#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
|
class LcdWidget : public QWidget
|
||||||
{
|
{
|
||||||
@@ -50,6 +51,8 @@ class LcdWidget : public QWidget
|
|||||||
bgDefaultColor(QColor(148, 156, 149)),
|
bgDefaultColor(QColor(148, 156, 149)),
|
||||||
fgDefaultColor(QColor(0, 0, 0))
|
fgDefaultColor(QColor(0, 0, 0))
|
||||||
{
|
{
|
||||||
|
frameTimer.setInterval(LCD_WIDGET_REFRESH_PERIOD);
|
||||||
|
connect(&frameTimer, &QTimer::timeout, this, &LcdWidget::onFrameTick);
|
||||||
}
|
}
|
||||||
|
|
||||||
~LcdWidget()
|
~LcdWidget()
|
||||||
@@ -84,8 +87,10 @@ class LcdWidget : public QWidget
|
|||||||
QColor bgDefaultColor;
|
QColor bgDefaultColor;
|
||||||
QColor fgDefaultColor;
|
QColor fgDefaultColor;
|
||||||
QMutex lcdMtx;
|
QMutex lcdMtx;
|
||||||
QElapsedTimer redrawTimer;
|
QTimer frameTimer;
|
||||||
|
bool dirty = false;
|
||||||
|
|
||||||
|
void onFrameTick();
|
||||||
void doPaint(QPainter &p);
|
void doPaint(QPainter &p);
|
||||||
|
|
||||||
void paintEvent(QPaintEvent *) override;
|
void paintEvent(QPaintEvent *) override;
|
||||||
|
|||||||
Reference in New Issue
Block a user