fixed problems from rebase

This commit is contained in:
Dorian Zedler 2020-04-14 00:08:58 +02:00
parent 2cfc40444e
commit aff108ee90
Signed by: dorian
GPG key ID: 989DE36109AFA354
3 changed files with 43 additions and 32 deletions

View file

@ -46,21 +46,11 @@ class ScStw : public QObject {
Q_OBJECT Q_OBJECT
public: 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 * @brief The SignalKey enum contains all signal keys a client can subscribe to
* *
* @see ScStw::signalKeyFromInt() * @see ScStw::signalKeyFromInt()
*/ */
=======
>>>>>>> - some changes to file structure:ScStwLibraries/headers/ScStw.hpp
enum SignalKey { enum SignalKey {
InvalidSignal = -1, InvalidSignal = -1,
RaceStateChanged = 9000, RaceStateChanged = 9000,
@ -70,13 +60,6 @@ public:
}; };
Q_ENUM(SignalKey) 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 * @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::baseStationSettingFromString()
* @see ScStw::baseStationSettings * @see ScStw::baseStationSettings
*/ */
=======
>>>>>>> - some changes to file structure:ScStwLibraries/headers/ScStw.hpp
enum BaseStationSetting { enum BaseStationSetting {
InvalidSetting = -1, InvalidSetting = -1,
ReadySoundEnableSetting, ReadySoundEnableSetting,

View file

@ -4,6 +4,7 @@
#include <QObject> #include <QObject>
#include <QDateTime> #include <QDateTime>
#include <QDebug> #include <QDebug>
#include <QTimer>
#include "ScStw.hpp" #include "ScStw.hpp"
class ScStwTimer : public QObject class ScStwTimer : public QObject
@ -33,6 +34,7 @@ public slots:
// --- main functionality --- // --- main functionality ---
bool start(); bool start();
bool start(double timeOfStart);
bool cancel(); bool cancel();
bool stop(); bool stop();
bool stop(TimerState); bool stop(TimerState);
@ -42,11 +44,11 @@ public slots:
TimerState getState(); TimerState getState();
double getCurrentTime(); double getCurrentTime();
double getReactionTime(); double getReactionTime();
void refreshDisableStatus();
void setDisabled(bool disabled); void setDisabled(bool disabled);
protected slots: protected slots:
void handleClimberStart(double timeOfStart);
bool stop(StopReason reason); bool stop(StopReason reason);
// --- helper functions --- // --- helper functions ---
@ -57,6 +59,7 @@ signals:
void startCanceled(bool falseStart); void startCanceled(bool falseStart);
void reactionTimeChanged(); void reactionTimeChanged();
void stopRequested(); void stopRequested();
void requestEnableChange(ScStwTimer* timer);
}; };

View file

@ -7,17 +7,35 @@ ScStwTimer::ScStwTimer(QObject *parent) : QObject(parent)
this->stopTime = 0; this->stopTime = 0;
this->stoppedTime = 0; this->stoppedTime = 0;
this->reactionTime = 0; this->reactionTime = 0;
this->state = IDLE;
} }
bool ScStwTimer::start() { bool ScStwTimer::start() {
switch (this->state) { return this->start(QDateTime::currentMSecsSinceEpoch());
case STARTING: { }
// in case of STARTING, start the race!
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->stopTime = 0;
this->stoppedTime = 0; this->stoppedTime = 0;
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); this->setState(RUNNING);
return true; return true;
} }
@ -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() { bool ScStwTimer::cancel() {
if(!(this->state == STARTING || this->state == RUNNING)) if(!(this->state == IDLE || this->state == STARTING || this->state == RUNNING))
return false; return false;
this->setState(CANCELLED); this->setState(CANCELLED);
@ -37,7 +67,7 @@ bool ScStwTimer::cancel() {
} }
bool ScStwTimer::stop() { bool ScStwTimer::stop() {
this->stop(ManualStop); return this->stop(ManualStop);
} }
bool ScStwTimer::stop(TimerState result) { bool ScStwTimer::stop(TimerState result) {
@ -76,12 +106,9 @@ bool ScStwTimer::stop(StopReason reason) {
} }
case FailStop: { case FailStop: {
this->stoppedTime = 0; 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: " << "start Time: " << startTime << " reactionTime: " << reactionTime;
qDebug() << "+ [INFO][TIMER] False Start detected, step 2: " << "start Time: " << startTime << " startpadTriggerTime: " << startPadTriggerTime << " reactionTime: " << reactionTime;
this->setState(FAILED); this->setState(FAILED);
}
emit startCanceled(true); emit startCanceled(true);