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
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 {
NumberAnimation { properties: "scale"; from: 0; to: 1; duration: 300; easing.type: Easing.Linear }
}
@ -80,6 +130,8 @@ Popup {
arcBegin: 0
arcEnd: 0
onColorCircleChanged: prog.repaint()
Timer {
id: prog_refresh
running: false
@ -110,6 +162,8 @@ Popup {
}
height: parent.height * 0.13
width:height
opacity: root.connecting.active === true ? 0:1
enabled: opacity > 0
background: Rectangle {
radius: width * 0.5
@ -142,6 +196,7 @@ Popup {
}
}
}
}
StackView {
@ -150,6 +205,8 @@ Popup {
initialItem: settings
width: headlineUnderline.width
enabled: opacity !== 0 //disable when not visible
anchors {
top: parent.top
left: parent.left
@ -173,56 +230,24 @@ Popup {
/*----Connect to buzzer----*/
ItemDelegate {
id: connect_del
width: parent.width
text: _cppBuzzerConn.get("connected")===1 ? qsTr("connected to buzzer"):qsTr("connect to buzzer")
text: qsTr("connections")
font.pixelSize: options_stack.text_pixelSize
Timer {
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")
}
}
width: parent.width
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: {
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
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;
}
options_stack.push(connect)
}
}
@ -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-----*/
Component {
id: autostart

View file

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