* first seems to suffice.
*/
if(data.at(0) == 5){
- // Joystick movement
- _x = (int)(signed char) data.at(4);
- _y = (int)(signed char) data.at(5);
+ /*
+ * Joystick movement
+ *
+ * X-Axis: positive values -> right, negative values -> left
+ * Y-Axis: positive values -> down, negative values -> up
+ */
+
+ setX((int)(signed char) data.at(4));
+ setY((int)(signed char) data.at(5));
- emit(xChanged(_x));
- emit(yChanged(_y));
emit(stickMoved(_x, _y));
+ /*
+ * Emulate a digital joystick.
+ */
if(_up && (_y > -threshold())){
setUp(false);
}else if(!_up && (_y < -threshold())){
}else if(!_right && (_x > threshold())){
setRight(true);
}
- }else if(data.at(0) == 8){
- // Button press
+ }else if(data.at(0) == 8){
/*
+ * Button presses
+ *
* A -> 0, B -> 1, C -> 2, D ->3
* At index 3 to 6 (inclusive)
*/
bool val = (buttonMap & (1 << i)) > 0;
switch (i){
case 0:
- _a = val;
- emit (aChanged(val));
+ setA(val);
break;
case 1:
- _b = val;
- emit (bChanged(val));
+ setB(val);
break;
case 2:
- _c = val;
- emit (cChanged(val));
+ setC(val);
break;
case 3:
- _d = val;
- emit (dChanged(val));
+ setD(val);
break;
}
}
function loadKeyBindings(){
console.log("Loading key bindings.")
- btConn.keyBindingA = SettingsStorage.getSetting("A")
- btConn.keyBindingB = SettingsStorage.getSetting("B")
- btConn.keyBindingC = SettingsStorage.getSetting("C")
- btConn.keyBindingD = SettingsStorage.getSetting("D")
-
- btConn.keyBindingUp = SettingsStorage.getSetting("Up")
- btConn.keyBindingDown = SettingsStorage.getSetting("Down")
- btConn.keyBindingLeft = SettingsStorage.getSetting("Left")
- btConn.keyBindingRight = SettingsStorage.getSetting("Right")
+ zeeRemoteControl.keyBindingA = SettingsStorage.getSetting("A")
+ zeeRemoteControl.keyBindingB = SettingsStorage.getSetting("B")
+ zeeRemoteControl.keyBindingC = SettingsStorage.getSetting("C")
+ zeeRemoteControl.keyBindingD = SettingsStorage.getSetting("D")
+
+ zeeRemoteControl.keyBindingUp = SettingsStorage.getSetting("Up")
+ zeeRemoteControl.keyBindingDown = SettingsStorage.getSetting("Down")
+ zeeRemoteControl.keyBindingLeft = SettingsStorage.getSetting("Left")
+ zeeRemoteControl.keyBindingRight = SettingsStorage.getSetting("Right")
}
function updateConnectAndScanButton(){
name: "active"
PropertyChanges {
target: cursorRectangle
- 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)
+ x: moveArea.x + (moveArea.width * 0.5) + zeeRemoteControl.x - (cursorRectangle.width * 0.5)
+ y: moveArea.y + (moveArea.height * 0.5) + zeeRemoteControl.y - (cursorRectangle.height * 0.5)
}
PropertyChanges {
target: labelA
- color: btConn.a ? "red" : "blue"
+ color: zeeRemoteControl.a ? "red" : "blue"
}
PropertyChanges {
target: labelB
- color: btConn.b ? "red" : "blue"
+ color: zeeRemoteControl.b ? "red" : "blue"
}
PropertyChanges {
target: labelC
- color: btConn.c ? "red" : "blue"
+ color: zeeRemoteControl.c ? "red" : "blue"
}
PropertyChanges {
target: labelD
- color: btConn.d ? "red" : "blue"
+ color: zeeRemoteControl.d ? "red" : "blue"
}
},
State {
onClicked: {
mainPage.state = "connecting"
- btConn.connect(addressField.text, parseInt(portField.text))
+ zeeRemoteControl.connect(addressField.text, parseInt(portField.text))
}
}
text: "Disconnect"
onClicked: {
- btConn.disconnect()
+ zeeRemoteControl.disconnect()
}
}
Label{
id: labelA
text: "A"
- color: btConn.a ? "red" : "blue"
+ color: zeeRemoteControl.a ? "red" : "blue"
}
Label{
id: labelB
text: "B"
- color: btConn.b ? "red" : "blue"
+ color: zeeRemoteControl.b ? "red" : "blue"
}
Label{
id: labelC
text: "C"
- color: btConn.c ? "red" : "blue"
+ color: zeeRemoteControl.c ? "red" : "blue"
}
Label{
id: labelD
text: "D"
- color: btConn.d ? "red" : "blue"
+ color: zeeRemoteControl.d ? "red" : "blue"
}
}
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)
+ x: moveArea.x + (moveArea.width * 0.5) + zeeRemoteControl.x - (cursorRectangle.width * 0.5)
+ y: moveArea.y + (moveArea.height * 0.5) + zeeRemoteControl.y - (cursorRectangle.height * 0.5)
}
}
}
}
}
- BtConnector{
- id: btConn
+ ZeeRemoteControl{
+ id: zeeRemoteControl
threshold: 50
- property string keyBindingA
- property string keyBindingB
- property string keyBindingC
- property string keyBindingD
-
- property string keyBindingUp
- property string keyBindingDown
- property string keyBindingLeft
- property string keyBindingRight
-
onConnected: {
disconnectButton.enabled = true
infoText.text = "Connected. Have fun."
}
-
- onDisconnected: {
- mainPage.state = "disconnected"
- }
-
-// onStickMoved: {
-// console.log("Stick moved. x: " + x + " y: " + y)
-// }
-// onButtonsChanged: {
-// console.log("Buttons changed. A: " + a + " B: " + b + " C: " + c + " D: " + d)
-// }
-
- onAChanged: xtstAdapter.sendKey(keyBindingA, val);
- onBChanged: xtstAdapter.sendKey(keyBindingB, val);
- onCChanged: xtstAdapter.sendKey(keyBindingC, val);
- onDChanged: xtstAdapter.sendKey(keyBindingD, val);
-
- onUpChanged: xtstAdapter.sendKey(keyBindingUp, val)
- onDownChanged: xtstAdapter.sendKey(keyBindingDown, val)
- onLeftChanged: xtstAdapter.sendKey(keyBindingLeft, val)
- onRightChanged: xtstAdapter.sendKey(keyBindingRight, val)
+ onDisconnected: mainPage.state = "disconnected"
}
XtstAdapter{
--- /dev/null
+/*
+ * Copyright 2012 Ruediger Gad
+ *
+ * This file is part of QZeeControl.
+ *
+ * QZeeControl is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * QZeeControl is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with QZeeControl. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+import QtQuick 1.1
+import qzeecontrol 1.0
+
+BtConnector{
+ id: zeeRemoteControl
+
+ /*
+ * Keybindings
+ */
+ property string keyBindingA
+ property string keyBindingB
+ property string keyBindingC
+ property string keyBindingD
+
+ property string keyBindingUp
+ property string keyBindingDown
+ property string keyBindingLeft
+ property string keyBindingRight
+
+// Examples on how to use these old signals.
+// onStickMoved: {
+// console.log("Stick moved. x: " + x + " y: " + y)
+// }
+// onButtonsChanged: {
+// console.log("Buttons changed. A: " + a + " B: " + b + " C: " + c + " D: " + d)
+// }
+
+ /*
+ * Do the actual keyboard interaction.
+ */
+ onAChanged: xtstAdapter.sendKey(keyBindingA, val);
+ onBChanged: xtstAdapter.sendKey(keyBindingB, val);
+ onCChanged: xtstAdapter.sendKey(keyBindingC, val);
+ onDChanged: xtstAdapter.sendKey(keyBindingD, val);
+
+ onUpChanged: xtstAdapter.sendKey(keyBindingUp, val)
+ onDownChanged: xtstAdapter.sendKey(keyBindingDown, val)
+ onLeftChanged: xtstAdapter.sendKey(keyBindingLeft, val)
+ onRightChanged: xtstAdapter.sendKey(keyBindingRight, val)
+}
+
+