Merge remote-tracking branch 'origin/master'

This commit is contained in:
Dorian Zedler 2020-10-06 14:00:31 +02:00
commit bc7baa32be
Signed by: dorian
GPG Key ID: D3B255CB8BC7CD37
5 changed files with 77 additions and 27 deletions

View File

@ -112,16 +112,16 @@ public:
FirmwareAlreadyUpToDateInfo = 304,
CommandNotFoundError = 404,
ClientSessionAlreadyActiveError = 407,
UpdateSignatureInvalidError = 402,
TimestampTooSmallError = 406,
RequiredParameterNotGivenError = 405,
CurrentStateNotVaildForOperationError = 403,
AccessDeniedError = 401,
UpdateSignatureInvalidError = 402,
CurrentStateNotVaildForOperationError = 403,
CommandNotFoundError = 404,
RequiredParameterNotGivenError = 405,
TimestampTooSmallError = 406,
ClientSessionAlreadyActiveError = 407,
NoSessionActiveError = 408,
ItemNotFoundError = 409,
LastTimerCannotBeDisabledError = 410,
UpdateFailedError = 500,

View File

@ -146,6 +146,7 @@ private slots:
bool playSoundsAndStartTimers();
ScStwSoundPlayer::PlayResult doDelayAndSoundOfCurrentStartState(double *timeOfSoundPlaybackStart = nullptr);
void technicalIncident();
ScStw::StatusCode setTimerDisabled(ScStwTimer* timer, bool disabled);
virtual void refreshCompetitionMode();

View File

