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
*/
enum ErrorCode {
enum StatusCode {
Success = 200,
Error = 900,
@ -89,7 +89,7 @@ public:
TimeoutError = 911,
SettingNotAccessibleError = 901
};
Q_ENUM(ErrorCode)
Q_ENUM(ScStw::StatusCode)
/*!
* \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();
/*! 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
@ -143,7 +149,7 @@ public slots:
* \param value the value to write to
* \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

View file

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

View file

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

View file

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

View file

@ -397,8 +397,6 @@ bool ScStwClient::isFirmwareUpToDate() {
int newFirmwareVersionMinor = newFirmwareVersion.split(".")[1].toInt();
int newFirmwareVersionPatch = newFirmwareVersion.split(".")[2].toInt();
qDebug() << "App firmware version is: " << newFirmwareVersion;
QString currentFirmwareVersion = this->firmwareVersion;
int currentFirmwareVersionMajor = currentFirmwareVersion.split(".")[0].toInt();
int currentFirmwareVersionMinor = currentFirmwareVersion.split(".")[1].toInt();
@ -411,11 +409,17 @@ bool ScStwClient::isFirmwareUpToDate() {
// --- 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;
requestData.append(key);
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) {

View file

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

View file

@ -39,6 +39,7 @@ int ScStwRemoteMonitorRace::start() {
}
void ScStwRemoteMonitorRace::cancelStart() {
this->stop();
return;
}
@ -107,6 +108,8 @@ void ScStwRemoteMonitorRace::handleClientStateChanged() {
case ScStwClient::CONNECTED:
break;
default:
this->timers.clear();
this->setState(IDLE);
break;
}
}
@ -120,7 +123,7 @@ void ScStwRemoteMonitorRace::handleClientStateChanged() {
* @param data
*/
void ScStwRemoteMonitorRace::handleBaseStationSignal(ScStw::SignalKey key, QVariant data) {
qDebug() << "got signal: " << data;
//qDebug() << "got signal: " << data;
switch (key) {
case ScStw::RaceStateChanged:
{
@ -166,7 +169,10 @@ bool ScStwRemoteMonitorRace::refreshRemoteTimers(QVariantList remoteTimers) {
foreach(QVariant remoteTimer, remoteTimers){
// 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)
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
};
}