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;
} }
} }
@ -425,12 +427,12 @@ void ScStwRace::setState(RaceState newState) {
void ScStwRace::handleTimerStateChange(ScStwTimer::TimerState newState) { void ScStwRace::handleTimerStateChange(ScStwTimer::TimerState newState) {
if( if(
newState == ScStwTimer::WON || newState == ScStwTimer::WON ||
newState == ScStwTimer::LOST || newState == ScStwTimer::LOST ||
newState == ScStwTimer::WILDCARD || newState == ScStwTimer::WILDCARD ||
newState == ScStwTimer::FAILED || newState == ScStwTimer::FAILED ||
this->state == INCIDENT this->state == INCIDENT
) )
return; return;
qDebug() << "[INFO][MAIN] handling timer state change"; qDebug() << "[INFO][MAIN] handling timer state change";
@ -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;
} }
@ -502,14 +504,14 @@ void ScStwRace::handleFalseStart() {
// iterate through all timers and find the lowest reactiontime that was stopped // iterate through all timers and find the lowest reactiontime that was stopped
foreach(ScStwTimer *timer, this->timers) { foreach(ScStwTimer *timer, this->timers) {
if( if(
timer->getState() >= ScStwTimer::FAILING && timer->getState() >= ScStwTimer::FAILING &&
timer->getState() <= ScStwTimer::FAILED && timer->getState() <= ScStwTimer::FAILED &&
!timer->isDisabled() && !timer->isDisabled() &&
( (
timer->getReactionTime() < lowestReactionTime || timer->getReactionTime() < lowestReactionTime ||
lowestReactionTime == -4000 lowestReactionTime == -4000
) )
) { ) {
lowestReactionTime = timer->getReactionTime(); lowestReactionTime = timer->getReactionTime();
} }
} }
@ -524,11 +526,11 @@ void ScStwRace::handleFalseStart() {
foreach(ScStwTimer * timer, this->timers) { foreach(ScStwTimer * timer, this->timers) {
qDebug() << "THIS TIMERS reaction time is: " << timer->getReactionTime(); qDebug() << "THIS TIMERS reaction time is: " << timer->getReactionTime();
if( if(
timer->getState() >= ScStwTimer::FAILING && timer->getState() >= ScStwTimer::FAILING &&
timer->getState() <= ScStwTimer::FAILED && timer->getState() <= ScStwTimer::FAILED &&
!timer->isDisabled() && !timer->isDisabled() &&
timer->getReactionTime() <= lowestReactionTime timer->getReactionTime() <= lowestReactionTime
) { ) {
// this is the timer with the lowest stopped time // this is the timer with the lowest stopped time
timer->setResult(ScStwTimer::FAILED); timer->setResult(ScStwTimer::FAILED);
qDebug() << "FOUND BAD TIMER"; qDebug() << "FOUND BAD TIMER";
@ -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)
@ -598,7 +600,7 @@ bool ScStwRace::getIsReadyForNextState() {
} }
break; break;
case WAITING: { case WAITING: {
foreach (ScStwTimer *timer, this->timers) { foreach (ScStwTimer *timer, this->timers) {
if(timer->getReadyState() != ScStwTimer::IsReady && timer->getReadyState() != ScStwTimer::IsDisabled) if(timer->getReadyState() != ScStwTimer::IsReady && timer->getReadyState() != ScStwTimer::IsDisabled)
return false; return false;
@ -656,9 +658,9 @@ void ScStwRace::refreshCompetitionMode() {
else { else {
foreach(ScStwTimer* timer, this->timers) { foreach(ScStwTimer* timer, this->timers) {
if( if(
(timer->getWantsToBeDisabled() && timer->getState() != ScStwTimer::DISABLED) || (timer->getWantsToBeDisabled() && timer->getState() != ScStwTimer::DISABLED) ||
(!timer->getWantsToBeDisabled() && timer->getState() == ScStwTimer::DISABLED) (!timer->getWantsToBeDisabled() && timer->getState() == ScStwTimer::DISABLED)
) )
this->handleTimerWantsToBeDisabledChange(timer, timer->getWantsToBeDisabled()); this->handleTimerWantsToBeDisabledChange(timer, timer->getWantsToBeDisabled());
} }
} }
@ -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());
@ -888,9 +890,9 @@ void ScStwRace::setAutoRefreshTimerText(bool autoRefresh) {
this->timerTextRefreshTimer = new QTimer(this); this->timerTextRefreshTimer = new QTimer(this);
this->timerTextRefreshTimer->setInterval(1); this->timerTextRefreshTimer->setInterval(1);
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;