Compare commits

...

7 Commits

Author SHA1 Message Date
Roberto Viola
04d37e0a68 Merge remote-tracking branch 'origin/master' into fixing_trainprogram_jitter 2025-02-23 16:30:47 +00:00
Roberto Viola
b5890ea818 Update trainprogram.cpp 2025-02-12 11:24:12 +01:00
Roberto Viola
83627f5397 Merge branch 'master' into fixing_trainprogram_jitter 2025-02-12 10:07:42 +01:00
Roberto Viola
2b8af5d777 Update trainprogram.cpp 2025-02-09 09:39:52 +01:00
Roberto Viola
3f6b284468 Merge branch 'master' into fixing_trainprogram_jitter 2025-01-30 10:05:48 +01:00
Roberto Viola
1be9e2620d Update trainprogram.cpp 2023-12-01 15:08:14 +01:00
Roberto Viola
805981df4d fixing 2023-12-01 14:53:33 +01:00
2 changed files with 30 additions and 0 deletions

View File

@@ -586,6 +586,17 @@ void trainprogram::scheduler() {
QMutexLocker(&this->schedulerMutex);
QSettings settings;
QDateTime now = QDateTime::currentDateTime();
qint64 msecsElapsed = lastSchedulerCall.msecsTo(now);
// Reset jitter if it's getting too large
if (qAbs(currentTimerJitter) > 5000) {
currentTimerJitter = 0;
}
currentTimerJitter += msecsElapsed - 1000;
lastSchedulerCall = now;
// outside the if case about a valid train program because the information for the floating window url should be
// sent anyway
if (settings.value(QZSettings::peloton_companion_workout_ocr, QZSettings::default_companion_peloton_workout_ocr)
@@ -811,6 +822,7 @@ void trainprogram::scheduler() {
#endif
}
currentTimerJitter = 0;
return;
}
@@ -832,6 +844,20 @@ void trainprogram::scheduler() {
#endif
ticks++;
qDebug() << QStringLiteral("trainprogram ticks") << ticks << QStringLiteral("currentTimerJitter") << currentTimerJitter;
if(qAbs(currentTimerJitter) > 1000) {
// we are late...
if (currentTimerJitter > 1000) {
int seconds = currentTimerJitter / 1000;
ticks += seconds;
currentTimerJitter -= (seconds * 1000);
qDebug() << QStringLiteral("fixing jitter!") << seconds << ticks << currentTimerJitter;
} else {
// negative jitter, reset the counter without touching the ticks
currentTimerJitter = 0;
}
}
double odometerFromTheDevice = bluetoothManager->device()->odometer();
@@ -1270,6 +1296,7 @@ void trainprogram::restart() {
ticks = 0;
offset = 0;
currentStep = 0;
currentTimerJitter = 0;
started = true;
}

View File

@@ -168,6 +168,9 @@ private slots:
int lastStepTimestampChanged = 0;
double lastCurrentStepDistance = 0.0;
QTime lastCurrentStepTime = QTime(0, 0, 0);
int64_t currentTimerJitter = 0;
QDateTime lastSchedulerCall = QDateTime::currentDateTime();
QUdpSocket* pelotonOCRsocket = nullptr;
void pelotonOCRcomputeTime(QString t);