From 97d17618bf66024ecb3f764a86e9ac1ccbf9f9c0 Mon Sep 17 00:00:00 2001 From: Dorian Zedler Date: Wed, 29 Aug 2018 18:33:39 +0200 Subject: [PATCH] implemented connectivity to startpad --- headers/buzzerconn.h | 1 + qml/connections/StartpadConn.qml | 2 +- qml/main.qml | 35 +++++++++++++++++++++++++++++++- sources/main.cpp | 13 +++++++++--- 4 files changed, 46 insertions(+), 5 deletions(-) diff --git a/headers/buzzerconn.h b/headers/buzzerconn.h index 97cb0a6..7cd2ff7 100644 --- a/headers/buzzerconn.h +++ b/headers/buzzerconn.h @@ -9,6 +9,7 @@ #include #include #include +#include typedef struct strReturnData{ int status_code; diff --git a/qml/connections/StartpadConn.qml b/qml/connections/StartpadConn.qml index a872c08..3ab731b 100644 --- a/qml/connections/StartpadConn.qml +++ b/qml/connections/StartpadConn.qml @@ -39,7 +39,7 @@ Item { startpadConn.pushed() } - if(root.state === "RUNNING"){ + if(root.state === "RUNNING" || root.state === "STARTING"){ running_refresh_timer.start() } } diff --git a/qml/main.qml b/qml/main.qml index 5e1e9c1..0160907 100644 --- a/qml/main.qml +++ b/qml/main.qml @@ -79,7 +79,16 @@ Window { StartpadConn { id: startpadConn - + onPushed: { + console.log("startpad triggered") + var offset = _cppStartpadConn.get("offset") + var last_pressed = _cppStartpadConn.get("lastpressed") + var trigger_time = (last_pressed + offset) + root.last_run.react_time = trigger_time - root.startTime + if(trigger_time - root.startTime <= 0){ + root.stop("false") + } + } } Timer { @@ -167,6 +176,7 @@ Window { onPlayingChanged: { if(!playing && root.state==="STARTING"){ root.startTime = _cppBuzzerConn.get("currtime") + console.log(root.startTime) root.currTime = _cppBuzzerConn.get("currtime") time.text = ( ( root.currTime - root.startTime ) / 1000 ).toFixed(3) + " sec" @@ -210,6 +220,28 @@ Window { } } } + + Label { + id: react_time + property int rtime: root.last_run.react_time + text: qsTr("reaction time (ms): ") + Math.round(rtime) + opacity: (root.state === "RUNNING" || root.sate === "STARTING" || root.state === "STOPPED") && rtime !== 0 ? 1:0 + color: StyleSettings.textColor + anchors { + horizontalCenter: parent.horizontalCenter + top: time.bottom + topMargin: parent.height * 0.1 + } + Timer { + running: root.state === "RUNNING" || root.sate === "STARTING" || root.state === "STOPPED" + repeat: true + interval: 1 + onTriggered: { + react_time.rtime = root.last_run.react_time + } + } + } + } ConnectionIcon { @@ -674,6 +706,7 @@ Window { function reset(){ root.state = "IDLE" + root.last_run.react_time = 0 } } } diff --git a/sources/main.cpp b/sources/main.cpp index a4c65bc..b6e07bd 100644 --- a/sources/main.cpp +++ b/sources/main.cpp @@ -105,8 +105,8 @@ int main(int argc, char *argv[]) #endif connectToDatabase(); - BuzzerConn * pBuzzerConn = new BuzzerConn(nullptr, QUrl("http://api.itsblue.de/test/buzzerem.php")); - BuzzerConn * pStartpadConn = new BuzzerConn(nullptr, QUrl("http://api.itsblue.de/test/startpadem.php")); + BuzzerConn * pBuzzerConn = new BuzzerConn(nullptr, QUrl("http://192.168.4.1")); + BuzzerConn * pStartpadConn = new BuzzerConn(nullptr, QUrl("http://192.168.4.2")); AppSettings * pAppSettings = new AppSettings(); //setup the sql storage model as a qml model @@ -129,5 +129,12 @@ int main(int argc, char *argv[]) engine.rootContext()->setContextProperty("_cppStartpadConn", pStartpadConn); engine.rootContext()->setContextProperty("_cppAppSettings", pAppSettings); - return app.exec(); + int iRet = 0; + iRet = app.exec(); + + delete pBuzzerConn; + delete pStartpadConn; + delete pAppSettings; + + return iRet; }