Add some note about keybindings.
[qzeecontrol] / btconnector.h
index aaeac76..4d9ecb4 100644 (file)
@@ -1,3 +1,22 @@
+/*
+ *  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/>.
+ */
+
 #ifndef BTCONNECTOR_H
 #define BTCONNECTOR_H
 
@@ -9,36 +28,77 @@ QTM_USE_NAMESPACE
 class BtConnector : public QObject
 {
     Q_OBJECT
-public:
-    explicit BtConnector(QObject *parent = 0){qDebug("BtConnector Constructor");}
-    ~BtConnector(){if(socket != NULL) delete socket;}
 
-    Q_INVOKABLE void connect(QString address, int port){
-        qDebug("Trying to connect to: %s--%d", address.toUtf8().constData(), port);
+    Q_PROPERTY(int threshold READ threshold NOTIFY thresholdChanged WRITE setThreshold)
+
+    Q_PROPERTY(bool up READ up NOTIFY upChanged)
+    Q_PROPERTY(bool down READ down NOTIFY downChanged)
+    Q_PROPERTY(bool left READ left NOTIFY leftChanged)
+    Q_PROPERTY(bool right READ right NOTIFY rightChanged)
+
+    Q_PROPERTY(bool a READ a NOTIFY aChanged)
+    Q_PROPERTY(bool b READ b NOTIFY bChanged)
+    Q_PROPERTY(bool c READ c NOTIFY cChanged)
+    Q_PROPERTY(bool d READ d NOTIFY dChanged)
+
+    Q_PROPERTY(int x READ x NOTIFY xChanged)
+    Q_PROPERTY(int y READ y NOTIFY yChanged)
+public:
+    explicit BtConnector(QObject *parent = 0);
 
-        if(socket != NULL)
+    ~BtConnector(){
+        if(socket)
             delete socket;
-        socket = new QBluetoothSocket(QBluetoothSocket::RfcommSocket);
-        QObject::connect(socket, SIGNAL(connected()), this, SIGNAL(connected()));
-        QObject::connect(socket, SIGNAL(disconnected()), this, SIGNAL(disconnected()));
-        QObject::connect(socket, SIGNAL(error(QBluetoothSocket::SocketError)), this, SIGNAL(error(QBluetoothSocket::SocketError)));
+    }
+
+    Q_INVOKABLE void connect(QString address, int port);
 
-        qDebug("Connecting...");
-        socket->connectToService(QBluetoothAddress(address), port);
-        qDebug("Connected.");
+    int threshold(void){return _threshold;}
+    void setThreshold(int val){
+        _threshold = val;
+        thresholdChanged(_threshold);
+    }
 
-        QObject::connect(socket, SIGNAL(readyRead()), this, SLOT(readData()));
+    void setUp(bool val){
+        _up = val;
+        upChanged(_up);
+    }
+    void setDown(bool val){
+        _down = val;
+        downChanged(_down);
+    }
+    void setLeft(bool val){
+        _left = val;
+        leftChanged(_left);
+    }
+    void setRight(bool val){
+        _right = val;
+        rightChanged(_right);
     }
 
+    bool up(){return _up;}
+    bool down(){return _down;}
+    bool left(){return _left;}
+    bool right(){return _right;}
+
+    bool a(){return _a;}
+    bool b(){return _b;}
+    bool c(){return _c;}
+    bool d(){return _d;}
+
+    int x(){return _x;}
+    int y(){return _y;}
+
 public slots:
     void disconnect(){
-        if(socket == NULL)
+        if(!socket)
             return;
 
         if(socket->isOpen())
             socket->close();
 
         delete socket;
+        socket = 0;
     }
 
 signals:
@@ -47,21 +107,44 @@ signals:
     void error(QBluetoothSocket::SocketError errorCode);
 
     void stickMoved(int x, int y);
+    void buttonsChanged(bool a, bool b, bool c, bool d);
+
+    void thresholdChanged(int val);
+
+    void upChanged(bool val);
+    void downChanged(bool val);
+    void leftChanged(bool val);
+    void rightChanged(bool val);
+
+    void aChanged(bool val);
+    void bChanged(bool val);
+    void cChanged(bool val);
+    void dChanged(bool val);
+
+    void xChanged(int val);
+    void yChanged(int val);
 
 private slots:
-    void readData(){
-        qDebug("readData...");
-        QByteArray data = socket->readAll();
-        qDebug("read %d bytes.", data.size());
-
-        for(int i=0; i < data.size(); i++){
-            qDebug("%d: %d", i, ((signed char)data.at(i)));
-        }
-    }
+    void readData();
 
 private:
     QBluetoothSocket *socket;
 
+    int _threshold;
+
+    bool _up;
+    bool _down;
+    bool _left;
+    bool _right;
+
+    bool _a;
+    bool _b;
+    bool _c;
+    bool _d;
+
+    int _x;
+    int _y;
+    char oldButtonMap;
 };
 
 #endif // BTCONNECTOR_H