Skip to content

Commit 1b93ada

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 d4ed932 commit 1b93ada

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()),
@@ -479,6 +481,7 @@ MainWindow::MainWindow(QWidget *parent) :
479481
mPollAppTimer.start(int(1000.0 / mSettings.value("poll_rate_app_data", 50).toDouble()));
480482
mPollImuTimer.start(int(1000.0 / mSettings.value("poll_rate_imu_data", 50).toDouble()));
481483
mPollBmsTimer.start(int(1000.0 / mSettings.value("poll_rate_bms_data", 10).toDouble()));
484+
mRepaintDisplayBarTimer.start(100);
482485

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

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

957969
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
@@ -165,12 +165,16 @@ private slots:
165165
bool mKeyRight;
166166
bool mMcConfRead;
167167
bool mAppConfRead;
168+
bool shouldSetDisplayBars;
168169
QMap<QString, int> mPageNameIdList;
169170

170171
QTimer mPollRtTimer;
171172
QTimer mPollAppTimer;
172173
QTimer mPollImuTimer;
173174
QTimer mPollBmsTimer;
175+
QTimer mRepaintDisplayBarTimer;
176+
177+
MC_VALUES mMcValues;
174178

175179
PageWelcome *mPageWelcome;
176180
PageConnection *mPageConnection;

0 commit comments

Comments
 (0)