Skip to content

Commit e82b3fb

Browse files
committed
[Realtime data][text readout] Repaint at a reduced frequency
1 parent 0feef3a commit e82b3fb

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

widgets/rtdatatext.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ RtDataText::RtDataText(QWidget *parent) : QWidget(parent)
2929
mBoxH = 10;
3030
mBoxW = 10;
3131
mTxtOfs = 2;
32+
shouldUpdate_flag = false;
3233

3334
mValues.amp_hours = 0;
3435
mValues.amp_hours_charged = 0;
@@ -47,13 +48,27 @@ RtDataText::RtDataText(QWidget *parent) : QWidget(parent)
4748
mValues.v_in = 0;
4849
mValues.watt_hours = 0;
4950
mValues.watt_hours_charged = 0;
51+
52+
// Create a timer to control the text repaint rate
53+
mTimer = new QTimer(this);
54+
mTimer->setInterval(1000.0/30); // Set refresh rate to 30Hz
55+
mTimer->start();
56+
57+
QObject::connect(mTimer, &QTimer::timeout, [&]() {
58+
// Check if data should be repainted
59+
if (shouldUpdate_flag == true){
60+
// Trigger the repaint
61+
update();
62+
shouldUpdate_flag = false;
63+
}
64+
});
5065
}
5166

5267
void RtDataText::setValues(const MC_VALUES &values)
5368
{
5469
mValues = values;
5570
mValues.fault_str.remove(0, 11);
56-
update();
71+
shouldUpdate_flag = true;
5772
}
5873

5974
QSize RtDataText::sizeHint() const

widgets/rtdatatext.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#define RTDATATEXT_H
2222

2323
#include <QWidget>
24+
#include <QTimer>
2425
#include "datatypes.h"
2526

2627
class RtDataText : public QWidget
@@ -45,6 +46,9 @@ public slots:
4546
int mBoxH;
4647
int mBoxW;
4748
int mTxtOfs;
49+
bool shouldUpdate_flag;
50+
51+
QTimer *mTimer;
4852

4953
};
5054

0 commit comments

Comments
 (0)