From abdf3b1eaba8151f1b8e862750c38cb7a5411d2a Mon Sep 17 00:00:00 2001 From: "Javier S. Pedro" Date: Mon, 13 Aug 2012 21:31:52 +0200 Subject: make watchsimulator work again --- metawatch/metawatch.cpp | 40 +++++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 17 deletions(-) (limited to 'metawatch/metawatch.cpp') diff --git a/metawatch/metawatch.cpp b/metawatch/metawatch.cpp index 6f8edca..6dfdd2f 100644 --- a/metawatch/metawatch.cpp +++ b/metawatch/metawatch.cpp @@ -109,13 +109,14 @@ MetaWatch::MetaWatch(ConfigKey* settings, QObject* parent) : _connectTimer->setSingleShot(true); _connectAlignedTimer->setSingleShot(true); - connect(_connectTimer, SIGNAL(timeout()), SLOT(retryConnect())); - connect(_connectAlignedTimer, SIGNAL(timeout()), SLOT(retryConnect())); + connect(_connectTimer, SIGNAL(timeout()), SLOT(timedReconnect())); + connect(_connectAlignedTimer, SIGNAL(timeout()), SLOT(timedReconnect())); _sendTimer->setInterval(DelayBetweenMessages); connect(_sendTimer, SIGNAL(timeout()), SLOT(timedSend())); - retryConnect(); + // Do an initial connection attempt + _connectTimer->start(100); } MetaWatch::~MetaWatch() @@ -249,7 +250,7 @@ void MetaWatch::displayNotification(Notification *notification) _idleTimer->stop(); } else { _ringTimer->stop(); - setVibrateMode(true, RingLength, RingLength, 2); + // XXX setVibrateMode(true, RingLength, RingLength, 2); _idleTimer->start(); } } @@ -322,6 +323,22 @@ quint16 MetaWatch::calcCrc(const Message& msg) return calcCrc(data, msgSize + 4); } +void MetaWatch::retryConnect() +{ + delete _socket; + _socket = new QBluetoothSocket(QBluetoothSocket::RfcommSocket); + + connect(_socket, SIGNAL(connected()), SLOT(socketConnected())); + connect(_socket, SIGNAL(disconnected()), SLOT(socketDisconnected())); + connect(_socket, SIGNAL(readyRead()), SLOT(socketData())); + connect(_socket, SIGNAL(error(QBluetoothSocket::SocketError)), + SLOT(socketError(QBluetoothSocket::SocketError))); + connect(_socket, SIGNAL(stateChanged(QBluetoothSocket::SocketState)), + SLOT(socketState(QBluetoothSocket::SocketState))); + + _socket->connectToService(_address, 1, QIODevice::ReadWrite | QIODevice::Unbuffered); +} + void MetaWatch::send(const Message &msg) { _toSend.enqueue(msg); @@ -754,20 +771,9 @@ void MetaWatch::socketState(QBluetoothSocket::SocketState error) qDebug() << "socket is in" << error; } -void MetaWatch::retryConnect() +void MetaWatch::timedReconnect() { - delete _socket; - _socket = new QBluetoothSocket(QBluetoothSocket::RfcommSocket); - - connect(_socket, SIGNAL(connected()), SLOT(socketConnected())); - connect(_socket, SIGNAL(disconnected()), SLOT(socketDisconnected())); - connect(_socket, SIGNAL(readyRead()), SLOT(socketData())); - connect(_socket, SIGNAL(error(QBluetoothSocket::SocketError)), - SLOT(socketError(QBluetoothSocket::SocketError))); - connect(_socket, SIGNAL(stateChanged(QBluetoothSocket::SocketState)), - SLOT(socketState(QBluetoothSocket::SocketState))); - - _socket->connectToService(_address, 1, QIODevice::ReadWrite | QIODevice::Unbuffered); + retryConnect(); } void MetaWatch::timedSend() -- cgit v1.2.3