From b6a440efde0c1a3b198c9adbf887e0227f518c2f Mon Sep 17 00:00:00 2001 From: Dorian Zedler Date: Sun, 9 Sep 2018 20:18:00 +0200 Subject: [PATCH] the startpad is now fully functional --- headers/buzzerconn.h | 6 ++++-- qml/SettingsDialog.qml | 2 +- qml/connections/StartpadConn.qml | 5 +++-- qml/main.qml | 24 +++++++++++++++++++----- sources/buzzerconn.cpp | 27 ++++++++++++++++++++++++++- sources/main.cpp | 2 +- 6 files changed, 54 insertions(+), 12 deletions(-) diff --git a/headers/buzzerconn.h b/headers/buzzerconn.h index 2d411aa..8255edb 100644 --- a/headers/buzzerconn.h +++ b/headers/buzzerconn.h @@ -39,13 +39,14 @@ private: QNetworkAccessManager *reloadNetworkManager; QDateTime *date; QTcpSocket *socket; - + QStringList pending_commands; + //QSemaphore dataPipe(1); signals: public slots: ReturnData_t senddata(QNetworkAccessManager * NetMan, QUrl serviceUrl, int timeout); //function to communicate with the buzzer - signed long sendCommand(QString command, int timeout); + Q_INVOKABLE signed long sendCommand(QString command, int timeout); //function to send commands to the sensor //Can be: //command - return @@ -70,6 +71,7 @@ public slots: Q_INVOKABLE QString test(); Q_INVOKABLE bool refresh(); //refreshed the connection to the buzzer + Q_INVOKABLE void appendCommand(QString command); }; diff --git a/qml/SettingsDialog.qml b/qml/SettingsDialog.qml index 90f041b..e553157 100644 --- a/qml/SettingsDialog.qml +++ b/qml/SettingsDialog.qml @@ -254,7 +254,7 @@ Popup { } } - /*-----Page to connect to sensors like a startpad or buzzer-----*/ + /*-----Page to connect to extenstions like a startpad or buzzer-----*/ Component { id: connect Column { diff --git a/qml/connections/StartpadConn.qml b/qml/connections/StartpadConn.qml index 3ab731b..8a49176 100644 --- a/qml/connections/StartpadConn.qml +++ b/qml/connections/StartpadConn.qml @@ -10,6 +10,7 @@ Item { signal pushed() property bool connected: false property var status: {'status': startpadConn.state, 'progress': get_progress()} + property bool active Timer { //timer that refreshes the connection state to the buzzer @@ -30,7 +31,7 @@ Item { Timer { //timer that checks, if the button has been pushed id: running_refresh_timer - running: root.state === "RUNNING" + running: (root.state === "RUNNING" || root.state === "STARTING") && active repeat: false interval: 1 @@ -39,7 +40,7 @@ Item { startpadConn.pushed() } - if(root.state === "RUNNING" || root.state === "STARTING"){ + if(root.state === "RUNNING" || root.state === "STARTING" && active){ running_refresh_timer.start() } } diff --git a/qml/main.qml b/qml/main.qml index 0160907..09abe66 100644 --- a/qml/main.qml +++ b/qml/main.qml @@ -79,7 +79,13 @@ Window { StartpadConn { id: startpadConn + active: true + onActiveChanged: { + console.log("active changed: "+active) + } + onPushed: { + active = false console.log("startpad triggered") var offset = _cppStartpadConn.get("offset") var last_pressed = _cppStartpadConn.get("lastpressed") @@ -127,7 +133,6 @@ Window { time.text = "ready" } } - onTriggered: { if(action === "at_marks"){ at_marksSound.play() @@ -163,6 +168,7 @@ Window { source: "qrc:/sounds/ready_1.wav" onPlayingChanged: { if(!playing && root.state==="STARTING"){ + startSound.play() } } @@ -175,14 +181,20 @@ Window { onPlayingChanged: { if(!playing && root.state==="STARTING"){ - root.startTime = _cppBuzzerConn.get("currtime") - console.log(root.startTime) - root.currTime = _cppBuzzerConn.get("currtime") + console.log(root.startTime) + _cppStartpadConn.appendCommand("SET_LED_RUNNING") + root.currTime = root.startTime time.text = ( ( root.currTime - root.startTime ) / 1000 ).toFixed(3) + " sec" root.state = "RUNNING" } + else if(playing) { + console.log("start sound started") + root.startTime = _cppBuzzerConn.get("currtime") + 3100 //set the startime to be 0 after the starttone + startpadConn.active = true + } } + } /*------------------------ @@ -593,7 +605,7 @@ Window { State { name: "RUNNING" //state when the timer is running - PropertyChanges { target: time; text: ( ( root.currTime - root.startTime ) / 1000 ).toFixed(3) + " sec"; font.pixelSize: root.landscape() ? parent.width * 0.2:parent.height * 0.3; scale: 1 } + PropertyChanges { target: time; text: Math.abs( ( ( root.currTime - root.startTime ) / 1000 ) ).toFixed(3) + " sec"; font.pixelSize: root.landscape() ? parent.width * 0.2:parent.height * 0.3; scale: 1 } PropertyChanges { target: startButt; enabled: true; text: "stop" anchors.rightMargin: root.landscape() ? parent.width * 0.05:parent.width * 0.5 - startButt.width * 0.5 //put the button more to the right to hide the menu (only in landscape mode) @@ -675,6 +687,7 @@ Window { } function stop(type){ + _cppStartpadConn.appendCommand("SET_LED_STARTING"); switch(type){ case "buzzer": //the buzzer was pushed @@ -702,6 +715,7 @@ Window { startSound.stop() break } + startpadConn.active = true } function reset(){ diff --git a/sources/buzzerconn.cpp b/sources/buzzerconn.cpp index 4362ccc..b3c30aa 100644 --- a/sources/buzzerconn.cpp +++ b/sources/buzzerconn.cpp @@ -56,7 +56,7 @@ bool BuzzerConn::connect() } - QList times = gettimes(1000); + QList times = gettimes(2000); qDebug() << times[0]; if(times[0] == 200.0){ this->latest_button_pressed = times[2]; @@ -152,6 +152,16 @@ bool BuzzerConn::buzzer_triggered() if(!this->connected){ return(false); } + + if(pending_commands.length() > 0){ + QString command = this->pending_commands.first(); + + signed long retval = this->sendCommand(command, 800); + if(retval > 0){ + this->pending_commands.removeFirst(); + } + } + QList times = this->gettimes(1000); if(times[0] == 200.0){ if(times[2] > this->latest_button_pressed){ @@ -235,6 +245,17 @@ bool BuzzerConn::refresh() // //this->connected = false; // return(false); // } + + if(pending_commands.length() > 0){ + QString command = this->pending_commands.first(); + + signed long retval = this->sendCommand(command, 800); + if(retval > 0){ + this->pending_commands.removeFirst(); + } + } + + //refresh the times QList ret = this->gettimes(800); if(ret[0] >= 0){ this->errors = 0; @@ -340,3 +361,7 @@ signed long BuzzerConn::sendCommand(QString command, int timeout){ return data; } + +void BuzzerConn::appendCommand(QString command){ + this->pending_commands.append(command); +} diff --git a/sources/main.cpp b/sources/main.cpp index 6144ca9..cfa2fc0 100644 --- a/sources/main.cpp +++ b/sources/main.cpp @@ -106,7 +106,7 @@ int main(int argc, char *argv[]) connectToDatabase(); BuzzerConn * pBuzzerConn = new BuzzerConn(nullptr, "192.168.4.1", 80); - BuzzerConn * pStartpadConn = new BuzzerConn(nullptr, "192.168.4.3", 80); + BuzzerConn * pStartpadConn = new BuzzerConn(nullptr, "192.168.43.150", 80); AppSettings * pAppSettings = new AppSettings(); //setup the sql storage model as a qml model