Skip to content

Commit 0d4136f

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 e82b3fb commit 0d4136f

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

mainwindow.cpp

Lines changed: 15 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+
shouldUpdateDisplayBars = false;
223+
222224
connect(mDebugTimer, SIGNAL(timeout()),
223225
this, SLOT(timerSlotDebugMsg()));
224226
connect(mTimer, SIGNAL(timeout()),
@@ -481,6 +483,8 @@ MainWindow::MainWindow(QWidget *parent) :
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()));
483485

486+
mRepaintDisplayBarTimer.start(1000.0/30); // Set the refresh rate to 30Hz
487+
484488
connect(&mPollRtTimer, &QTimer::timeout, [this]() {
485489
if (ui->actionRtData->isChecked()) {
486490
mVesc->commands()->getValues();
@@ -514,6 +518,15 @@ MainWindow::MainWindow(QWidget *parent) :
514518
}
515519
});
516520

521+
connect(&mRepaintDisplayBarTimer, &QTimer::timeout, [this]() {
522+
if (shouldUpdateDisplayBars) {
523+
ui->dispCurrent->setVal(mMcValues.current_motor);
524+
ui->dispDuty->setVal(mMcValues.duty_now * 100.0);
525+
526+
shouldUpdateDisplayBars = false;
527+
}
528+
});
529+
517530
// Restore size and position
518531
if (mSettings.contains("mainwindow/size")) {
519532
resize(mSettings.value("mainwindow/size").toSize());
@@ -951,8 +964,8 @@ void MainWindow::serialPortNotWritable(const QString &port)
951964
void MainWindow::valuesReceived(MC_VALUES values, unsigned int mask)
952965
{
953966
(void)mask;
954-
ui->dispCurrent->setVal(values.current_motor);
955-
ui->dispDuty->setVal(values.duty_now * 100.0);
967+
mMcValues = values;
968+
shouldUpdateDisplayBars = true;
956969
}
957970

958971
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 shouldUpdateDisplayBars;
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)