Skip to content

Commit

Permalink
[MainWindow] Repaint display bars at a reduced frequency
Browse files Browse the repository at this point in the history
Too high of a frequency can't be easily read and burns up lots of CPU in
redraw events.
  • Loading branch information
kubark42 committed Jan 20, 2022
1 parent d4ed932 commit 1b93ada
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
16 changes: 14 additions & 2 deletions mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,8 @@ MainWindow::MainWindow(QWidget *parent) :
mKeyLeft = false;
mKeyRight = false;

shouldSetDisplayBars = false;

connect(mDebugTimer, SIGNAL(timeout()),
this, SLOT(timerSlotDebugMsg()));
connect(mTimer, SIGNAL(timeout()),
Expand Down Expand Up @@ -479,6 +481,7 @@ MainWindow::MainWindow(QWidget *parent) :
mPollAppTimer.start(int(1000.0 / mSettings.value("poll_rate_app_data", 50).toDouble()));
mPollImuTimer.start(int(1000.0 / mSettings.value("poll_rate_imu_data", 50).toDouble()));
mPollBmsTimer.start(int(1000.0 / mSettings.value("poll_rate_bms_data", 10).toDouble()));
mRepaintDisplayBarTimer.start(100);

connect(&mPollRtTimer, &QTimer::timeout, [this]() {
if (ui->actionRtData->isChecked()) {
Expand Down Expand Up @@ -513,6 +516,15 @@ MainWindow::MainWindow(QWidget *parent) :
}
});

connect(&mRepaintDisplayBarTimer, &QTimer::timeout, [this]() {
if (shouldSetDisplayBars) {
ui->dispCurrent->setVal(mMcValues.current_motor);
ui->dispDuty->setVal(mMcValues.duty_now * 100.0);

shouldSetDisplayBars = false;
}
});

// Restore size and position
if (mSettings.contains("mainwindow/size")) {
resize(mSettings.value("mainwindow/size").toSize());
Expand Down Expand Up @@ -950,8 +962,8 @@ void MainWindow::serialPortNotWritable(const QString &port)
void MainWindow::valuesReceived(MC_VALUES values, unsigned int mask)
{
(void)mask;
ui->dispCurrent->setVal(values.current_motor);
ui->dispDuty->setVal(values.duty_now * 100.0);
mMcValues = values;
shouldSetDisplayBars = true;
}

void MainWindow::paramChangedDouble(QObject *src, QString name, double newParam)
Expand Down
4 changes: 4 additions & 0 deletions mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,16 @@ private slots:
bool mKeyRight;
bool mMcConfRead;
bool mAppConfRead;
bool shouldSetDisplayBars;
QMap<QString, int> mPageNameIdList;

QTimer mPollRtTimer;
QTimer mPollAppTimer;
QTimer mPollImuTimer;
QTimer mPollBmsTimer;
QTimer mRepaintDisplayBarTimer;

MC_VALUES mMcValues;

PageWelcome *mPageWelcome;
PageConnection *mPageConnection;
Expand Down

0 comments on commit 1b93ada

Please sign in to comment.