Page {
tools: commonTools
+ Button{
+ id: scanButton
+ anchors{bottom: addressRow.top; bottomMargin: 10; horizontalCenter: parent.horizontalCenter}
+ enabled: true
+
+ text: "Scan"
+
+ onClicked: {
+ btDiscovery.discovery = true
+ }
+ }
+
+ Row{
+ id: addressRow
+ spacing: 5
+ anchors{bottom: infoText.top; bottomMargin: 10; horizontalCenter: parent.horizontalCenter}
+
+ TextField{
+ id: addressField
+ text: "No device found yet."
+
+ onTextChanged: {
+ connectButton.enabled = true
+ infoText.text = "Press \"Connect\" to connect to the device."
+ }
+ }
+ TextField{
+ id: portField
+ text: "-"
+ width: 60
+ validator: IntValidator{}
+ }
+ }
+
Label {
- id: label
+ id: infoText
anchors{bottom: connectButton.top; bottomMargin: 10; horizontalCenter: parent.horizontalCenter}
+ width: parent.width
- text: "Press to connect."
+ text: "Please scan for a device first."
+ horizontalAlignment: Text.AlignHCenter
+ wrapMode: Text.WordWrap
}
Button{
id: connectButton
anchors{bottom: disconnectButton.top; bottomMargin: 10; horizontalCenter: parent.horizontalCenter}
+ enabled: false
text: "Connect"
onClicked: {
- btDiscovery.discovery = true
+ enabled = false
+ btConn.connect(addressField.text, parseInt(portField.text))
}
}
onClicked: {
btConn.disconnect()
+
}
}
onDiscoveryChanged: {
if(discovery){
- label.text = "Scanning for devices..."
+ infoText.text = "Scanning for devices..."
+ scanButton.enabled = false
connectButton.enabled = false
disconnectButton.enabled = false
}else{
- connectButton.enabled = true
+ scanButton.enabled = true
disconnectButton.enabled = false
}
}
onNewServiceDiscovered: {
- console.log("Service " + service.serviceName + " found on " + service.deviceName + " at address " + service.deviceAddress + " on port " + service.servicePort + ".")
- //btSocket.service = service
- btConn.connect(service.deviceAddress, service.servicePort)
+ console.log("Service " + service.serviceName + " found on "
+ + service.deviceName + " at address " + service.deviceAddress
+ + " on port " + service.servicePort + ".")
+ if(service.serviceName === "Zeemote"){
+ addressField.text = service.deviceAddress
+ portField.text = service.servicePort
+ }
}
}
- /*
- BluetoothSocket{
- id: btSocket
-
- onDataAvailable: {
- console.log("Data available: " + stringData.charCodeAt(0) + data)
- }
-
- onServiceChanged: {
- console.log("Service changed. Connecting...")
- connected = true
- }
-
- onConnectedChanged: {
- console.log("Connected.")
- }
- }*/
-
BtConnector{
id: btConn
property int joystickThreshold: 50
onConnected: {
- connectButton.enabled = false
disconnectButton.enabled = true
- label.text = "Connected."
+ infoText.text = "Connected. Have fun."
}
onDisconnected: {
connectButton.enabled = true
disconnectButton.enabled = false
- label.text = "Press to connect."
+ infoText.text = "Press \"Connect\" to connect to the device."
}
// onStickMoved: {