Page {
tools: commonTools
+ Label {
+ id: label
+ anchors{bottom: connectButton.top; bottomMargin: 10; horizontalCenter: parent.horizontalCenter}
+ text: "Press to connect."
+ }
- Column {
- anchors.centerIn: parent
- spacing: 10
+ Button{
+ id: connectButton
+ anchors{bottom: disconnectButton.top; bottomMargin: 10; horizontalCenter: parent.horizontalCenter}
- Label {
- id: label
+ text: "Connect"
- text: "Press to connect."
+ onClicked: {
+ btDiscovery.discovery = true
}
+ }
- Button{
- id: connectButton
+ Button{
+ id: disconnectButton
+ anchors{bottom: buttonRow.top; bottomMargin: 10; horizontalCenter: parent.horizontalCenter}
- text: "Connect"
+ text: "Disconnect"
- onClicked: {
- btDiscovery.discovery = true
- }
+ onClicked: {
+ btConn.disconnect()
}
+ }
- Button{
- id: disconnectButton
-
- text: "Disconnect"
+ Row{
+ id: buttonRow
+ anchors.centerIn: parent
+ spacing: 20
- onClicked: {
- btConn.disconnect()
- }
+ Label{
+ id: labelA
+ text: "A"
+ color: btConn.a ? "red" : "blue"
+ }
+ Label{
+ id: labelB
+ text: "B"
+ color: btConn.b ? "red" : "blue"
}
+ Label{
+ id: labelC
+ text: "C"
+ color: btConn.c ? "red" : "blue"
+ }
+ Label{
+ id: labelD
+ text: "D"
+ color: btConn.d ? "red" : "blue"
+ }
+ }
+
+ Rectangle{
+ id: moveArea
+ anchors{top: buttonRow.bottom; topMargin: 10; horizontalCenter: parent.horizontalCenter}
+ color: "gray"
+
+ width: 256
+ height: 256
+ }
+
+ Rectangle{
+ id: cursorRectangle
+ width: 10
+ height: 10
+ color: "red"
+
+ x: moveArea.x + (moveArea.width * 0.5) + btConn.x - (cursorRectangle.width * 0.5)
+ y: moveArea.y + (moveArea.height * 0.5) + btConn.y - (cursorRectangle.height * 0.5)
}
BluetoothDiscoveryModel{
BtConnector{
id: btConn
+ property int joystickThreshold: 50
+
onConnected: {
connectButton.enabled = false
disconnectButton.enabled = true
onButtonsChanged: {
console.log("Buttons changed. A: " + a + " B: " + b + " C: " + c + " D: " + d)
}
+
+ onAChanged: {
+ console.log("A changed to: " + val)
+ xtstAdapter.sendKey("a", val);
+ }
+ onBChanged: {
+ console.log("B changed to: " + val)
+ xtstAdapter.sendKey("b", val);
+ }
+ onCChanged: {
+ console.log("C changed to: " + val)
+ xtstAdapter.sendKey("c", val);
+ }
+ onDChanged: {
+ console.log("D changed to: " + val)
+ xtstAdapter.sendKey("d", val);
+ }
+
+ onXChanged: {
+ if(val > joystickThreshold){
+ xtstAdapter.sendKey("Right", true);
+ }else if(val < -joystickThreshold){
+ xtstAdapter.sendKey("Left", true);
+ }else{
+ xtstAdapter.sendKey("Right", false);
+ xtstAdapter.sendKey("Left", false);
+ }
+ }
+
+ onYChanged: {
+ if(val > joystickThreshold){
+ xtstAdapter.sendKey("Down", true);
+ }else if(val < -joystickThreshold){
+ xtstAdapter.sendKey("Up", true);
+ }else{
+ xtstAdapter.sendKey("Down", false);
+ xtstAdapter.sendKey("Up", false);
+ }
+ }
+ }
+
+ XtstAdapter{
+ id: xtstAdapter
}
}