Made the Buzzer connection modular to be able to connect multiple devices to the app (like a startpad)

This commit is contained in:
Dorian Zedler 2018-08-18 21:27:18 +02:00
parent 9bda535869
commit 78194dda0f
3 changed files with 115 additions and 50 deletions

View file

@ -38,4 +38,7 @@ Item {
} }
} }
function connect(){
return(_cppBuzzerConn.connect())
}
} }

View file

@ -30,6 +30,56 @@ Popup {
modal: true modal: true
dim: false dim: false
property var connecting: {
'active': false, 'ret': false
};
signal connectRequested(var type)
function connect(type) {
connecting.active = true
root.closePolicy = Popup.NoAutoClose
options_stack.opacity = 0
prog.arcEnd = 0
prog.colorCircle = "grey"
prog.opacity = 1
prog.text = qsTr("connecting...")
prog_refresh.running = true
switch(type){
case "buzzer":
connectRequested("buzzer")
break
}
if(connecting.ret){
prog_refresh.running = false
prog.colorCircle = "green"
prog.text = qsTr("success")
prog.arcEnd = 360
}
else {
prog_refresh.running = false
prog.colorCircle = "red"
prog.text = qsTr("error")
prog.arcEnd = 360
}
//make a short delay and go back to normal options
shortDelay.start()
}
Timer {
id: shortDelay
running: false
repeat: false
interval: 1000
onTriggered: {
prog.opacity = 0;
options_stack.opacity = 1
root.closePolicy = Popup.CloseOnPressOutside;
connecting.active = false
}
}
enter: Transition { enter: Transition {
NumberAnimation { properties: "scale"; from: 0; to: 1; duration: 300; easing.type: Easing.Linear } NumberAnimation { properties: "scale"; from: 0; to: 1; duration: 300; easing.type: Easing.Linear }
} }
@ -80,6 +130,8 @@ Popup {
arcBegin: 0 arcBegin: 0
arcEnd: 0 arcEnd: 0
onColorCircleChanged: prog.repaint()
Timer { Timer {
id: prog_refresh id: prog_refresh
running: false running: false
@ -110,6 +162,8 @@ Popup {
} }
height: parent.height * 0.13 height: parent.height * 0.13
width:height width:height
opacity: root.connecting.active === true ? 0:1
enabled: opacity > 0
background: Rectangle { background: Rectangle {
radius: width * 0.5 radius: width * 0.5
@ -142,6 +196,7 @@ Popup {
} }
} }
} }
} }
StackView { StackView {
@ -150,6 +205,8 @@ Popup {
initialItem: settings initialItem: settings
width: headlineUnderline.width width: headlineUnderline.width
enabled: opacity !== 0 //disable when not visible
anchors { anchors {
top: parent.top top: parent.top
left: parent.left left: parent.left
@ -173,56 +230,24 @@ Popup {
/*----Connect to buzzer----*/ /*----Connect to buzzer----*/
ItemDelegate { ItemDelegate {
id: connect_del id: connect_del
width: parent.width text: qsTr("connections")
text: _cppBuzzerConn.get("connected")===1 ? qsTr("connected to buzzer"):qsTr("connect to buzzer")
font.pixelSize: options_stack.text_pixelSize font.pixelSize: options_stack.text_pixelSize
Timer { width: parent.width
running: connect_del.scale === 1
repeat: true
interval: 10
onTriggered: {
connect_del.text = _cppBuzzerConn.get("connected")===1 ? qsTr("connected to buzzer"):qsTr("connect to buzzer")
}
}
Image {
id: connect_del_image
source: "qrc:/graphics/icons/back_black.png"
rotation: 180
height: options_stack.text_pixelSize
width: height
anchors {
verticalCenter: parent.verticalCenter
right: parent.right
rightMargin: 10
}
}
onClicked: { onClicked: {
root.closePolicy = Popup.NoAutoClose options_stack.push(connect)
options_stack.opacity = 0
prog.arcEnd = 0
prog.colorCircle = "grey"
prog.opacity = 1
prog.text = qsTr("connecting...")
prog_refresh.running = true
if(_cppBuzzerConn.connect()){
prog_refresh.running = false
prog.colorCircle = "green"
prog.text = qsTr("success")
prog.arcEnd = 360
}
else {
prog_refresh.running = false
prog.colorCircle = "red"
prog.text = qsTr("error")
prog.arcEnd = 360
}
//make a short delay and go back to normal options
shortDelay.start()
}
Timer {
id: shortDelay
running: false
repeat: false
interval: 1000
onTriggered: {
connect_del.enabled = true;
prog.opacity = 0;
options_stack.opacity = 1
root.closePolicy = Popup.CloseOnPressOutside;
}
} }
} }
@ -262,6 +287,34 @@ Popup {
} }
} }
/*-----Page to connect to sensors like a startpad or buzzer-----*/
Component {
id: connect
Column {
id: connect_col
property string title: "connections"
property int delegateHeight: height*0.18
ItemDelegate {
id: connect_buzz_del
width: parent.width
text: _cppBuzzerConn.get("connected")===1 ? qsTr("connected to buzzer"):qsTr("connect to buzzer")
font.pixelSize: options_stack.text_pixelSize
Timer {
running: connect_buzz_del.scale === 1
repeat: true
interval: 10
onTriggered: {
connect_buzz_del.text = _cppBuzzerConn.get("connected")===1 ? qsTr("connected to buzzer"):qsTr("connect to buzzer")
}
}
onClicked: {
root.connect("buzzer")
}
}
}
}
/*-----Page to setup automatc start sequence-----*/ /*-----Page to setup automatc start sequence-----*/
Component { Component {
id: autostart id: autostart

View file

@ -33,7 +33,6 @@ Window {
Page { Page {
id:root id:root
anchors.fill: parent anchors.fill: parent
@ -45,7 +44,7 @@ Window {
property double last_button_pressed property double last_button_pressed
property var last_run : { property var last_run : {
'stopp_type': "", 'time': 0 'stop_type': "", 'time': 0
}; };
//set default state to IDLE //set default state to IDLE
@ -63,6 +62,7 @@ Window {
} }
BuzzerConn { BuzzerConn {
id: buzzerConn
onPushed: { onPushed: {
// the buzzer was pushed // the buzzer was pushed
root.stop("buzzer") root.stop("buzzer")
@ -367,6 +367,15 @@ Window {
------*/ ------*/
SettingsDialog{ SettingsDialog{
id: settingsDialog id: settingsDialog
onConnectRequested: {
switch(type){
case "buzzer":
settingsDialog.connecting.ret = buzzerConn.connect()
break
}
}
} }
// ProfilesDialog { // ProfilesDialog {
@ -627,7 +636,7 @@ Window {
console.log("STOPPED: "+root.stoppedTime) console.log("STOPPED: "+root.stoppedTime)
break break
case "manual": case "manual":
//te stop button was pressed //the stop button was pressed
root.stoppedTime = new Date().getTime() - root.startTime root.stoppedTime = new Date().getTime() - root.startTime
time.text = ( root.stoppedTime / 1000 ).toFixed(3) + " sec" time.text = ( root.stoppedTime / 1000 ).toFixed(3) + " sec"
root.state = "STOPPED" root.state = "STOPPED"