@@ -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)
951964void 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
958971void MainWindow::paramChangedDouble (QObject *src, QString name, double newParam)
0 commit comments