@ -265,6 +265,10 @@ public slots:
*/
virtual ScStwTimer::ReadyState getReadyState();
bool isRunning();
bool isDisabled();
protected slots:
/*!

View File

@ -112,8 +112,8 @@ ScStw::StatusCode ScStwRace::reset() {
ScStw::StatusCode returnCode = ScStw::Success;
foreach(ScStwTimer *speedTimer, this->timers){
if(!speedTimer->reset() && speedTimer->getState() != ScStwTimer::DISABLED && speedTimer->getState() != ScStwTimer::IDLE) {
foreach(ScStwTimer *timer, this->timers){
if(!timer->reset() && timer->getState() != ScStwTimer::DISABLED && timer->getState() != ScStwTimer::IDLE) {
returnCode = ScStw::InternalErrorTimerOperationFailed;
}
}
@ -154,15 +154,36 @@ ScStw::StatusCode ScStwRace::cancel() {
}
ScStw::StatusCode ScStwRace::setTimerDisabled(int timerId, bool disabled) {
if(this->state != IDLE && this->state != WAITING)
return ScStw::CurrentStateNotVaildForOperationError;
if(timerId < 0 || timerId - 1 > this->timers.length())
return ScStw::ItemNotFoundError;
this->timers[timerId]->setDisabled(disabled);
return this->setTimerDisabled(this->timers[timerId], disabled);
}
ScStw::StatusCode ScStwRace::setTimerDisabled(ScStwTimer* timer, bool disabled) {
qDebug() << "[INFO][RACE] Setting timer "<< timer->getLetter() << " to disabled: " << disabled << " this state: " << this->state;
if(this->state != IDLE && this->state != WAITING)
return ScStw::CurrentStateNotVaildForOperationError;
if(!this->timers.contains(timer))
return ScStw::ItemNotFoundError;
int enabledTimerCount = 0;
foreach(ScStwTimer *timer, this->timers) {
if(timer->getState() != ScStwTimer::DISABLED)
enabledTimerCount ++;
}
if(disabled && enabledTimerCount <= 1)
return ScStw::LastTimerCannotBeDisabledError;
qDebug() << "[INFO][RACE] Setting timer "<< timer->getLetter() << " to disabled: " << disabled;
timer->setDisabled(disabled);
return ScStw::Success;
}
void ScStwRace::handleTimerReadyStateChange(ScStwTimer::ReadyState readyState) {
@ -435,16 +456,18 @@ void ScStwRace::handleTimerStop() {
// find out which timer has won
double lowestStoppedTime = -1;
QList<ScStwTimer *> timersWhichHaveWon;
// iterate through all timers and find the lowest time that was stopped
foreach(ScStwTimer * timer, this->timers) {
if(timer->getCurrentTime() <= lowestStoppedTime || lowestStoppedTime < 0) {
qDebug() << "Current stopped time is: " << timer->getCurrentTime();
if(!timer->isRunning() && !timer->isDisabled() && (timer->getCurrentTime() <= lowestStoppedTime || lowestStoppedTime < 0)) {
// this is the timer with the lowest stopped time
lowestStoppedTime = timer->getCurrentTime();
}
}
qDebug() << "LOWEST Stop time is: " << lowestStoppedTime;
// append the timer(s) with the lowest stopped time to the winner list
foreach(ScStwTimer * timer, this->timers) {
if(timer->getCurrentTime() <= lowestStoppedTime)
@ -469,6 +492,7 @@ void ScStwRace::handleFalseStart() {
if(
timer->getState() >= ScStwTimer::FAILING &&
timer->getState() <= ScStwTimer::FAILED &&
!timer->isDisabled() &&
(
timer->getReactionTime() < lowestReactionTime ||
lowestReactionTime == -4000
@ -490,6 +514,7 @@ void ScStwRace::handleFalseStart() {
if(
timer->getState() >= ScStwTimer::FAILING &&
timer->getState() <= ScStwTimer::FAILED &&
!timer->isDisabled() &&
timer->getReactionTime() <= lowestReactionTime
) {
// this is the timer with the lowest stopped time
@ -563,7 +588,7 @@ bool ScStwRace::getIsReadyForNextState() {
break;
case WAITING: {
foreach (ScStwTimer *timer, this->timers) {
if(timer->getReadyState() != ScStwTimer::IsReady)
if(timer->getReadyState() != ScStwTimer::IsReady && timer->getReadyState() != ScStwTimer::IsDisabled)
return false;
}
break;
@ -584,11 +609,14 @@ bool ScStwRace::getIsReadyForNextState() {
* @param {ScStwExtensionControlledTimer*} timer timer to be enabled
*/
void ScStwRace::handleTimerWantsToBeDisabledChange(ScStwTimer* timer, bool wantsToBeDisabled) {
qDebug() << "Handling timer wants to be disabled";
if(this->competitionMode)
return;
if(this->state == IDLE) {
timer->setDisabled(wantsToBeDisabled);
qDebug() << "Handling timer wants to be disabled: " << wantsToBeDisabled;
this->setTimerDisabled(timer, wantsToBeDisabled);
}
}
@ -603,17 +631,20 @@ void ScStwRace::refreshCompetitionMode() {
qDebug() << "[INFO][RACE] Setting competition mode to " << currentCompetitionMode;
this->competitionMode = currentCompetitionMode;
}
if(this->competitionMode) {
foreach (ScStwTimer *timer, this->timers) {
timer->setDisabled(false);
}
if(this->competitionMode) {
foreach (ScStwTimer *timer, this->timers) {
timer->setDisabled(false);
}
else {
foreach(ScStwTimer* timer, this->timers) {
if(timer->getWantsToBeDisabled() && timer->getState() != ScStwTimer::DISABLED)
this->handleTimerWantsToBeDisabledChange(timer, timer->getWantsToBeDisabled());
}
}
else {
foreach(ScStwTimer* timer, this->timers) {
if(
(timer->getWantsToBeDisabled() && timer->getState() != ScStwTimer::DISABLED) ||
(!timer->getWantsToBeDisabled() && timer->getState() == ScStwTimer::DISABLED)
)
this->handleTimerWantsToBeDisabledChange(timer, timer->getWantsToBeDisabled());
}
}
}
@ -686,6 +717,9 @@ bool ScStwRace::addTimer(ScStwTimer *timer) {
if(this->competitionMode && timer->getState() == ScStwTimer::DISABLED)
timer->setDisabled(false);
else if(!this->competitionMode)
this->handleTimerWantsToBeDisabledChange(timer, timer->getWantsToBeDisabled());
return true;

View File

@ -278,14 +278,17 @@ QString ScStwTimer::getText() {
void ScStwTimer::setDisabled(bool disabled) {
if(disabled)
this->setState(DISABLED);
else
else {
this->setState(IDLE);
}
}
void ScStwTimer::setWantsToBeDisabled(bool wantsToBeDisabled) {
if(this->wantsToBeDisabled == wantsToBeDisabled)
return;
qDebug() << "Wants to be disabled changed: " << wantsToBeDisabled;
this->wantsToBeDisabled = wantsToBeDisabled;
emit this->wantsToBeDisabledChanged(this, wantsToBeDisabled);
@ -294,3 +297,11 @@ void ScStwTimer::setWantsToBeDisabled(bool wantsToBeDisabled) {
bool ScStwTimer::getWantsToBeDisabled() {
return this->wantsToBeDisabled;
}
bool ScStwTimer::isRunning() {
return this->state == RUNNING;
}
bool ScStwTimer::isDisabled() {
return this->state == DISABLED;
}