summaryrefslogtreecommitdiff
path: root/src/watchconnector.cpp
diff options
context:
space:
mode:
authorJouni Roivas <jroivas@iki.fi>2014-03-02 11:19:19 +0200
committerJouni Roivas <jroivas@iki.fi>2014-03-02 11:19:19 +0200
commitc89b4e0cce457c6b96f44e23b66d6ab0254f0eac (patch)
treeb80c4c1e4d490656aacb20c2410bde68836bc817 /src/watchconnector.cpp
parentdb2e550807b363cb8f31fa976da361bcf90e8f2c (diff)
Try to reconnect on error
Diffstat (limited to 'src/watchconnector.cpp')
-rw-r--r--src/watchconnector.cpp18
1 files changed, 17 insertions, 1 deletions
diff --git a/src/watchconnector.cpp b/src/watchconnector.cpp
index fb518ed..ab27b71 100644
--- a/src/watchconnector.cpp
+++ b/src/watchconnector.cpp
@@ -1,6 +1,10 @@
#include "watchconnector.h"
#include <QDateTime>
+using namespace watch;
+
+static int __reconnect_timeout = 1000;
+
WatchConnector::WatchConnector(QObject *parent) :
QObject(parent)
{
@@ -13,7 +17,7 @@ WatchConnector::~WatchConnector()
void WatchConnector::deviceDiscovered(const QBluetoothDeviceInfo &device)
{
- //FIXME: Configurable
+ //FIXME TODO: Configurable
if (device.name().startsWith("Pebble")) {
qDebug() << "Found Pebble:" << device.name() << '(' << device.address().toString() << ')';
handleWatch(device);
@@ -25,11 +29,20 @@ void WatchConnector::deviceDiscovered(const QBluetoothDeviceInfo &device)
void WatchConnector::deviceConnect(const QString name, const QString address)
{
if (name.startsWith("Pebble")) {
+ _last_name = name;
+ _last_address = address;
QBluetoothDeviceInfo device(QBluetoothAddress(address), name, 0);
deviceDiscovered(device);
}
}
+void WatchConnector::reconnect()
+{
+ if (_last_name != "" && _last_address != "") {
+ deviceConnect(_last_name, _last_address);
+ }
+}
+
void WatchConnector::handleWatch(const QBluetoothDeviceInfo &device)
{
qDebug() << "handleWatch" << device.name();
@@ -153,6 +166,9 @@ void WatchConnector::disconnected()
socket = nullptr;
emit connectedChanged();
emit nameChanged();
+
+ // Try to connect again after a timeout
+ QTimer::singleShot(__reconnect_timeout, this, SLOT(reconnect()));
}
void WatchConnector::sendData(const QByteArray &data)