Add screenshots etc. for ovi store and apps.formeego.com.
[qzeecontrol] / btconnector.h
1 /*
2  *  Copyright 2012 Ruediger Gad
3  *
4  *  This file is part of QZeeControl.
5  *
6  *  QZeeControl is free software: you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation, either version 3 of the License, or
9  *  (at your option) any later version.
10  *
11  *  QZeeControl is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with QZeeControl.  If not, see <http://www.gnu.org/licenses/>.
18  */
19
20 #ifndef BTCONNECTOR_H
21 #define BTCONNECTOR_H
22
23 #include <QObject>
24 #include <QtConnectivity/QBluetoothAddress>
25 #include <QtConnectivity/QBluetoothSocket>
26
27 QTM_USE_NAMESPACE
28 class BtConnector : public QObject
29 {
30     Q_OBJECT
31
32     Q_PROPERTY(int threshold READ threshold NOTIFY thresholdChanged WRITE setThreshold)
33
34     Q_PROPERTY(bool up READ up NOTIFY upChanged)
35     Q_PROPERTY(bool down READ down NOTIFY downChanged)
36     Q_PROPERTY(bool left READ left NOTIFY leftChanged)
37     Q_PROPERTY(bool right READ right NOTIFY rightChanged)
38
39     Q_PROPERTY(bool a READ a NOTIFY aChanged)
40     Q_PROPERTY(bool b READ b NOTIFY bChanged)
41     Q_PROPERTY(bool c READ c NOTIFY cChanged)
42     Q_PROPERTY(bool d READ d NOTIFY dChanged)
43
44     Q_PROPERTY(int x READ x NOTIFY xChanged)
45     Q_PROPERTY(int y READ y NOTIFY yChanged)
46 public:
47     explicit BtConnector(QObject *parent = 0);
48
49     ~BtConnector(){
50         if(socket)
51             delete socket;
52     }
53
54     Q_INVOKABLE void connect(QString address, int port);
55
56     int threshold(void){return _threshold;}
57     void setThreshold(int val){
58         _threshold = val;
59         thresholdChanged(_threshold);
60     }
61
62     void setUp(bool val){
63         _up = val;
64         upChanged(_up);
65     }
66     void setDown(bool val){
67         _down = val;
68         downChanged(_down);
69     }
70     void setLeft(bool val){
71         _left = val;
72         leftChanged(_left);
73     }
74     void setRight(bool val){
75         _right = val;
76         rightChanged(_right);
77     }
78
79     bool up(){return _up;}
80     bool down(){return _down;}
81     bool left(){return _left;}
82     bool right(){return _right;}
83
84     bool a(){return _a;}
85     bool b(){return _b;}
86     bool c(){return _c;}
87     bool d(){return _d;}
88
89     int x(){return _x;}
90     int y(){return _y;}
91
92 public slots:
93     void disconnect(){
94         if(!socket)
95             return;
96
97         if(socket->isOpen())
98             socket->close();
99
100         delete socket;
101         socket = 0;
102     }
103
104 signals:
105     void connected();
106     void disconnected();
107     void error(QBluetoothSocket::SocketError errorCode);
108
109     void stickMoved(int x, int y);
110     void buttonsChanged(bool a, bool b, bool c, bool d);
111
112     void thresholdChanged(int val);
113
114     void upChanged(bool val);
115     void downChanged(bool val);
116     void leftChanged(bool val);
117     void rightChanged(bool val);
118
119     void aChanged(bool val);
120     void bChanged(bool val);
121     void cChanged(bool val);
122     void dChanged(bool val);
123
124     void xChanged(int val);
125     void yChanged(int val);
126
127 private slots:
128     void readData();
129
130 private:
131     QBluetoothSocket *socket;
132
133     int _threshold;
134
135     bool _up;
136     bool _down;
137     bool _left;
138     bool _right;
139
140     bool _a;
141     bool _b;
142     bool _c;
143     bool _d;
144
145     int _x;
146     int _y;
147     char oldButtonMap;
148 };
149
150 #endif // BTCONNECTOR_H