the startpad is now fully functional

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

View file

@ -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);
};

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

View file

@ -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()
}
}

View file

@ -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,16 +181,22 @@ 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
}
}
}
/*------------------------
Timer text an upper line
------------------------*/
@ -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(){

View file

@ -56,7 +56,7 @@ bool BuzzerConn::connect()
}
QList<double> times = gettimes(1000);
QList<double> 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<double> 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<double> 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);
}

View file

@ -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