+/*
+ * 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
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){qDebug("BtConnector Constructor");}
- ~BtConnector(){if(socket != NULL) delete socket;}
+ explicit BtConnector(QObject *parent = 0){
+ _x = 0;
+ _y = 0;
+ }
+ ~BtConnector(){
+ if(socket)
+ delete socket;
+ }
Q_INVOKABLE void connect(QString address, int port){
qDebug("Trying to connect to: %s--%d", address.toUtf8().constData(), port);
- if(socket != NULL)
+ 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(readyRead()), this, SLOT(readData()));
}
+ 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:
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
/*
}
}
- qDebug("Button map: %d", buttonMap);
+// qDebug("Button map: %d", buttonMap);
emit(buttonsChanged(buttonMap & 0x01, buttonMap & 0x02, buttonMap & 0x04, buttonMap & 0x08));
}
}
private:
QBluetoothSocket *socket;
+ int _x;
+ int _y;
};
#endif // BTCONNECTOR_H