Skip to content

Commit 13302b3

Browse files
committed
[MainWindow] Repaint display bars at a reduced frequency
Too high of a frequency can't be easily read and burns up lots of CPU in redraw events.
1 parent 08d8851 commit 13302b3

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

mainwindow.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,8 @@ MainWindow::MainWindow(QWidget *parent) :
219219
mKeyLeft = false;
220220
mKeyRight = false;
221221

222+
shouldSetDisplayBars = false;
223+
222224
connect(mDebugTimer, SIGNAL(timeout()),
223225
this, SLOT(timerSlotDebugMsg()));
224226
connect(mTimer, SIGNAL(timeout()),
@@ -480,6 +482,7 @@ MainWindow::MainWindow(QWidget *parent) :
480482
mPollAppTimer.start(int(1000.0 / mSettings.value("poll_rate_app_data", 50).toDouble()));
481483
mPollImuTimer.start(int(1000.0 / mSettings.value("poll_rate_imu_data", 50).toDouble()));
482484
mPollBmsTimer.start(int(1000.0 / mSettings.value("poll_rate_bms_data", 10).toDouble()));
485+
mRepaintDisplayBarTimer.start(100);
483486

484487
connect(&mPollRtTimer, &QTimer::timeout, [this]() {
485488
if (ui->actionRtData->isChecked()) {
@@ -514,6 +517,15 @@ MainWindow::MainWindow(QWidget *parent) :
514517
}
515518
});
516519

520+
connect(&mRepaintDisplayBarTimer, &QTimer::timeout, [this]() {
521+
if (shouldSetDisplayBars) {
522+
ui->dispCurrent->setVal(mMcValues.current_motor);
523+
ui->dispDuty->setVal(mMcValues.duty_now * 100.0);
524+
525+
shouldSetDisplayBars = false;
526+
}
527+
});
528+
517529
// Restore size and position
518530
if (mSettings.contains("mainwindow/size")) {
519531
resize(mSettings.value("mainwindow/size").toSize());
@@ -951,8 +963,8 @@ void MainWindow::serialPortNotWritable(const QString &port)
951963
void MainWindow::valuesReceived(MC_VALUES values, unsigned int mask)
952964
{
953965
(void)mask;
954-
ui->dispCurrent->setVal(values.current_motor);
955-
ui->dispDuty->setVal(values.duty_now * 100.0);
966+
mMcValues = values;
967+
shouldSetDisplayBars = true;
956968
}
957969

958970
void MainWindow::paramChangedDouble(QObject *src, QString name, double newParam)

mainwindow.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,12 +166,16 @@ private slots:
166166
bool mKeyRight;
167167
bool mMcConfRead;
168168
bool mAppConfRead;
169+
bool shouldSetDisplayBars;
169170
QMap<QString, int> mPageNameIdList;
170171

171172
QTimer mPollRtTimer;
172173
QTimer mPollAppTimer;
173174
QTimer mPollImuTimer;
174175
QTimer mPollBmsTimer;
176+
QTimer mRepaintDisplayBarTimer;
177+
178+
MC_VALUES mMcValues;
175179

176180
PageWelcome *mPageWelcome;
177181
PageConnection *mPageConnection;

0 commit comments

Comments
 (0)