2020-06-07 14:43:47 +02:00
|
|
|
/****************************************************************************
|
|
|
|
** ScStw Libraries
|
|
|
|
** Copyright (C) 2020 Itsblue development
|
|
|
|
**
|
|
|
|
** This program is free software: you can redistribute it and/or modify
|
|
|
|
** it under the terms of the GNU General Public License as published by
|
|
|
|
** the Free Software Foundation, either version 3 of the License, or
|
|
|
|
** (at your option) any later version.
|
|
|
|
**
|
|
|
|
** This program is distributed in the hope that it will be useful,
|
|
|
|
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
** GNU General Public License for more details.
|
|
|
|
**
|
|
|
|
** You should have received a copy of the GNU General Public License
|
|
|
|
** along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
****************************************************************************/
|
|
|
|
|
2020-04-11 23:41:34 +02:00
|
|
|
#ifndef SCSTWRACE_H
|
|
|
|
#define SCSTWRACE_H
|
|
|
|
|
|
|
|
#include <QObject>
|
|
|
|
#include <QDebug>
|
|
|
|
#include <QTimer>
|
|
|
|
#include <QEventLoop>
|
|
|
|
#include "scstwtimer.h"
|
|
|
|
#include "scstwsoundplayer.h"
|
|
|
|
|
2020-04-19 13:09:24 +02:00
|
|
|
/*!
|
|
|
|
* \brief The ScStwRace class can be used to measure timings of climbing races with multiple lanes at once.
|
|
|
|
*
|
|
|
|
* The ScStwRace is a container to manage multiple timers at a time and introduces a propper start sequence
|
|
|
|
* with start commands ('At your Marks' and 'Ready') and the official IFSC start signal.
|
|
|
|
*
|
|
|
|
* ## Basic usage:
|
|
|
|
*
|
|
|
|
* \code
|
|
|
|
* ScStwRace race;
|
|
|
|
*
|
|
|
|
* // add two timers
|
|
|
|
* race.addTimer(new ScStwTimer());
|
|
|
|
* race.addTimer(new ScStwTimer());
|
|
|
|
*
|
|
|
|
* // start a race
|
|
|
|
* race.start();
|
|
|
|
* \endcode
|
|
|
|
*
|
|
|
|
*/
|
2020-04-11 23:41:34 +02:00
|
|
|
class ScStwRace : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
2020-04-15 21:47:04 +02:00
|
|
|
Q_PROPERTY(RaceState state READ getState NOTIFY stateChanged)
|
2020-04-17 19:57:00 +02:00
|
|
|
Q_PROPERTY(QVariantList timers READ getTimerDetailList NOTIFY timersChanged)
|
|
|
|
Q_PROPERTY(QVariantList nextStartActionDetails READ getNextStartActionDetails NOTIFY nextStartActionDetailsChanged)
|
2020-04-19 13:09:24 +02:00
|
|
|
|
2020-04-11 23:41:34 +02:00
|
|
|
public:
|
|
|
|
explicit ScStwRace(QObject *parent = nullptr);
|
|
|
|
|
|
|
|
enum RaceState { IDLE, STARTING, WAITING, RUNNING, STOPPED };
|
|
|
|
Q_ENUM(RaceState)
|
|
|
|
|
2020-04-17 19:57:00 +02:00
|
|
|
enum StartAction { None = -1, AtYourMarks = 0, Ready = 1, Start = 2 };
|
2020-04-11 23:41:34 +02:00
|
|
|
Q_ENUM(StartAction)
|
|
|
|
|
2020-04-17 19:57:00 +02:00
|
|
|
enum NextStartActionDetailAttributes {
|
|
|
|
NextStartAction = 0,
|
|
|
|
NextStartActionTotalDelay = 1,
|
|
|
|
NextStartActionDelayProgress = 2
|
|
|
|
};
|
|
|
|
Q_ENUM(NextStartActionDetailAttributes);
|
|
|
|
|
2020-04-18 14:25:48 +02:00
|
|
|
protected:
|
|
|
|
StartAction nextStartAction;
|
|
|
|
QList<ScStwTimer *> timers;
|
|
|
|
void setState(RaceState newState);
|
|
|
|
|
2020-04-11 23:41:34 +02:00
|
|
|
private:
|
|
|
|
RaceState state;
|
|
|
|
|
|
|
|
QList<ScStwTimer*> timerEnableQueque;
|
|
|
|
|
|
|
|
QTimer *nextActionTimer;
|
|
|
|
QEventLoop *nextActionLoop;
|
|
|
|
|
|
|
|
// sounds
|
|
|
|
ScStwSoundPlayer * soundPlayer;
|
|
|
|
|
|
|
|
|
|
|
|
// some settings
|
|
|
|
double soundVolume;
|
|
|
|
|
2020-04-15 19:21:32 +02:00
|
|
|
/*!
|
|
|
|
* \brief stores the start action settings
|
2020-04-11 23:41:34 +02:00
|
|
|
*
|
2020-04-15 19:21:32 +02:00
|
|
|
* \details Stores the settings for the action ScStwRace::AtYourMarks and ScStwRace::Ready. The settings keys are: "Enabled" and "Delay"
|
2020-04-11 23:41:34 +02:00
|
|
|
*/
|
|
|
|
QMap<StartAction, QVariantMap> startActionSettings;
|
|
|
|
|
|
|
|
|
|
|
|
public slots:
|
2020-04-19 22:39:33 +02:00
|
|
|
/*!
|
|
|
|
* \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
|
|
|
|
*/
|
2020-04-19 13:09:24 +02:00
|
|
|
int start(bool asyncronous = true);
|
2020-04-19 22:39:33 +02:00
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Function to stop the currently running race
|
|
|
|
*
|
|
|
|
* \return 200: OK; 904: state not matching
|
|
|
|
*/
|
2020-05-26 15:59:55 +02:00
|
|
|
virtual int stop();
|
2020-04-19 22:39:33 +02:00
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Function to reset a stopped race
|
|
|
|
* \return
|
|
|
|
*/
|
2020-05-26 15:59:55 +02:00
|
|
|
virtual int reset();
|
2020-05-26 17:57:32 +02:00
|
|
|
virtual int cancel();
|
2020-04-17 19:57:00 +02:00
|
|
|
|
|
|
|
// setters
|
2020-04-11 23:41:34 +02:00
|
|
|
bool writeStartActionSetting(StartAction action, bool enabled, int delay);
|
|
|
|
bool setSoundVolume(double volume);
|
2020-05-26 15:59:55 +02:00
|
|
|
virtual bool addTimer(ScStwTimer *timer);
|
2020-04-17 19:57:00 +02:00
|
|
|
|
|
|
|
// getters
|
2020-04-11 23:41:34 +02:00
|
|
|
RaceState getState();
|
|
|
|
StartAction getNextStartAction();
|
2020-05-26 15:59:55 +02:00
|
|
|
virtual QVariantList getNextStartActionDetails();
|
2020-04-11 23:41:34 +02:00
|
|
|
QVariantList getTimerDetailList();
|
|
|
|
|
2020-04-18 14:25:48 +02:00
|
|
|
protected slots:
|
|
|
|
|
|
|
|
|
2020-04-11 23:41:34 +02:00
|
|
|
private slots:
|
|
|
|
void refreshTimerStates();
|
|
|
|
void handleTimerEnable(ScStwTimer* timer);
|
2020-04-19 22:39:33 +02:00
|
|
|
int handleFalseStart();
|
2020-04-11 23:41:34 +02:00
|
|
|
bool playSoundsAndStartTimers(StartAction thisAction);
|
2020-04-19 22:39:33 +02:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Function to declare the winner and looser timers after a timer has been stopped
|
|
|
|
*/
|
2020-04-18 14:25:48 +02:00
|
|
|
void handleTimerStop();
|
2020-04-11 23:41:34 +02:00
|
|
|
|
|
|
|
signals:
|
|
|
|
void startTimers();
|
|
|
|
void stopTimers(int type);
|
|
|
|
void resetTimers();
|
|
|
|
void stateChanged(RaceState state);
|
|
|
|
void nextStartActionChanged();
|
2020-04-17 19:57:00 +02:00
|
|
|
void nextStartActionDetailsChanged();
|
|
|
|
void timersChanged();
|
2020-04-11 23:41:34 +02:00
|
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // SCSTWRACE_H
|