From aff108ee905c29ddec50b0ca41ccb081627a8826 Mon Sep 17 00:00:00 2001 From: Dorian Zedler Date: Tue, 14 Apr 2020 00:08:58 +0200 Subject: [PATCH] fixed problems from rebase --- ScStwLibraries/headers/ScStw.hpp | 19 ---------- ScStwLibraries/headers/scstwtimer.h | 5 ++- ScStwLibraries/sources/scstwtimer.cpp | 51 ++++++++++++++++++++------- 3 files changed, 43 insertions(+), 32 deletions(-) diff --git a/ScStwLibraries/headers/ScStw.hpp b/ScStwLibraries/headers/ScStw.hpp index 6657fc7..345b44f 100644 --- a/ScStwLibraries/headers/ScStw.hpp +++ b/ScStwLibraries/headers/ScStw.hpp @@ -46,21 +46,11 @@ class ScStw : public QObject { Q_OBJECT public: - /** - * @brief The RaceState enum contains all states a race can have - */ -<<<<<<< HEAD:ScStwLibraries/ScStw.hpp - enum RaceState { IDLE, STARTING, WAITING, RUNNING, STOPPED }; - Q_ENUM(RaceState) - /** * @brief The SignalKey enum contains all signal keys a client can subscribe to * * @see ScStw::signalKeyFromInt() */ -======= - ->>>>>>> - some changes to file structure:ScStwLibraries/headers/ScStw.hpp enum SignalKey { InvalidSignal = -1, RaceStateChanged = 9000, @@ -70,13 +60,6 @@ public: }; Q_ENUM(SignalKey) -<<<<<<< HEAD:ScStwLibraries/ScStw.hpp - /** - * @brief The NextStartAction enum contains all action that occur before a race is started - */ - enum NextStartAction { AtYourMarks, Ready, Start, None }; - Q_ENUM(NextStartAction) - /** * @brief The BaseStationSetting enum contains all settings of the base station that can be changed by a client * @@ -85,8 +68,6 @@ public: * @see ScStw::baseStationSettingFromString() * @see ScStw::baseStationSettings */ -======= ->>>>>>> - some changes to file structure:ScStwLibraries/headers/ScStw.hpp enum BaseStationSetting { InvalidSetting = -1, ReadySoundEnableSetting, diff --git a/ScStwLibraries/headers/scstwtimer.h b/ScStwLibraries/headers/scstwtimer.h index 5e3d890..12a4e01 100644 --- a/ScStwLibraries/headers/scstwtimer.h +++ b/ScStwLibraries/headers/scstwtimer.h @@ -4,6 +4,7 @@ #include #include #include +#include #include "ScStw.hpp" class ScStwTimer : public QObject @@ -33,6 +34,7 @@ public slots: // --- main functionality --- bool start(); + bool start(double timeOfStart); bool cancel(); bool stop(); bool stop(TimerState); @@ -42,11 +44,11 @@ public slots: TimerState getState(); double getCurrentTime(); double getReactionTime(); - void refreshDisableStatus(); void setDisabled(bool disabled); protected slots: + void handleClimberStart(double timeOfStart); bool stop(StopReason reason); // --- helper functions --- @@ -57,6 +59,7 @@ signals: void startCanceled(bool falseStart); void reactionTimeChanged(); void stopRequested(); + void requestEnableChange(ScStwTimer* timer); }; diff --git a/ScStwLibraries/sources/scstwtimer.cpp b/ScStwLibraries/sources/scstwtimer.cpp index 17a645f..9ea2588 100644 --- a/ScStwLibraries/sources/scstwtimer.cpp +++ b/ScStwLibraries/sources/scstwtimer.cpp @@ -7,18 +7,36 @@ ScStwTimer::ScStwTimer(QObject *parent) : QObject(parent) this->stopTime = 0; this->stoppedTime = 0; this->reactionTime = 0; + + this->state = IDLE; } bool ScStwTimer::start() { - switch (this->state) { - case STARTING: { - // in case of STARTING, start the race! + return this->start(QDateTime::currentMSecsSinceEpoch()); +} - this->startTime = QDateTime::currentMSecsSinceEpoch(); +bool ScStwTimer::start(double timeOfStart) { + switch (this->state) { + case IDLE: { + // in case of IDLE, start the race! + + this->startTime = timeOfStart; this->stopTime = 0; this->stoppedTime = 0; - this->setState(RUNNING); + if(timeOfStart - QDateTime::currentMSecsSinceEpoch() > 0) { + this->setState(STARTING); + QTimer::singleShot(timeOfStart - QDateTime::currentMSecsSinceEpoch(), [=](){ + if(this->state == STARTING) + this->setState(RUNNING); + }); + QTimer::singleShot(timeOfStart - QDateTime::currentMSecsSinceEpoch() - 1000, [=](){ + //this->handleClimberStart(QDateTime::currentMSecsSinceEpoch()); + }); + + } + else + this->setState(RUNNING); return true; } default: { @@ -28,8 +46,20 @@ bool ScStwTimer::start() { } } +void ScStwTimer::handleClimberStart(double timeOfStart) { + this->reactionTime = timeOfStart - this->startTime; + qDebug() << "+ [INFO][TIMER] reaction time: " << this->reactionTime; + + if(this->reactionTime <= 0){ + this->stop(FailStop); + return; + } + + // TODO: check if necessary: emit this->reactionTimeChanged(); +} + bool ScStwTimer::cancel() { - if(!(this->state == STARTING || this->state == RUNNING)) + if(!(this->state == IDLE || this->state == STARTING || this->state == RUNNING)) return false; this->setState(CANCELLED); @@ -37,7 +67,7 @@ bool ScStwTimer::cancel() { } bool ScStwTimer::stop() { - this->stop(ManualStop); + return this->stop(ManualStop); } bool ScStwTimer::stop(TimerState result) { @@ -76,12 +106,9 @@ bool ScStwTimer::stop(StopReason reason) { } case FailStop: { this->stoppedTime = 0; - //qDebug() << "+ [INFO][TIMER] Stopped: " << "start Time: " << startTime << " stopTime: " << stopTime << " stoppedTime: " << stoppedTime << " reactionTime: " << reactionTime; - if(this->state == RUNNING){ - qDebug() << "+ [INFO][TIMER] False Start detected, step 2: " << "start Time: " << startTime << " startpadTriggerTime: " << startPadTriggerTime << " reactionTime: " << reactionTime; - this->setState(FAILED); - } + qDebug() << "+ [INFO][TIMER] False Start detected: " << "start Time: " << startTime << " reactionTime: " << reactionTime; + this->setState(FAILED); emit startCanceled(true);