Fixed stopped and reaction time (Fix #9)
This commit is contained in:
parent
6037d29c4c
commit
7529095d6f
2 changed files with 44 additions and 42 deletions
|
@ -72,7 +72,9 @@ ScStw::StatusCode ScStwRace::start(bool asyncronous) {
|
|||
this->setState(PREPAIRING);
|
||||
|
||||
if(asyncronous) {
|
||||
QTimer::singleShot(1, [=](){this->playSoundsAndStartTimers();});
|
||||
QTimer::singleShot(1, [=]() {
|
||||
this->playSoundsAndStartTimers();
|
||||
});
|
||||
}
|
||||
else
|
||||
this->playSoundsAndStartTimers();
|
||||
|
@ -94,8 +96,8 @@ ScStw::StatusCode ScStwRace::stop() {
|
|||
|
||||
ScStw::StatusCode returnCode = ScStw::Success;
|
||||
|
||||
foreach(ScStwTimer *speedTimer, this->timers){
|
||||
if(!speedTimer->stop(timeOfStop) && speedTimer->getState() != ScStwTimer::DISABLED){
|
||||
foreach(ScStwTimer *speedTimer, this->timers) {
|
||||
if(!speedTimer->stop(timeOfStop) && speedTimer->getState() != ScStwTimer::DISABLED) {
|
||||
returnCode = ScStw::InternalErrorTimerOperationFailed;
|
||||
}
|
||||
}
|
||||
|
@ -121,7 +123,7 @@ ScStw::StatusCode ScStwRace::reset() {
|
|||
|
||||
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) {
|
||||
returnCode = ScStw::InternalErrorTimerOperationFailed;
|
||||
}
|
||||
|
@ -143,7 +145,7 @@ ScStw::StatusCode ScStwRace::cancel() {
|
|||
|
||||
ScStw::StatusCode returnCode = ScStw::Success;
|
||||
|
||||
foreach(ScStwTimer *timer, this->timers){
|
||||
foreach(ScStwTimer *timer, this->timers) {
|
||||
if(!timer->cancel() && timer->getState() != ScStwTimer::DISABLED)
|
||||
returnCode = ScStw::InternalErrorTimerOperationFailed;
|
||||
}
|
||||
|
@ -351,8 +353,8 @@ bool ScStwRace::playSoundsAndStartTimers() {
|
|||
|
||||
// start all timers
|
||||
bool startOk = true;
|
||||
foreach(ScStwTimer *timer, this->timers){
|
||||
if(!timer->start(timeOfSoundPlaybackStart + 3100) && timer->getState() != ScStwTimer::DISABLED){
|
||||
foreach(ScStwTimer *timer, this->timers) {
|
||||
if(!timer->start(timeOfSoundPlaybackStart + 3000) && timer->getState() != ScStwTimer::DISABLED) {
|
||||
startOk = false;
|
||||
}
|
||||
}
|
||||
|
@ -425,12 +427,12 @@ void ScStwRace::setState(RaceState newState) {
|
|||
|
||||
void ScStwRace::handleTimerStateChange(ScStwTimer::TimerState newState) {
|
||||
if(
|
||||
newState == ScStwTimer::WON ||
|
||||
newState == ScStwTimer::LOST ||
|
||||
newState == ScStwTimer::WILDCARD ||
|
||||
newState == ScStwTimer::FAILED ||
|
||||
this->state == INCIDENT
|
||||
)
|
||||
newState == ScStwTimer::WON ||
|
||||
newState == ScStwTimer::LOST ||
|
||||
newState == ScStwTimer::WILDCARD ||
|
||||
newState == ScStwTimer::FAILED ||
|
||||
this->state == INCIDENT
|
||||
)
|
||||
return;
|
||||
|
||||
qDebug() << "[INFO][MAIN] handling timer state change";
|
||||
|
@ -439,8 +441,8 @@ void ScStwRace::handleTimerStateChange(ScStwTimer::TimerState newState) {
|
|||
bool raceIsOver = true;
|
||||
int incidentCount = 0;
|
||||
|
||||
foreach(ScStwTimer * timer, this->timers){
|
||||
if(timer->getState() < ScStwTimer::WAITING){
|
||||
foreach(ScStwTimer * timer, this->timers) {
|
||||
if(timer->getState() < ScStwTimer::WAITING) {
|
||||
// if the timer is not in stoped state
|
||||
raceIsOver = false;
|
||||
}
|
||||
|
@ -502,14 +504,14 @@ void ScStwRace::handleFalseStart() {
|
|||
// iterate through all timers and find the lowest reactiontime that was stopped
|
||||
foreach(ScStwTimer *timer, this->timers) {
|
||||
if(
|
||||
timer->getState() >= ScStwTimer::FAILING &&
|
||||
timer->getState() <= ScStwTimer::FAILED &&
|
||||
!timer->isDisabled() &&
|
||||
(
|
||||
timer->getReactionTime() < lowestReactionTime ||
|
||||
lowestReactionTime == -4000
|
||||
)
|
||||
) {
|
||||
timer->getState() >= ScStwTimer::FAILING &&
|
||||
timer->getState() <= ScStwTimer::FAILED &&
|
||||
!timer->isDisabled() &&
|
||||
(
|
||||
timer->getReactionTime() < lowestReactionTime ||
|
||||
lowestReactionTime == -4000
|
||||
)
|
||||
) {
|
||||
lowestReactionTime = timer->getReactionTime();
|
||||
}
|
||||
}
|
||||
|
@ -524,11 +526,11 @@ void ScStwRace::handleFalseStart() {
|
|||
foreach(ScStwTimer * timer, this->timers) {
|
||||
qDebug() << "THIS TIMERS reaction time is: " << timer->getReactionTime();
|
||||
if(
|
||||
timer->getState() >= ScStwTimer::FAILING &&
|
||||
timer->getState() <= ScStwTimer::FAILED &&
|
||||
!timer->isDisabled() &&
|
||||
timer->getReactionTime() <= lowestReactionTime
|
||||
) {
|
||||
timer->getState() >= ScStwTimer::FAILING &&
|
||||
timer->getState() <= ScStwTimer::FAILED &&
|
||||
!timer->isDisabled() &&
|
||||
timer->getReactionTime() <= lowestReactionTime
|
||||
) {
|
||||
// this is the timer with the lowest stopped time
|
||||
timer->setResult(ScStwTimer::FAILED);
|
||||
qDebug() << "FOUND BAD TIMER";
|
||||
|
@ -562,7 +564,7 @@ void ScStwRace::technicalIncident() {
|
|||
this->setState(INCIDENT);
|
||||
}
|
||||
|
||||
foreach(ScStwTimer *timer, this->timers){
|
||||
foreach(ScStwTimer *timer, this->timers) {
|
||||
if(raceIsRunning && timer->getReadyState() == ScStwTimer::ExtensionBatteryIsCritical)
|
||||
continue;
|
||||
else if(timer->getReadyState() == ScStwTimer::ExtensionIsNotConnected || timer->getReadyState() == ScStwTimer::ExtensionBatteryIsCritical)
|
||||
|
@ -598,7 +600,7 @@ bool ScStwRace::getIsReadyForNextState() {
|
|||
}
|
||||
|
||||
break;
|
||||
case WAITING: {
|
||||
case WAITING: {
|
||||
foreach (ScStwTimer *timer, this->timers) {
|
||||
if(timer->getReadyState() != ScStwTimer::IsReady && timer->getReadyState() != ScStwTimer::IsDisabled)
|
||||
return false;
|
||||
|
@ -656,9 +658,9 @@ void ScStwRace::refreshCompetitionMode() {
|
|||
else {
|
||||
foreach(ScStwTimer* timer, this->timers) {
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
@ -818,7 +820,7 @@ int ScStwRace::getSoundDelaySetting(ScStwSoundPlayer::StartSound sound) {
|
|||
QVariantList ScStwRace::getTimerDetailList() {
|
||||
QVariantList tmpTimers;
|
||||
|
||||
foreach(ScStwTimer * timer, this->timers){
|
||||
foreach(ScStwTimer * timer, this->timers) {
|
||||
QVariantMap tmpTimer;
|
||||
tmpTimer.insert("id", this->timers.indexOf(timer));
|
||||
tmpTimer.insert("state", timer->getState());
|
||||
|
@ -888,9 +890,9 @@ void ScStwRace::setAutoRefreshTimerText(bool autoRefresh) {
|
|||
this->timerTextRefreshTimer = new QTimer(this);
|
||||
this->timerTextRefreshTimer->setInterval(1);
|
||||
this->timerTextRefreshTimer->connect(
|
||||
this->timerTextRefreshTimer,
|
||||
&QTimer::timeout,
|
||||
[=]{
|
||||
this->timerTextRefreshTimer,
|
||||
&QTimer::timeout,
|
||||
[=] {
|
||||
// refresh timer text
|
||||
if(this->getState() == ScStwRace::RUNNING) {
|
||||
emit this->timersChanged();
|
||||
|
|
|
@ -53,7 +53,7 @@ bool ScStwTimer::start(double timeOfStart) {
|
|||
|
||||
if(timeOfStart - QDateTime::currentMSecsSinceEpoch() > 0) {
|
||||
this->setState(STARTING);
|
||||
QTimer::singleShot(timeOfStart - QDateTime::currentMSecsSinceEpoch(), [=](){
|
||||
QTimer::singleShot(timeOfStart - QDateTime::currentMSecsSinceEpoch(), [=]() {
|
||||
if(this->state == STARTING)
|
||||
this->setState(RUNNING);
|
||||
});
|
||||
|
@ -87,7 +87,7 @@ void ScStwTimer::handleClimberStart(double timeOfStart) {
|
|||
this->reactionTime = timeOfStart - this->startTime;
|
||||
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;
|
||||
this->setState(FAILING);
|
||||
}
|
||||
|
@ -171,8 +171,8 @@ bool ScStwTimer::setResult(TimerState result) {
|
|||
return false;
|
||||
}
|
||||
|
||||
bool ScStwTimer::reset(){
|
||||
if( this->state < WON || this->state == DISABLED ){
|
||||
bool ScStwTimer::reset() {
|
||||
if( this->state < WON || this->state == DISABLED ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -192,7 +192,7 @@ ScStwTimer::ReadyState ScStwTimer::getReadyState() {
|
|||
// --- helper functions ---
|
||||
// ------------------------
|
||||
|
||||
void ScStwTimer::setState(TimerState newState){
|
||||
void ScStwTimer::setState(TimerState newState) {
|
||||
if(this->state == DISABLED && newState != IDLE)
|
||||
return;
|
||||
|
||||
|
|
Reference in a new issue