diff --git a/graphics/BaseStation.xcf b/graphics/BaseStation.xcf new file mode 100644 index 0000000..a4d75f3 Binary files /dev/null and b/graphics/BaseStation.xcf differ diff --git a/graphics/icons/BaseStation.png b/graphics/icons/BaseStation.png new file mode 100644 index 0000000..1956399 Binary files /dev/null and b/graphics/icons/BaseStation.png differ diff --git a/graphics/icons/BaseStation_black.png b/graphics/icons/BaseStation_black.png new file mode 100644 index 0000000..6c7e61e Binary files /dev/null and b/graphics/icons/BaseStation_black.png differ diff --git a/headers/apptheme.h b/headers/apptheme.h index 2e4bbf9..0fd5d29 100644 --- a/headers/apptheme.h +++ b/headers/apptheme.h @@ -24,7 +24,7 @@ signals: public slots: QVariant getStyle(); - Q_INVOKABLE bool changeTheme(); + Q_INVOKABLE void changeTheme(); }; #endif // APPTHEME_H diff --git a/headers/baseconn.h b/headers/baseconn.h index ee0bbdd..afcc757 100644 --- a/headers/baseconn.h +++ b/headers/baseconn.h @@ -26,7 +26,7 @@ public: // values for the socket connection int connection_progress; QString ip; - qint16 port = 3563; + ushort port = 3563; int errors; int errors_until_disconnect = 4; diff --git a/headers/climbingrace.h b/headers/climbingrace.h index e10e568..4500cd8 100644 --- a/headers/climbingrace.h +++ b/headers/climbingrace.h @@ -14,6 +14,7 @@ class ClimbingRace : public QObject Q_OBJECT Q_PROPERTY(int state READ getState NOTIFY stateChanged) + Q_PROPERTY(int mode READ getMode NOTIFY modeChanged) Q_PROPERTY(QVariant timers READ getTimerTextList NOTIFY timerTextChanged) Q_PROPERTY(QString baseStationState READ getBaseStationState NOTIFY baseStationStateChanged) Q_PROPERTY(QVariant baseStationConnections READ getBaseStationConnections NOTIFY baseStationConnectionsChanged) @@ -38,6 +39,8 @@ private: QTimer * timerTextRefreshTimer; QTimer * nextStartActionTimer; + QDateTime *date; + QList speedTimers; int nextStartAction; @@ -63,6 +66,7 @@ signals: void nextStartActionDelayProgressChanged(); void stateChanged(int state); + void modeChanged(); void timerTextChanged(); void baseStationStateChanged(); void baseStationConnectionsChanged(); @@ -76,6 +80,7 @@ public slots: // functions for qml Q_INVOKABLE int getState(); + Q_INVOKABLE int getMode(); Q_INVOKABLE QVariant getTimerTextList(); Q_INVOKABLE double getNextStartActionDelayProgress(); diff --git a/qml/components/ConnectionIcon.qml b/qml/components/ConnectionIcon.qml index 7566f45..0a19e49 100644 --- a/qml/components/ConnectionIcon.qml +++ b/qml/components/ConnectionIcon.qml @@ -7,8 +7,8 @@ Image { source: "qrc:/graphics/icons/buzzer_black.png" mipmap: true - opacity: status !== "disconnected" ? 1:0 - visible: false + opacity: status === "connected" || status === "connecting" ? 1:0 + visible: true width: height onOpacityChanged: visible = true diff --git a/qml/components/ProgressCircle.qml b/qml/components/ProgressCircle.qml index 3fa6350..a1e7317 100644 --- a/qml/components/ProgressCircle.qml +++ b/qml/components/ProgressCircle.qml @@ -47,7 +47,7 @@ Item { enabled: true NumberAnimation { duration: root.animationDuration - easing.type: Easing.InOutCubic + easing.type: Easing.Linear } } @@ -56,7 +56,7 @@ Item { enabled: true NumberAnimation { duration: root.animationDuration - easing.type: Easing.InOutCubic + easing.type: Easing.Linear } } diff --git a/qml/main.qml b/qml/main.qml index dd319d8..3a2277c 100644 --- a/qml/main.qml +++ b/qml/main.qml @@ -141,6 +141,63 @@ Window { } } + Item { + id: connectionIconContainer + + anchors { + top: parent.top + left: parent.left + right: parent.right + bottom: parent.bottom + bottomMargin: root.landscape() ? 0:parent.height * 0.8 + rightMargin: root.landscape() ? parent.width * 0.8:0 + } + + ConnectionIcon { + id: baseConnConnIcon + status: speedBackend.baseStationState + + source: "qrc:/graphics/icons/BaseStation_black.png" + anchors { + top: parent.top + topMargin: 10 + left: parent.left + leftMargin: 10 + } + scale: 1.3 + height: !root.landscape()? parent.height*0.3:parent.width*0.3 + } + + ConnectionIcon { + id: buzzerConnIcon + status: speedBackend.baseStationConnections[1]["state"] + + source: "qrc:/graphics/icons/buzzer_black.png" + anchors { + top: parent.top + topMargin: 10 + left: baseConnConnIcon.right + leftMargin: 1 + } + height: !root.landscape()? parent.height*0.17:parent.width*0.17 + } + + ConnectionIcon { + id: startpadConnIcon + status: speedBackend.baseStationConnections[0]["state"] + + source: "qrc:/graphics/icons/startpad_black.png" + anchors { + top: parent.top + topMargin: 10 + left: buzzerConnIcon.right + leftMargin: 0 + } + height: !root.landscape() ? parent.height*0.17:parent.width*0.17 + } + } + + Rectangle { id: upper_line width: root.landscape() ? 1:parent.width @@ -226,7 +283,7 @@ Window { } } - animationDuration: 0 + animationDuration: speedBackend.mode === 1 ? 150:0 } /*---------------------- diff --git a/shared.qrc b/shared.qrc index 30f93c4..4eeeff4 100644 --- a/shared.qrc +++ b/shared.qrc @@ -22,5 +22,7 @@ graphics/icons/startpad_black.png sounds/false.wav graphics/icons/error.png + graphics/icons/BaseStation.png + graphics/icons/BaseStation_black.png diff --git a/sources/apptheme.cpp b/sources/apptheme.cpp index ae45771..5939698 100644 --- a/sources/apptheme.cpp +++ b/sources/apptheme.cpp @@ -82,7 +82,7 @@ QVariant AppTheme::getStyle() { return *this->currentTheme; } -bool AppTheme::changeTheme() { +void AppTheme::changeTheme() { QString currentThemeString = pGlobalAppSettings->loadSetting("theme"); QString newThemeString = "Light"; diff --git a/sources/baseconn.cpp b/sources/baseconn.cpp index cd77c9b..3a539b6 100644 --- a/sources/baseconn.cpp +++ b/sources/baseconn.cpp @@ -122,14 +122,6 @@ QVariantMap BaseConn::sendCommand(int header, QJsonValue data){ QString jsonRequest = QJsonDocument(requestObj).toJson(); - QByteArray arrBlock; - QDataStream out(&arrBlock, QIODevice::WriteOnly); - //out.setVersion(QDataStream::Qt_5_10); - out << quint16(0) << jsonRequest; - - out.device()->seek(0); - out << quint16(ulong(arrBlock.size()) - sizeof(quint16)); - QTimer timer; timer.setSingleShot(true); @@ -142,7 +134,7 @@ QVariantMap BaseConn::sendCommand(int header, QJsonValue data){ //write data - socket->write(arrBlock); + socket->write(jsonRequest.toLatin1()); //wait for an answer to finish (programm gets stuck in here) loop.exec(); @@ -171,50 +163,27 @@ QVariantMap BaseConn::sendCommand(int header, QJsonValue data){ } void BaseConn::readyRead() { - QDataStream in(socket); - //in.setVersion(QDataStream::Qt_5_10); - qint16 nextBlockSize = 0; - for (;;) - { - if (!nextBlockSize) - { - if (ulong(socket->bytesAvailable()) < sizeof(quint16)) { break; } - in >> nextBlockSize; - } - if (socket->bytesAvailable() < nextBlockSize) { break; } + QString reply = socket->readAll(); + int id = 0; - QString str; in >> str; + QJsonDocument jsonReply = QJsonDocument::fromJson(reply.toUtf8()); + QJsonObject replyObj = jsonReply.object(); - // if (str == "0") - // { - // str = "Connection closed"; - // closeConnection(); - // } + if(!replyObj.isEmpty()){ + id = replyObj.value("id").toInt(); - nextBlockSize = 0; - QString reply = str; - int id = 0; - - QJsonDocument jsonReply = QJsonDocument::fromJson(reply.toUtf8()); - QJsonObject replyObj = jsonReply.object(); - - if(!replyObj.isEmpty()){ - id = replyObj.value("id").toInt(); - - for(int i = 0; i < this->waitingRequests.length(); i++){ - if(this->waitingRequests[i].id == id){ - this->waitingRequests[i].reply = replyObj; - this->waitingRequests[i].loop->quit(); - return; - } + for(int i = 0; i < this->waitingRequests.length(); i++){ + if(this->waitingRequests[i].id == id){ + this->waitingRequests[i].reply = replyObj; + this->waitingRequests[i].loop->quit(); + return; } } - - latestReadReply = str; - emit gotUnexpectedReply(str); - } + + latestReadReply = reply; + emit gotUnexpectedReply(reply); } int BaseConn::writeRemoteSetting(QString key, QString value) { diff --git a/sources/climbingrace.cpp b/sources/climbingrace.cpp index 71eaee8..b20f0ab 100644 --- a/sources/climbingrace.cpp +++ b/sources/climbingrace.cpp @@ -18,18 +18,19 @@ ClimbingRace::ClimbingRace(QObject *parent) : QObject(parent) this->appSettings = new AppSettings; this->baseConn = new BaseConn; - this->baseConn->setIP("192.168.4.1"); + this->baseConn->setIP("ScStw"); connect(this->baseConn, &BaseConn::stateChanged, this, &ClimbingRace::baseStationStateChanged); this->speedTimers.append( new SpeedTimer ); this->player = new QMediaPlayer; + this->date = new QDateTime; this->nextStartActionTimer = new QTimer(this); nextStartActionTimer->setSingleShot(true); this->baseStationSyncTimer = new QTimer(); - this->baseStationSyncTimer->setInterval(10); + this->baseStationSyncTimer->setInterval(100); this->baseStationSyncTimer->setSingleShot(true); this->baseStationSyncTimer->connect(this->baseStationSyncTimer, &QTimer::timeout, this, &ClimbingRace::syncWithBaseStation); this->baseStationSyncTimer->start(); @@ -228,19 +229,19 @@ void ClimbingRace::syncWithBaseStation() { speedTimers[0]->setState(SpeedTimer::STARTING); } - tmpReply = this->baseConn->sendCommand(2004); - if(tmpReply["status"] != 200){ - //handle Error!! - qDebug() << "+ --- getting next start action from basestation failed: " << tmpReply["status"]; - this->baseStationSyncTimer->start(); - return; - } - else { - if(this->nextStartAction != tmpReply["data"].toInt()){ - this->nextStartAction = tmpReply["data"].toInt(); - this->nextStartActionChanged(this->nextStartAction); - } - } +// tmpReply = this->baseConn->sendCommand(2004); +// if(tmpReply["status"] != 200){ +// //handle Error!! +// qDebug() << "+ --- getting next start action from basestation failed: " << tmpReply["status"]; +// this->baseStationSyncTimer->start(); +// return; +// } +// else { +// if(this->nextStartAction != tmpReply["data"].toInt()){ +// this->nextStartAction = tmpReply["data"].toInt(); +// this->nextStartActionChanged(this->nextStartAction); +// } +// } tmpReply = this->baseConn->sendCommand(2005); if(tmpReply["status"] != 200){ @@ -270,6 +271,7 @@ void ClimbingRace::syncWithBaseStation() { else { QVariantList timers = tmpReply["data"].toList(); + speedTimers[0]->startTime = this->date->currentMSecsSinceEpoch() - timers[0].toMap()["currTime"].toDouble(); speedTimers[0]->stoppedTime = timers[0].toMap()["currTime"].toDouble(); speedTimers[0]->reactionTime = timers[0].toMap()["reactTime"].toDouble(); @@ -392,12 +394,19 @@ void ClimbingRace::setState(raceState newState) { } void ClimbingRace::refreshMode() { + raceMode newMode; if(this->baseConn->state == "connected"){ - this->mode = REMOTE; + newMode = REMOTE; } else { - this->mode = LOCAL; + newMode = LOCAL; } + + if(this->mode != newMode){ + this->mode = newMode; + emit this->modeChanged(); + } + } void ClimbingRace::refreshTimerText() { @@ -456,6 +465,10 @@ int ClimbingRace::getState() { return this->state; } +int ClimbingRace::getMode() { + return this->mode; +} + QVariant ClimbingRace::getTimerTextList() { return this->qmlTimers; // QVariantList test;