Label{
id: labelA
text: "A"
- color: "blue"
+ color: btConn.a ? "red" : "blue"
}
Label{
id: labelB
text: "B"
- color: "blue"
+ color: btConn.b ? "red" : "blue"
}
Label{
id: labelC
text: "C"
- color: "blue"
+ color: btConn.c ? "red" : "blue"
}
Label{
id: labelD
text: "D"
- color: "blue"
+ color: btConn.d ? "red" : "blue"
}
}
width: 256
height: 256
+ }
- Rectangle{
- id: cursor
- width: 10
- height: 10
- color: "red"
- z: 32
-
- x: moveArea.x + (moveArea.width * 0.5) + btConn.x
- y: moveArea.y + (moveArea.height * 0.5) + btConn.y
+ Rectangle{
+ id: cursorRectangle
+ width: 10
+ height: 10
+ color: "red"
- onXChanged: console.log("New x: " + x)
- onYChanged: console.log("New y: " + y)
- }
+ 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{
id: btDiscovery
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)
- labelA.color = a ? "red" : "blue"
- labelB.color = b ? "red" : "blue"
- labelC.color = c ? "red" : "blue"
- labelD.color = d ? "red" : "blue"
}
+
+ 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
}
}