Fixed stopped and reaction time (Fix #9)

This commit is contained in:
Dorian Zedler 2021-03-19 12:05:20 +01:00
parent 6037d29c4c
commit 7529095d6f
Signed by: dorian
GPG key ID: 989DE36109AFA354
2 changed files with 44 additions and 42 deletions

View file

@ -72,7 +72,9 @@ ScStw::StatusCode ScStwRace::start(bool asyncronous) {
this->setState(PREPAIRING); this->setState(PREPAIRING);
if(asyncronous) { if(asyncronous) {
QTimer::singleShot(1, [=](){this->playSoundsAndStartTimers();}); QTimer::singleShot(1, [=]() {
this->playSoundsAndStartTimers();
});
} }
else else
this->playSoundsAndStartTimers(); this->playSoundsAndStartTimers();
@ -94,8 +96,8 @@ ScStw::StatusCode ScStwRace::stop() {
ScStw::StatusCode returnCode = ScStw::Success; ScStw::StatusCode returnCode = ScStw::Success;
foreach(ScStwTimer *speedTimer, this->timers){ foreach(ScStwTimer *speedTimer, this->timers) {
if(!speedTimer->stop(timeOfStop) && speedTimer->getState() != ScStwTimer::DISABLED){ if(!speedTimer->stop(timeOfStop) && speedTimer->getState() != ScStwTimer::DISABLED) {
returnCode = ScStw::InternalErrorTimerOperationFailed; returnCode = ScStw::InternalErrorTimerOperationFailed;
} }
} }
@ -121,7 +123,7 @@ ScStw::StatusCode ScStwRace::reset() {
ScStw::StatusCode returnCode = ScStw::Success; ScStw::StatusCode returnCode = ScStw::Success;
foreach(ScStwTimer *timer, this->timers){ foreach(ScStwTimer *timer, this->timers) {
if(!timer->reset() && timer->getState() != ScStwTimer::DISABLED && timer->getState() != ScStwTimer::IDLE) { if(!timer->reset() && timer->getState() != ScStwTimer::DISABLED && timer->getState() != ScStwTimer::IDLE) {
returnCode = ScStw::InternalErrorTimerOperationFailed; returnCode = ScStw::InternalErrorTimerOperationFailed;
} }
@ -143,7 +145,7 @@ ScStw::StatusCode ScStwRace::cancel() {
ScStw::StatusCode returnCode = ScStw::Success; ScStw::StatusCode returnCode = ScStw::Success;
foreach(ScStwTimer *timer, this->timers){ foreach(ScStwTimer *timer, this->timers) {
if(!timer->cancel() && timer->getState() != ScStwTimer::DISABLED) if(!timer->cancel() && timer->getState() != ScStwTimer::DISABLED)
returnCode = ScStw::InternalErrorTimerOperationFailed; returnCode = ScStw::InternalErrorTimerOperationFailed;
} }
@ -351,8 +353,8 @@ bool ScStwRace::playSoundsAndStartTimers() {
// start all timers // start all timers
bool startOk = true; bool startOk = true;
foreach(ScStwTimer *timer, this->timers){ foreach(ScStwTimer *timer, this->timers) {
if(!timer->start(timeOfSoundPlaybackStart + 3100) && timer->getState() != ScStwTimer::DISABLED){ if(!timer->start(timeOfSoundPlaybackStart + 3000) && timer->getState() != ScStwTimer::DISABLED) {
startOk = false; startOk = false;
} }
} }
@ -439,8 +441,8 @@ void ScStwRace::handleTimerStateChange(ScStwTimer::TimerState newState) {
bool raceIsOver = true; bool raceIsOver = true;
int incidentCount = 0; int incidentCount = 0;
foreach(ScStwTimer * timer, this->timers){ foreach(ScStwTimer * timer, this->timers) {
if(timer->getState() < ScStwTimer::WAITING){ if(timer->getState() < ScStwTimer::WAITING) {
// if the timer is not in stoped state // if the timer is not in stoped state
raceIsOver = false; raceIsOver = false;
} }
@ -562,7 +564,7 @@ void ScStwRace::technicalIncident() {
this->setState(INCIDENT); this->setState(INCIDENT);
} }
foreach(ScStwTimer *timer, this->timers){ foreach(ScStwTimer *timer, this->timers) {
if(raceIsRunning && timer->getReadyState() == ScStwTimer::ExtensionBatteryIsCritical) if(raceIsRunning && timer->getReadyState() == ScStwTimer::ExtensionBatteryIsCritical)
continue; continue;
else if(timer->getReadyState() == ScStwTimer::ExtensionIsNotConnected || timer->getReadyState() == ScStwTimer::ExtensionBatteryIsCritical) else if(timer->getReadyState() == ScStwTimer::ExtensionIsNotConnected || timer->getReadyState() == ScStwTimer::ExtensionBatteryIsCritical)
@ -818,7 +820,7 @@ int ScStwRace::getSoundDelaySetting(ScStwSoundPlayer::StartSound sound) {
QVariantList ScStwRace::getTimerDetailList() { QVariantList ScStwRace::getTimerDetailList() {
QVariantList tmpTimers; QVariantList tmpTimers;
foreach(ScStwTimer * timer, this->timers){ foreach(ScStwTimer * timer, this->timers) {
QVariantMap tmpTimer; QVariantMap tmpTimer;
tmpTimer.insert("id", this->timers.indexOf(timer)); tmpTimer.insert("id", this->timers.indexOf(timer));
tmpTimer.insert("state", timer->getState()); tmpTimer.insert("state", timer->getState());
@ -890,7 +892,7 @@ void ScStwRace::setAutoRefreshTimerText(bool autoRefresh) {
this->timerTextRefreshTimer->connect( this->timerTextRefreshTimer->connect(
this->timerTextRefreshTimer, this->timerTextRefreshTimer,
&QTimer::timeout, &QTimer::timeout,
[=]{ [=] {
// refresh timer text // refresh timer text
if(this->getState() == ScStwRace::RUNNING) { if(this->getState() == ScStwRace::RUNNING) {
emit this->timersChanged(); emit this->timersChanged();

View file

@ -53,7 +53,7 @@ bool ScStwTimer::start(double timeOfStart) {
if(timeOfStart - QDateTime::currentMSecsSinceEpoch() > 0) { if(timeOfStart - QDateTime::currentMSecsSinceEpoch() > 0) {
this->setState(STARTING); this->setState(STARTING);
QTimer::singleShot(timeOfStart - QDateTime::currentMSecsSinceEpoch(), [=](){ QTimer::singleShot(timeOfStart - QDateTime::currentMSecsSinceEpoch(), [=]() {
if(this->state == STARTING) if(this->state == STARTING)
this->setState(RUNNING); this->setState(RUNNING);
}); });
@ -87,7 +87,7 @@ void ScStwTimer::handleClimberStart(double timeOfStart) {
this->reactionTime = timeOfStart - this->startTime; this->reactionTime = timeOfStart - this->startTime;
qDebug() << "+ [INFO][TIMER] reaction time: " << this->reactionTime; qDebug() << "+ [INFO][TIMER] reaction time: " << this->reactionTime;
if(this->reactionTime <= 0 && this->reactionTime){ if(this->reactionTime <= 100 && this->reactionTime) {
qDebug() << "[INFO][TIMER] False Start detected: " << "start Time: " << startTime << " reactionTime: " << reactionTime; qDebug() << "[INFO][TIMER] False Start detected: " << "start Time: " << startTime << " reactionTime: " << reactionTime;
this->setState(FAILING); this->setState(FAILING);
} }
@ -171,8 +171,8 @@ bool ScStwTimer::setResult(TimerState result) {
return false; return false;
} }
bool ScStwTimer::reset(){ bool ScStwTimer::reset() {
if( this->state < WON || this->state == DISABLED ){ if( this->state < WON || this->state == DISABLED ) {
return false; return false;
} }
@ -192,7 +192,7 @@ ScStwTimer::ReadyState ScStwTimer::getReadyState() {
// --- helper functions --- // --- helper functions ---
// ------------------------ // ------------------------
void ScStwTimer::setState(TimerState newState){ void ScStwTimer::setState(TimerState newState) {
if(this->state == DISABLED && newState != IDLE) if(this->state == DISABLED && newState != IDLE)
return; return;