2019-03-07 17:18:24 +01:00
|
|
|
#ifndef CLIMBINGRACE_H
|
|
|
|
#define CLIMBINGRACE_H
|
|
|
|
|
|
|
|
#include <QObject>
|
|
|
|
#include <QSound>
|
|
|
|
#include <QSoundEffect>
|
|
|
|
#include <QMediaPlayer>
|
|
|
|
#include "headers/baseconn.h"
|
|
|
|
#include "headers/appsettings.h"
|
|
|
|
#include "headers/speedtimer.h"
|
|
|
|
|
|
|
|
class ClimbingRace : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
Q_PROPERTY(int state READ getState NOTIFY stateChanged)
|
2019-03-24 21:16:16 +01:00
|
|
|
Q_PROPERTY(int mode READ getMode NOTIFY modeChanged)
|
2019-03-07 17:18:24 +01:00
|
|
|
Q_PROPERTY(QVariant timers READ getTimerTextList NOTIFY timerTextChanged)
|
|
|
|
Q_PROPERTY(QString baseStationState READ getBaseStationState NOTIFY baseStationStateChanged)
|
|
|
|
Q_PROPERTY(QVariant baseStationConnections READ getBaseStationConnections NOTIFY baseStationConnectionsChanged)
|
|
|
|
Q_PROPERTY(double nextStartActionDelayProgress READ getNextStartActionDelayProgress NOTIFY nextStartActionDelayProgressChanged)
|
2019-10-13 16:42:38 +02:00
|
|
|
Q_PROPERTY(int nextStartAction READ getNextStartAction NOTIFY nextStartActionChanged)
|
2019-11-02 15:22:50 +01:00
|
|
|
Q_PROPERTY(QVariantMap baseStationProperties READ getBaseStationProperties NOTIFY baseStationPropertiesChanged)
|
2019-03-07 17:18:24 +01:00
|
|
|
|
|
|
|
public:
|
|
|
|
explicit ClimbingRace(QObject *parent = nullptr);
|
|
|
|
|
2019-04-15 13:33:31 +02:00
|
|
|
enum raceState { IDLE, STARTING, WAITING, RUNNING, STOPPED };
|
2019-03-07 17:18:24 +01:00
|
|
|
raceState state;
|
|
|
|
|
|
|
|
enum raceMode { LOCAL, REMOTE };
|
|
|
|
raceMode mode;
|
|
|
|
|
2019-10-13 16:42:38 +02:00
|
|
|
enum NextStartAction { AtYourMarks, Ready, Start, None };
|
|
|
|
|
2019-03-07 17:18:24 +01:00
|
|
|
private:
|
|
|
|
AppSettings * appSettings;
|
|
|
|
BaseConn * baseConn;
|
|
|
|
|
|
|
|
QMediaPlayer * player;
|
|
|
|
|
|
|
|
QTimer * timerTextRefreshTimer;
|
|
|
|
QTimer * nextStartActionTimer;
|
|
|
|
|
2019-03-24 21:16:16 +01:00
|
|
|
QDateTime *date;
|
|
|
|
|
2019-03-07 17:18:24 +01:00
|
|
|
QList<SpeedTimer *> speedTimers;
|
|
|
|
|
2019-10-13 16:42:38 +02:00
|
|
|
NextStartAction nextStartAction;
|
2019-03-07 17:18:24 +01:00
|
|
|
|
|
|
|
double nextStartActionDelayProgress;
|
2019-10-13 16:42:38 +02:00
|
|
|
// only used in remote mode:
|
|
|
|
double nextStartActionDelayStartedAt;
|
|
|
|
double nextStartActionTotalDelay;
|
2019-03-07 17:18:24 +01:00
|
|
|
|
|
|
|
// helper vars
|
|
|
|
QVariantList qmlTimers;
|
2019-03-27 22:23:12 +01:00
|
|
|
const QStringList remoteSettings = {"ready_en", "ready_delay", "at_marks_en", "at_marks_delay"};
|
2019-04-08 18:03:23 +02:00
|
|
|
const QStringList remoteOnlySettings = {"soundVolume"};
|
2019-03-07 17:18:24 +01:00
|
|
|
|
|
|
|
private slots:
|
|
|
|
// helper functions
|
|
|
|
void playSoundsAndStartRace();
|
|
|
|
bool playSound(QString path);
|
|
|
|
void setState(raceState newState);
|
|
|
|
void refreshMode();
|
|
|
|
void refreshTimerText();
|
|
|
|
|
2019-10-06 19:02:47 +02:00
|
|
|
bool refreshRemoteTimers(QVariantList timers);
|
2019-04-15 13:33:31 +02:00
|
|
|
|
2019-03-07 17:18:24 +01:00
|
|
|
signals:
|
2019-10-13 16:42:38 +02:00
|
|
|
void nextStartActionChanged();
|
2019-03-07 17:18:24 +01:00
|
|
|
void nextStartActionDelayProgressChanged();
|
|
|
|
|
|
|
|
void stateChanged(int state);
|
2019-03-24 21:16:16 +01:00
|
|
|
void modeChanged();
|
2019-03-07 17:18:24 +01:00
|
|
|
void timerTextChanged();
|
|
|
|
void baseStationStateChanged();
|
|
|
|
void baseStationConnectionsChanged();
|
2019-11-02 15:22:50 +01:00
|
|
|
void baseStationPropertiesChanged();
|
2019-03-07 17:18:24 +01:00
|
|
|
|
|
|
|
public slots:
|
|
|
|
Q_INVOKABLE int startRace();
|
|
|
|
Q_INVOKABLE int stopRace(int type);
|
|
|
|
Q_INVOKABLE int resetRace();
|
|
|
|
|
2019-10-06 19:02:47 +02:00
|
|
|
// base station sync
|
|
|
|
void handleBaseStationUpdate(QVariant data);
|
2019-11-09 23:10:17 +01:00
|
|
|
Q_INVOKABLE bool pairConnectedUsbExtensions();
|
2019-03-07 17:18:24 +01:00
|
|
|
|
|
|
|
// functions for qml
|
|
|
|
Q_INVOKABLE int getState();
|
2019-03-24 21:16:16 +01:00
|
|
|
Q_INVOKABLE int getMode();
|
2019-03-07 17:18:24 +01:00
|
|
|
Q_INVOKABLE QVariant getTimerTextList();
|
|
|
|
Q_INVOKABLE double getNextStartActionDelayProgress();
|
2019-10-13 16:42:38 +02:00
|
|
|
Q_INVOKABLE int getNextStartAction();
|
2019-03-07 17:18:24 +01:00
|
|
|
|
|
|
|
Q_INVOKABLE void writeSetting(QString key, QVariant value);
|
|
|
|
Q_INVOKABLE QString readSetting(QString key);
|
|
|
|
|
2019-08-20 22:55:37 +02:00
|
|
|
Q_INVOKABLE void connectBaseStation();
|
2019-03-29 23:42:56 +01:00
|
|
|
Q_INVOKABLE void disconnectBaseStation();
|
2019-03-07 17:18:24 +01:00
|
|
|
Q_INVOKABLE QString getBaseStationState();
|
|
|
|
Q_INVOKABLE QVariant getBaseStationConnections();
|
2019-11-02 15:22:50 +01:00
|
|
|
Q_INVOKABLE QVariantMap getBaseStationProperties();
|
|
|
|
|
|
|
|
Q_INVOKABLE bool updateBasestationFirmware();
|
|
|
|
Q_INVOKABLE bool updateBasestationTime();
|
2019-05-02 22:39:22 +02:00
|
|
|
|
|
|
|
// athlete management
|
2019-04-30 23:44:04 +02:00
|
|
|
Q_INVOKABLE QVariant getAthletes();
|
2019-05-02 22:39:22 +02:00
|
|
|
Q_INVOKABLE bool createAthlete( QString userName, QString fullName );
|
|
|
|
Q_INVOKABLE bool deleteAthlete( QString userName );
|
2019-09-08 15:08:50 +02:00
|
|
|
Q_INVOKABLE bool selectAthlete( QString userName, int timerId );
|
2019-05-03 22:54:32 +02:00
|
|
|
Q_INVOKABLE QVariant getResults( QString userName );
|
2019-03-29 23:42:56 +01:00
|
|
|
|
|
|
|
Q_INVOKABLE bool reloadBaseStationIpAdress();
|
2019-03-07 17:18:24 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // CLIMBINGRACE_H
|