some fixes and additions for qml

This commit is contained in:
Dorian Zedler 2020-04-19 13:09:24 +02:00
parent f4ee962c98
commit 1ae207a235
Signed by: dorian
GPG key ID: 989DE36109AFA354
8 changed files with 79 additions and 14 deletions

View file

@ -81,7 +81,7 @@ public:
/*! /*!
* \brief The ErrorCode enum contains all error codes that can occur when sending a command to the basestation * \brief The ErrorCode enum contains all error codes that can occur when sending a command to the basestation
*/ */
enum ErrorCode { enum StatusCode {
Success = 200, Success = 200,
Error = 900, Error = 900,
@ -89,7 +89,7 @@ public:
TimeoutError = 911, TimeoutError = 911,
SettingNotAccessibleError = 901 SettingNotAccessibleError = 901
}; };
Q_ENUM(ErrorCode) Q_ENUM(ScStw::StatusCode)
/*! /*!
* \brief SOCKET_MESSAGE_START_KEY contains the key, a message is supposed to start with * \brief SOCKET_MESSAGE_START_KEY contains the key, a message is supposed to start with

View file

@ -135,7 +135,13 @@ public slots:
*/ */
bool isFirmwareUpToDate(); bool isFirmwareUpToDate();
/*! helper functions */ // helper functions
/*!
* \brief Function to pair all extensions that are currently connected via USB to the base station
* \return whether the pairing was successfull
*/
bool pairConnectedUsbExtensions();
/*! /*!
* \brief Function to write a setting on the base station * \brief Function to write a setting on the base station
@ -143,7 +149,7 @@ public slots:
* \param value the value to write to * \param value the value to write to
* \return the status code returned by the command * \return the status code returned by the command
*/ */
ScStw::ErrorCode writeRemoteSetting(ScStw::BaseStationSetting key, QString value); ScStw::StatusCode writeRemoteSetting(ScStw::BaseStationSetting key, QString value);
/*! /*!
* \brief Function to read a setting on the base station * \brief Function to read a setting on the base station

View file

@ -8,12 +8,33 @@
#include "scstwtimer.h" #include "scstwtimer.h"
#include "scstwsoundplayer.h" #include "scstwsoundplayer.h"
/*!
* \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
*
*/
class ScStwRace : public QObject class ScStwRace : public QObject
{ {
Q_OBJECT Q_OBJECT
Q_PROPERTY(RaceState state READ getState NOTIFY stateChanged) Q_PROPERTY(RaceState state READ getState NOTIFY stateChanged)
Q_PROPERTY(QVariantList timers READ getTimerDetailList NOTIFY timersChanged) Q_PROPERTY(QVariantList timers READ getTimerDetailList NOTIFY timersChanged)
Q_PROPERTY(QVariantList nextStartActionDetails READ getNextStartActionDetails NOTIFY nextStartActionDetailsChanged) Q_PROPERTY(QVariantList nextStartActionDetails READ getNextStartActionDetails NOTIFY nextStartActionDetailsChanged)
public: public:
explicit ScStwRace(QObject *parent = nullptr); explicit ScStwRace(QObject *parent = nullptr);
@ -59,7 +80,7 @@ private:
public slots: public slots:
int start(); int start(bool asyncronous = true);
int stop(); int stop();
int reset(); int reset();
void cancelStart(bool falseStart); void cancelStart(bool falseStart);

View file

@ -8,6 +8,7 @@
class ScStwRemoteMonitorRace : public ScStwRace class ScStwRemoteMonitorRace : public ScStwRace
{ {
Q_OBJECT Q_OBJECT
Q_PROPERTY(QVariantList nextStartActionDetails READ getNextStartActionDetails NOTIFY nextStartActionDetailsChanged)
public: public:
ScStwRemoteMonitorRace(ScStwClient *monitorClient, QObject *parent = nullptr); ScStwRemoteMonitorRace(ScStwClient *monitorClient, QObject *parent = nullptr);
@ -24,6 +25,7 @@ public slots:
int stop(); int stop();
int reset(); int reset();
bool addTimer(ScStwTimer *timer); bool addTimer(ScStwTimer *timer);
QVariantList getNextStartActionDetails();
private slots: private slots:
void handleClientStateChanged(); void handleClientStateChanged();

View file

@ -14,6 +14,7 @@
* It is recommended to use it in combination with the ScStwRace class. * It is recommended to use it in combination with the ScStwRace class.
* *
* ## When using standalone: * ## When using standalone:
*
* \code{.cpp} * \code{.cpp}
* ScStwTimer timer; * ScStwTimer timer;
* // start the timer * // start the timer

View file

@ -397,8 +397,6 @@ bool ScStwClient::isFirmwareUpToDate() {
int newFirmwareVersionMinor = newFirmwareVersion.split(".")[1].toInt(); int newFirmwareVersionMinor = newFirmwareVersion.split(".")[1].toInt();
int newFirmwareVersionPatch = newFirmwareVersion.split(".")[2].toInt(); int newFirmwareVersionPatch = newFirmwareVersion.split(".")[2].toInt();
qDebug() << "App firmware version is: " << newFirmwareVersion;
QString currentFirmwareVersion = this->firmwareVersion; QString currentFirmwareVersion = this->firmwareVersion;
int currentFirmwareVersionMajor = currentFirmwareVersion.split(".")[0].toInt(); int currentFirmwareVersionMajor = currentFirmwareVersion.split(".")[0].toInt();
int currentFirmwareVersionMinor = currentFirmwareVersion.split(".")[1].toInt(); int currentFirmwareVersionMinor = currentFirmwareVersion.split(".")[1].toInt();
@ -411,11 +409,17 @@ bool ScStwClient::isFirmwareUpToDate() {
// --- helper functions --- // --- helper functions ---
// ------------------------ // ------------------------
ScStw::ErrorCode ScStwClient::writeRemoteSetting(ScStw::BaseStationSetting key, QString value) { bool ScStwClient::pairConnectedUsbExtensions() {
QVariantMap ret = this->sendCommand(5002, "", 10000);
qDebug() << ret;
return ScStw::StatusCode(ret["status"].toInt()) == ScStw::Success;
}
ScStw::StatusCode ScStwClient::writeRemoteSetting(ScStw::BaseStationSetting key, QString value) {
QJsonArray requestData; QJsonArray requestData;
requestData.append(key); requestData.append(key);
requestData.append(value); requestData.append(value);
return ScStw::ErrorCode(this->sendCommand(3000, requestData)["status"].toInt()); return ScStw::StatusCode(this->sendCommand(3000, requestData)["status"].toInt());
} }
QString ScStwClient::readRemoteSetting(ScStw::BaseStationSetting key) { QString ScStwClient::readRemoteSetting(ScStw::BaseStationSetting key) {

View file

@ -33,7 +33,7 @@ ScStwRace::ScStwRace(QObject *parent) : QObject(parent)
* @brief ScStwRace::startRace * @brief ScStwRace::startRace
* @return {int} 200: OK; 904: MAIN state not matching * @return {int} 200: OK; 904: MAIN state not matching
*/ */
int ScStwRace::start() { int ScStwRace::start(bool asyncronous) {
if(this->state != IDLE) { if(this->state != IDLE) {
return 904; return 904;
} }
@ -42,7 +42,11 @@ int ScStwRace::start() {
this->setState(STARTING); this->setState(STARTING);
this->playSoundsAndStartTimers(None); if(asyncronous) {
QTimer::singleShot(1, [=](){this->playSoundsAndStartTimers(None);});
}
else
this->playSoundsAndStartTimers(None);
return 200; return 200;
} }
@ -245,7 +249,7 @@ bool ScStwRace::playSoundsAndStartTimers(StartAction thisAction) {
*/ */
void ScStwRace::setState(RaceState newState) { void ScStwRace::setState(RaceState newState) {
if(newState != this->state) { if(newState != this->state) {
qDebug() << "+ [INFO][MAIN] state changed: " << newState; qDebug() << "[INFO][RACE] state changed: " << newState;
this->state = newState; this->state = newState;
emit this->stateChanged(newState); emit this->stateChanged(newState);

View file

@ -39,6 +39,7 @@ int ScStwRemoteMonitorRace::start() {
} }
void ScStwRemoteMonitorRace::cancelStart() { void ScStwRemoteMonitorRace::cancelStart() {
this->stop();
return; return;
} }
@ -107,6 +108,8 @@ void ScStwRemoteMonitorRace::handleClientStateChanged() {
case ScStwClient::CONNECTED: case ScStwClient::CONNECTED:
break; break;
default: default:
this->timers.clear();
this->setState(IDLE);
break; break;
} }
} }
@ -120,7 +123,7 @@ void ScStwRemoteMonitorRace::handleClientStateChanged() {
* @param data * @param data
*/ */
void ScStwRemoteMonitorRace::handleBaseStationSignal(ScStw::SignalKey key, QVariant data) { void ScStwRemoteMonitorRace::handleBaseStationSignal(ScStw::SignalKey key, QVariant data) {
qDebug() << "got signal: " << data; //qDebug() << "got signal: " << data;
switch (key) { switch (key) {
case ScStw::RaceStateChanged: case ScStw::RaceStateChanged:
{ {
@ -166,7 +169,10 @@ bool ScStwRemoteMonitorRace::refreshRemoteTimers(QVariantList remoteTimers) {
foreach(QVariant remoteTimer, remoteTimers){ foreach(QVariant remoteTimer, remoteTimers){
// create a local timer for each remote timer // create a local timer for each remote timer
this->timers.append(new ScStwTimer(this, true)); ScStwTimer * timer = new ScStwTimer(this, true);
this->timers.append(timer);
connect(timer, &ScStwTimer::stateChanged, this, &ScStwRace::timersChanged);
connect(timer, &ScStwTimer::reactionTimeChanged, this, &ScStwRace::timersChanged);
} }
} }
@ -192,3 +198,24 @@ bool ScStwRemoteMonitorRace::addTimer(ScStwTimer* timer) {
Q_UNUSED(timer) Q_UNUSED(timer)
return false; return false;
} }
QVariantList ScStwRemoteMonitorRace::getNextStartActionDetails() {
int nextActionDelay = 0;
double nextActionDelayProg = -1;
if(this->nextStartAction == AtYourMarks || this->nextStartAction == Ready) {
// get the total delay and the delay progress of the next action timer
double elapsed = QDateTime::currentMSecsSinceEpoch() - this->nextStartActionDelayStartedAt;
nextActionDelay = this->nextStartActionTotalDelay;
if(elapsed < 0 || elapsed > nextActionDelay) {
elapsed = nextActionDelay;
}
nextActionDelayProg = elapsed / nextActionDelay;
}
return {
this->nextStartAction,
nextActionDelay,
nextActionDelayProg
};
}