<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
-<!-- Written by Qt Creator 2.4.1, 2012-04-12T09:12:26. -->
+<!-- Written by Qt Creator 2.4.1, 2012-04-12T10:21:41. -->
<qtcreator>
<data>
<variable>ProjectExplorer.Project.ActiveTarget</variable>
class BtConnector : public QObject
{
Q_OBJECT
+
+ Q_PROPERTY(int x READ x NOTIFY xChanged)
+ Q_PROPERTY(int y READ y NOTIFY yChanged)
public:
explicit BtConnector(QObject *parent = 0){
-
+ _x = 0;
+ _y = 0;
}
~BtConnector(){
if(socket)
QObject::connect(socket, SIGNAL(readyRead()), this, SLOT(readData()));
}
+ int x(){return _x;}
+ int y(){return _y;}
+
public slots:
void disconnect(){
if(!socket)
void stickMoved(int x, int y);
void buttonsChanged(bool a, bool b, bool c, bool d);
+ void xChanged(int);
+ void yChanged(int);
+
private slots:
void readData(){
// qDebug("readData...");
*/
if(data.at(0) == 5){
// Joystick movement
- emit(stickMoved((int)(signed char) data.at(4), (int)(signed char) data.at(5)));
+ _x = (int)(signed char) data.at(4);
+ _y = (int)(signed char) data.at(5);
+
+ emit(xChanged(_x));
+ emit(yChanged(_y));
+ emit(stickMoved(_x, _y));
}else if(data.at(0) == 8){
// Button press
/*
private:
QBluetoothSocket *socket;
+ int _x;
+ int _y;
};
#endif // BTCONNECTOR_H
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
+ Row{
+ id: buttonRow
+ anchors.centerIn: parent
+ spacing: 20
- text: "Disconnect"
+ Label{
+ id: labelA
+ text: "A"
+ color: "blue"
+ }
+ Label{
+ id: labelB
+ text: "B"
+ color: "blue"
+ }
+ Label{
+ id: labelC
+ text: "C"
+ color: "blue"
+ }
+ Label{
+ id: labelD
+ text: "D"
+ color: "blue"
+ }
+ }
- onClicked: {
- btConn.disconnect()
- }
+ Rectangle{
+ id: moveArea
+ anchors{top: buttonRow.bottom; topMargin: 10; horizontalCenter: parent.horizontalCenter}
+ color: "gray"
+
+ 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
+
+ onXChanged: console.log("New x: " + x)
+ onYChanged: console.log("New y: " + y)
}
}
+
BluetoothDiscoveryModel{
id: btDiscovery
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"
}
}
}