the startpad is now fully functional

This commit is contained in:
Dorian Zedler 2018-09-09 20:18:00 +02:00
parent ba9ff3faf9
commit 4765684692
6 changed files with 54 additions and 12 deletions

View file

@ -39,13 +39,14 @@ private:
QNetworkAccessManager *reloadNetworkManager; QNetworkAccessManager *reloadNetworkManager;
QDateTime *date; QDateTime *date;
QTcpSocket *socket; QTcpSocket *socket;
QStringList pending_commands;
//QSemaphore dataPipe(1);
signals: signals:
public slots: public slots:
ReturnData_t senddata(QNetworkAccessManager * NetMan, QUrl serviceUrl, int timeout); ReturnData_t senddata(QNetworkAccessManager * NetMan, QUrl serviceUrl, int timeout);
//function to communicate with the buzzer //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 //function to send commands to the sensor
//Can be: //Can be:
//command - return //command - return
@ -70,6 +71,7 @@ public slots:
Q_INVOKABLE QString test(); Q_INVOKABLE QString test();
Q_INVOKABLE bool refresh(); Q_INVOKABLE bool refresh();
//refreshed the connection to the buzzer //refreshed the connection to the buzzer
Q_INVOKABLE void appendCommand(QString command);
}; };

View file

@ -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 { Component {
id: connect id: connect
Column { Column {

View file

@ -10,6 +10,7 @@ Item {
signal pushed() signal pushed()
property bool connected: false property bool connected: false
property var status: {'status': startpadConn.state, 'progress': get_progress()} property var status: {'status': startpadConn.state, 'progress': get_progress()}
property bool active
Timer { Timer {
//timer that refreshes the connection state to the buzzer //timer that refreshes the connection state to the buzzer
@ -30,7 +31,7 @@ Item {
Timer { Timer {
//timer that checks, if the button has been pushed //timer that checks, if the button has been pushed
id: running_refresh_timer id: running_refresh_timer
running: root.state === "RUNNING" running: (root.state === "RUNNING" || root.state === "STARTING") && active
repeat: false repeat: false
interval: 1 interval: 1
@ -39,7 +40,7 @@ Item {
startpadConn.pushed() startpadConn.pushed()
} }
if(root.state === "RUNNING" || root.state === "STARTING"){ if(root.state === "RUNNING" || root.state === "STARTING" && active){
running_refresh_timer.start() running_refresh_timer.start()
} }
} }

View file

@ -79,7 +79,13 @@ Window {
StartpadConn { StartpadConn {
id: startpadConn id: startpadConn
active: true
onActiveChanged: {
console.log("active changed: "+active)
}
onPushed: { onPushed: {
active = false
console.log("startpad triggered") console.log("startpad triggered")
var offset = _cppStartpadConn.get("offset") var offset = _cppStartpadConn.get("offset")
var last_pressed = _cppStartpadConn.get("lastpressed") var last_pressed = _cppStartpadConn.get("lastpressed")
@ -127,7 +133,6 @@ Window {
time.text = "ready" time.text = "ready"
} }
} }
onTriggered: { onTriggered: {
if(action === "at_marks"){ if(action === "at_marks"){
at_marksSound.play() at_marksSound.play()
@ -163,6 +168,7 @@ Window {
source: "qrc:/sounds/ready_1.wav" source: "qrc:/sounds/ready_1.wav"
onPlayingChanged: { onPlayingChanged: {
if(!playing && root.state==="STARTING"){ if(!playing && root.state==="STARTING"){
startSound.play() startSound.play()
} }
} }
@ -175,14 +181,20 @@ Window {
onPlayingChanged: { onPlayingChanged: {
if(!playing && root.state==="STARTING"){ 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" time.text = ( ( root.currTime - root.startTime ) / 1000 ).toFixed(3) + " sec"
root.state = "RUNNING" 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 { State {
name: "RUNNING" name: "RUNNING"
//state when the timer is 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; PropertyChanges { target: startButt; enabled: true;
text: "stop" 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) 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){ function stop(type){
_cppStartpadConn.appendCommand("SET_LED_STARTING");
switch(type){ switch(type){
case "buzzer": case "buzzer":
//the buzzer was pushed //the buzzer was pushed
@ -702,6 +715,7 @@ Window {
startSound.stop() startSound.stop()
break break
} }
startpadConn.active = true
} }
function reset(){ function reset(){

View file

@ -56,7 +56,7 @@ bool BuzzerConn::connect()
} }
QList<double> times = gettimes(1000); QList<double> times = gettimes(2000);
qDebug() << times[0]; qDebug() << times[0];
if(times[0] == 200.0){ if(times[0] == 200.0){
this->latest_button_pressed = times[2]; this->latest_button_pressed = times[2];
@ -152,6 +152,16 @@ bool BuzzerConn::buzzer_triggered()
if(!this->connected){ if(!this->connected){
return(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();
}
}
QList<double> times = this->gettimes(1000); QList<double> times = this->gettimes(1000);
if(times[0] == 200.0){ if(times[0] == 200.0){
if(times[2] > this->latest_button_pressed){ if(times[2] > this->latest_button_pressed){
@ -235,6 +245,17 @@ bool BuzzerConn::refresh()
// //this->connected = false; // //this->connected = false;
// return(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<double> ret = this->gettimes(800); QList<double> ret = this->gettimes(800);
if(ret[0] >= 0){ if(ret[0] >= 0){
this->errors = 0; this->errors = 0;
@ -340,3 +361,7 @@ signed long BuzzerConn::sendCommand(QString command, int timeout){
return data; return data;
} }
void BuzzerConn::appendCommand(QString command){
this->pending_commands.append(command);
}

View file

@ -106,7 +106,7 @@ int main(int argc, char *argv[])
connectToDatabase(); connectToDatabase();
BuzzerConn * pBuzzerConn = new BuzzerConn(nullptr, "192.168.4.1", 80); 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(); AppSettings * pAppSettings = new AppSettings();
//setup the sql storage model as a qml model //setup the sql storage model as a qml model