some cleanup
This commit is contained in:
parent
f985197ffa
commit
130213d09d
5 changed files with 78 additions and 80 deletions
|
@ -87,7 +87,10 @@ public:
|
|||
Error = 900,
|
||||
NotConnectedError = 910,
|
||||
TimeoutError = 911,
|
||||
SettingNotAccessibleError = 901
|
||||
SettingNotAccessibleError = 901,
|
||||
CurrentStateNotVaildForOperation = 904,
|
||||
InternalError = 950,
|
||||
InternalErrorTimerOperationFailed = 951
|
||||
};
|
||||
Q_ENUM(ScStw::StatusCode)
|
||||
|
||||
|
|
|
@ -80,10 +80,28 @@ private:
|
|||
|
||||
|
||||
public slots:
|
||||
/*!
|
||||
* \brief Function to start the race
|
||||
*
|
||||
* \param asyncronous if the function should just start the start sequence and then quit (true)
|
||||
* or if if should wait until the start sequence is over and quit after that (false)
|
||||
* \return 200: OK; 904: state not matching
|
||||
*/
|
||||
int start(bool asyncronous = true);
|
||||
|
||||
/*!
|
||||
* \brief Function to stop the currently running race
|
||||
*
|
||||
* \return 200: OK; 904: state not matching
|
||||
*/
|
||||
int stop();
|
||||
|
||||
/*!
|
||||
* \brief Function to reset a stopped race
|
||||
* \return
|
||||
*/
|
||||
int reset();
|
||||
void cancelStart(bool falseStart);
|
||||
int cancel();
|
||||
|
||||
// setters
|
||||
bool writeStartActionSetting(StartAction action, bool enabled, int delay);
|
||||
|
@ -102,7 +120,13 @@ protected slots:
|
|||
private slots:
|
||||
void refreshTimerStates();
|
||||
void handleTimerEnable(ScStwTimer* timer);
|
||||
int handleFalseStart();
|
||||
bool playSoundsAndStartTimers(StartAction thisAction);
|
||||
|
||||
|
||||
/**
|
||||
* \brief Function to declare the winner and looser timers after a timer has been stopped
|
||||
*/
|
||||
void handleTimerStop();
|
||||
|
||||
signals:
|
||||
|
|
|
@ -305,12 +305,6 @@ signals:
|
|||
*/
|
||||
void stateChanged();
|
||||
|
||||
/*!
|
||||
* \brief Emitted when the start was canceled
|
||||
* \param falseStart Wheter a false start occured
|
||||
*/
|
||||
void startCanceled(bool falseStart);
|
||||
|
||||
/*!
|
||||
* \brief Emitted when the reaction time changed
|
||||
*/
|
||||
|
|
|
@ -27,15 +27,9 @@ ScStwRace::ScStwRace(QObject *parent) : QObject(parent)
|
|||
// --- Main Functionality ---
|
||||
// --------------------------
|
||||
|
||||
/**
|
||||
* Function to start the race
|
||||
*
|
||||
* @brief ScStwRace::startRace
|
||||
* @return {int} 200: OK; 904: MAIN state not matching
|
||||
*/
|
||||
int ScStwRace::start(bool asyncronous) {
|
||||
if(this->state != IDLE) {
|
||||
return 904;
|
||||
return ScStw::CurrentStateNotVaildForOperation;
|
||||
}
|
||||
|
||||
qDebug() << "+ [INFO] starting race";
|
||||
|
@ -48,47 +42,33 @@ int ScStwRace::start(bool asyncronous) {
|
|||
else
|
||||
this->playSoundsAndStartTimers(None);
|
||||
|
||||
return 200;
|
||||
return ScStw::Success;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to stop the currently running race
|
||||
*
|
||||
* @brief ScStwRace::stopRace
|
||||
* @param {int} type 0: stop; 1: cancel; 2: false start
|
||||
* @return {int} 200: OK; 904: MAIN state not matching
|
||||
*/
|
||||
int ScStwRace::stop() {
|
||||
if(this->state != RUNNING && this->state != STARTING) {
|
||||
return 904;
|
||||
return ScStw::CurrentStateNotVaildForOperation;
|
||||
}
|
||||
|
||||
qDebug() << "+ [INFO] stopping race";
|
||||
|
||||
double timeOfStop = QDateTime::currentMSecsSinceEpoch();
|
||||
|
||||
int returnCode = 900;
|
||||
|
||||
bool stopOk = true;
|
||||
int returnCode = ScStw::Success;
|
||||
|
||||
foreach(ScStwTimer *speedTimer, this->timers){
|
||||
if(!speedTimer->stop(timeOfStop) && speedTimer->getState() != ScStwTimer::DISABLED){
|
||||
stopOk = false;
|
||||
returnCode = ScStw::InternalErrorTimerOperationFailed;
|
||||
}
|
||||
}
|
||||
|
||||
returnCode = stopOk ? 200:904;
|
||||
|
||||
if(returnCode == 200) {
|
||||
if(returnCode == ScStw::Success) {
|
||||
this->setState(STOPPED);
|
||||
}
|
||||
|
||||
return returnCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ScStwRace::handleTimerStop Function to declare the winner and looser timers after a timer has been stopped
|
||||
*/
|
||||
void ScStwRace::handleTimerStop() {
|
||||
if(this->state == RUNNING) {
|
||||
// find out which timer has won
|
||||
|
@ -129,56 +109,64 @@ void ScStwRace::handleTimerStop() {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ScStwRace::resetRace
|
||||
* @return {int} 200: OK; 904: MAIN state not matching
|
||||
*/
|
||||
int ScStwRace::reset() {
|
||||
if(this->state != STOPPED) {
|
||||
return 904;
|
||||
return ScStw::CurrentStateNotVaildForOperation;
|
||||
}
|
||||
|
||||
qDebug() << "+ [INFO] resetting race";
|
||||
|
||||
int returnCode = 200;
|
||||
int returnCode = ScStw::Success;
|
||||
|
||||
foreach(ScStwTimer *speedTimer, this->timers){
|
||||
if(!speedTimer->reset() && speedTimer->getState() != ScStwTimer::DISABLED) {
|
||||
returnCode = 904;
|
||||
returnCode = ScStw::InternalErrorTimerOperationFailed;
|
||||
}
|
||||
}
|
||||
|
||||
if(returnCode == 200){
|
||||
if(returnCode == ScStw::Success){
|
||||
this->setState(IDLE);
|
||||
}
|
||||
|
||||
return returnCode;
|
||||
}
|
||||
|
||||
void ScStwRace::cancelStart(bool falseStart){
|
||||
// TODO: FIXME
|
||||
qDebug() << "+ [INFO] cancelling race: " << falseStart;
|
||||
int ScStwRace::cancel() {
|
||||
if(this->state != STARTING && this->state != RUNNING)
|
||||
return ScStw::CurrentStateNotVaildForOperation;
|
||||
|
||||
if(falseStart){
|
||||
// cancel all running timers
|
||||
foreach(ScStwTimer *timer, this->timers) {
|
||||
timer->cancel();
|
||||
}
|
||||
qDebug() << "[INFO][RACE] cancelling race";
|
||||
|
||||
this->setState(STOPPED);
|
||||
this->soundPlayer->cancel(this->soundVolume);
|
||||
this->nextActionTimer->stop();
|
||||
this->nextActionLoop->quit();
|
||||
this->nextStartAction = None;
|
||||
|
||||
this->soundPlayer->cancel(this->soundVolume);
|
||||
int returnCode = ScStw::Success;
|
||||
|
||||
foreach(ScStwTimer *timer, this->timers){
|
||||
if(!timer->cancel() && timer->getState() != ScStwTimer::DISABLED)
|
||||
returnCode = ScStw::InternalErrorTimerOperationFailed;
|
||||
}
|
||||
else {
|
||||
this->soundPlayer->cancel(this->soundVolume);
|
||||
this->nextActionTimer->stop();
|
||||
this->nextActionLoop->quit();
|
||||
this->nextStartAction = None;
|
||||
|
||||
foreach(ScStwTimer *timer, this->timers){
|
||||
timer->cancel();
|
||||
}
|
||||
return returnCode;
|
||||
}
|
||||
|
||||
int ScStwRace::handleFalseStart() {
|
||||
if(this->getState() != STARTING && this->getState() != RUNNING)
|
||||
return ScStw::CurrentStateNotVaildForOperation;
|
||||
|
||||
int returnCode = ScStw::Success;
|
||||
// cancel all running timers
|
||||
foreach(ScStwTimer *timer, this->timers) {
|
||||
if(!timer->cancel() && timer->getState() != ScStwTimer::DISABLED && timer->getState() != ScStwTimer::FAILED)
|
||||
returnCode = ScStw::InternalErrorTimerOperationFailed;
|
||||
}
|
||||
|
||||
this->setState(STOPPED);
|
||||
this->soundPlayer->cancel(this->soundVolume);
|
||||
|
||||
return returnCode;
|
||||
}
|
||||
|
||||
bool ScStwRace::playSoundsAndStartTimers(StartAction thisAction) {
|
||||
|
@ -243,10 +231,6 @@ bool ScStwRace::playSoundsAndStartTimers(StartAction thisAction) {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ScStwRace::setState
|
||||
* @param {QString} newState
|
||||
*/
|
||||
void ScStwRace::setState(RaceState newState) {
|
||||
if(newState != this->state) {
|
||||
qDebug() << "[INFO][RACE] state changed: " << newState;
|
||||
|
@ -264,9 +248,6 @@ void ScStwRace::setState(RaceState newState) {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ScStwRace::refreshTimerStates
|
||||
*/
|
||||
void ScStwRace::refreshTimerStates() {
|
||||
|
||||
qDebug() << "[INFO][MAIN] refreshing timer states";
|
||||
|
@ -283,12 +264,13 @@ void ScStwRace::refreshTimerStates() {
|
|||
else if(timer->getState() == ScStwTimer::WAITING) {
|
||||
this->handleTimerStop();
|
||||
}
|
||||
else if (timer->getState() == ScStwTimer::FAILED) {
|
||||
this->handleFalseStart();
|
||||
}
|
||||
}
|
||||
|
||||
if(raceIsOver){
|
||||
if(raceIsOver)
|
||||
this->setState(STOPPED);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------
|
||||
|
@ -329,8 +311,8 @@ QVariantList ScStwRace::getNextStartActionDetails() {
|
|||
|
||||
return {
|
||||
this->nextStartAction,
|
||||
nextActionDelay,
|
||||
nextActionDelayProg
|
||||
nextActionDelay,
|
||||
nextActionDelayProg
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -369,7 +351,6 @@ bool ScStwRace::addTimer(ScStwTimer *timer) {
|
|||
|
||||
this->timers.append(timer);
|
||||
|
||||
connect(timer, &ScStwTimer::startCanceled, this, &ScStwRace::cancelStart);
|
||||
connect(timer, &ScStwTimer::stateChanged, this, &ScStwRace::refreshTimerStates);
|
||||
connect(timer, &ScStwTimer::requestEnableChange, this, &ScStwRace::handleTimerEnable);
|
||||
connect(timer, &ScStwTimer::stateChanged, this, &ScStwRace::timersChanged);
|
||||
|
|
|
@ -84,7 +84,6 @@ bool ScStwTimer::stop(StopReason reason, double timeOfStop) {
|
|||
switch (reason) {
|
||||
case ManualStop: {
|
||||
if(this->state == STARTING){
|
||||
emit startCanceled(false);
|
||||
this->setState(CANCELLED);
|
||||
}
|
||||
else {
|
||||
|
@ -96,19 +95,16 @@ bool ScStwTimer::stop(StopReason reason, double timeOfStop) {
|
|||
break;
|
||||
}
|
||||
case FailStop: {
|
||||
qDebug() << "+ [INFO][TIMER] False Start detected: " << "start Time: " << startTime << " reactionTime: " << reactionTime;
|
||||
qDebug() << "[INFO][TIMER] False Start detected: " << "start Time: " << startTime << " reactionTime: " << reactionTime;
|
||||
this->setState(FAILED);
|
||||
|
||||
emit startCanceled(true);
|
||||
|
||||
return true;
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
qDebug() << "+ [INFO][TIMER] Stopped: " << "start Time: " << startTime << " stopTime: " << stopTime << " stoppedTime: " << this->getCurrentTime() << " reactionTime: " << reactionTime;
|
||||
qDebug() << "[INFO][TIMER] Stopped: " << "start Time: " << startTime << " stopTime: " << stopTime << " stoppedTime: " << this->getCurrentTime() << " reactionTime: " << reactionTime;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
Reference in a new issue