File tree Expand file tree Collapse file tree 2 files changed +20
-1
lines changed Expand file tree Collapse file tree 2 files changed +20
-1
lines changed Original file line number Diff line number Diff 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
5267void 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
5974QSize RtDataText::sizeHint () const
Original file line number Diff line number Diff line change 2121#define RTDATATEXT_H
2222
2323#include < QWidget>
24+ #include < QTimer>
2425#include " datatypes.h"
2526
2627class 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
You can’t perform that action at this time.
0 commit comments