diff --git a/CHANGELOG b/CHANGELOG index c2cf6ad..002ede0 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [Unreleased] ### Added - added profiles dialog +- buzzer icon in the upper left corner indicating that the buzzer is connected ### Fixed - start seqnece continues in a buggy way when cancel is being pressed while 'at your marks' or 'ready' - bug that made the start sequence freeze if a delay of zero or lower or a non valid number was set as delay diff --git a/graphics/Buzzer.xcf b/graphics/Buzzer.xcf index 388afd7..c8bf7cd 100644 Binary files a/graphics/Buzzer.xcf and b/graphics/Buzzer.xcf differ diff --git a/graphics/icons/buzzer_black.png b/graphics/icons/buzzer_black.png new file mode 100644 index 0000000..5f34787 Binary files /dev/null and b/graphics/icons/buzzer_black.png differ diff --git a/headers/buzzerconn.h b/headers/buzzerconn.h index f20454e..51b1616 100644 --- a/headers/buzzerconn.h +++ b/headers/buzzerconn.h @@ -30,19 +30,29 @@ public: private: QNetworkAccessManager *networkManager; + QNetworkAccessManager *reloadNetworkManager; QDateTime *date; signals: public slots: - ReturnData_t senddata(QUrl serviceUrl, int timeout); + ReturnData_t senddata(QNetworkAccessManager * NetMan, QUrl serviceUrl, int timeout); + //function to communicate with the buzzer Q_INVOKABLE QList gettimes(int timeout); + //function to get the times from the buzzer as a list with the normal network manager Q_INVOKABLE bool connect(); - Q_INVOKABLE bool calcoffset(); + //function to connect to buzzer + Q_INVOKABLE bool calcoffset(QList times); + //function that calculates the average time offset between the buzzer and the device Q_INVOKABLE bool buzzer_triggered(); + //function that checks ih the buzzer has been pushed since the last call of this function Q_INVOKABLE bool start(); + //syncs the buzzer and the base to make a start possible Q_INVOKABLE double get(QString key); + //can return some things (offset, lastpressed, currtime, connection_progress, connected) Q_INVOKABLE QString test(); + Q_INVOKABLE bool refresh(); + //refreshed the connection to the buzzer }; #endif // BUZZERCONN_H diff --git a/qml/main.qml b/qml/main.qml index 311a0bc..0d51762 100644 --- a/qml/main.qml +++ b/qml/main.qml @@ -43,11 +43,13 @@ Window { Timer { //timer that refreshes the connection state to the buzzer - running: false - repeat: true - interval: 500 + id: connectionRefreshTimer + running: root.state !== "RUNNING" && root.state !== "STARTING" + repeat: false + interval: 1000 onTriggered: { - console.log(_cppBuzzerConn.calcoffset()) + _cppBuzzerConn.refresh() + connectionRefreshTimer.start() } } @@ -149,7 +151,7 @@ Window { onPlayingChanged: { if(!playing && root.state==="STARTING"){ root.startTime = _cppBuzzerConn.get("currtime") - _cppBuzzerConn.start() + root.currTime = _cppBuzzerConn.get("currtime") time.text = ( ( root.currTime - root.startTime ) / 1000 ).toFixed(3) + " sec" root.state = "RUNNING" @@ -181,17 +183,31 @@ Window { } } - Rectangle { + Image { + id: buzzerLogo + source: "qrc:/graphics/icons/buzzer_black.png" + mipmap: true anchors { top: parent.top topMargin: 10 left: parent.left leftMargin: 10 } - + visible: _cppBuzzerConn.get("connected")===1 + height: root.landscape()? root.height*0.1:root.width*0.1 width: height - radius: height*0.5 - color: "#6efc0f" + Component.onCompleted: { + visible= _cppBuzzerConn.get("connected")===1 + } + + Timer { + interval: 100 + running: true + repeat: true + onTriggered: { + buzzerLogo.visible= _cppBuzzerConn.get("connected")===1 + } + } } Rectangle { diff --git a/shared.qrc b/shared.qrc index 20004de..ff1b551 100644 --- a/shared.qrc +++ b/shared.qrc @@ -13,5 +13,6 @@ sounds/at_marks_1.wav sounds/ready_2.wav sounds/at_marks_2.wav + graphics/icons/buzzer_black.png diff --git a/sources/buzzerconn.cpp b/sources/buzzerconn.cpp index e390163..1efa6cd 100644 --- a/sources/buzzerconn.cpp +++ b/sources/buzzerconn.cpp @@ -3,6 +3,7 @@ BuzzerConn::BuzzerConn(QObject *parent) : QObject(parent) { this->networkManager = new QNetworkAccessManager(); + this->reloadNetworkManager = new QNetworkAccessManager(); this->date = new QDateTime; this->latest_button_pressed = 0; @@ -15,30 +16,31 @@ bool BuzzerConn::connect() QList times = gettimes(1000); qDebug() << times[0]; if(times[0] == 200.0){ - this->connected = true; this->latest_button_pressed = times[2]; for(int i=0;i<=100;i++){ this->connection_progress = i; - if(!calcoffset()){ + if(!calcoffset(this->gettimes(1000))){ this->connection_progress = 100; + this->connected = false; return(false); } } - + this->connected = true; return(true); } else{ + this->connected = false; return(false); } } -bool BuzzerConn::calcoffset() +bool BuzzerConn::calcoffset(QList times) { - QList times = gettimes(1000); if(times.length() != 3){ return(false); } - if(times[0] == 200.0 && this->connected){ + if(times[0] == 200.0){ + this->latest_button_pressed = times[2]; double offset = date->currentMSecsSinceEpoch() - times[1]; if(this->latest_offsets.length()>=100){ this->latest_offsets.removeFirst(); @@ -54,7 +56,7 @@ bool BuzzerConn::calcoffset() return(true); } else { - this->connected = false; + //this->connected = false; return(false); } } @@ -62,7 +64,7 @@ bool BuzzerConn::calcoffset() QList BuzzerConn::gettimes(int timeout) { QList times; - ReturnData_t ret = senddata(QUrl("http://192.168.4.1"), timeout); + ReturnData_t ret = senddata(this->networkManager, QUrl("http://192.168.4.1"), timeout); times.append(double(ret.status_code)); if(ret.status_code == 200){ @@ -142,11 +144,35 @@ double BuzzerConn::get(QString key) QString BuzzerConn::test() { - ReturnData_t ret = this->senddata(QUrl("http://www.google.de"), 500); + ReturnData_t ret = this->senddata(this->networkManager, QUrl("http://www.google.de"), 500); return(ret.text); } -ReturnData_t BuzzerConn::senddata(QUrl serviceUrl, int timeout) +bool BuzzerConn::refresh() +{ + if(!this->connected){ + return(false); + } + QList times; + ReturnData_t ret = senddata(this->reloadNetworkManager, QUrl("http://192.168.4.1"), 1000); + times.append(double(ret.status_code)); + + if(ret.status_code == 200){ + ret.text.replace("\n",""); + ret.text.replace("\r",""); + QStringList times_cache = ret.text.split("
"); + times.append(times_cache[0].toDouble()); + times.append(times_cache[1].toDouble()); + calcoffset(times); + return(true); + } + else{ + this->connected = false; + return(false); + } +} + +ReturnData_t BuzzerConn::senddata(QNetworkAccessManager * NetMan, QUrl serviceUrl, int timeout) { ReturnData_t ret; //this is a custom type to store the returned data @@ -166,10 +192,10 @@ ReturnData_t BuzzerConn::senddata(QUrl serviceUrl, int timeout) timer.setSingleShot(true); loop.connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit())); - loop.connect(this->networkManager, SIGNAL(finished(QNetworkReply*)), SLOT(quit())); + loop.connect(NetMan, SIGNAL(finished(QNetworkReply*)), SLOT(quit())); timer.start(timeout); - reply = this->networkManager->post(request, pdata.toString(QUrl::FullyEncoded).toUtf8()); + reply = NetMan->post(request, pdata.toString(QUrl::FullyEncoded).toUtf8()); loop.exec(); timer.stop();