From 0ad6b1fc702b56bed96077d540366a9a96903da7 Mon Sep 17 00:00:00 2001 From: Andrew Branson Date: Tue, 21 Apr 2015 12:47:07 +0200 Subject: Check if Bluetooth is on before reconnecting Don't try to reconnect to the watch if Bluetooth is switched off, instead start an extended reconnect timer (which has been refactored) --- daemon/watchconnector.cpp | 16 ++++++++++++++++ daemon/watchconnector.h | 2 ++ 2 files changed, 18 insertions(+) (limited to 'daemon') diff --git a/daemon/watchconnector.cpp b/daemon/watchconnector.cpp index 0ccd089..891625b 100644 --- a/daemon/watchconnector.cpp +++ b/daemon/watchconnector.cpp @@ -158,6 +158,16 @@ void WatchConnector::handleWatch(const QString &name, const QString &address) { qCDebug(l) << "handleWatch" << name << address; reconnectTimer.stop(); + + // Check if bluetooth is on + QBluetoothLocalDevice host; + bool btOff = host.hostMode() == QBluetoothLocalDevice::HostPoweredOff; + if (btOff) { + qCDebug(l) << "Bluetooth switched off."; + setIncreasedReconnectTimer(); + return; + } + if (socket != nullptr) { socket->close(); socket->deleteLater(); @@ -323,6 +333,12 @@ void WatchConnector::onDisconnected() writeData.clear(); // 3rd time around - user is not here, do not bother with resending last message } + setIncreasedReconnectTimer(); + +} + +void WatchConnector::setIncreasedReconnectTimer() +{ if (reconnectTimer.interval() < 10 * RECONNECT_TIMEOUT) { reconnectTimer.setInterval(reconnectTimer.interval() + RECONNECT_TIMEOUT); } diff --git a/daemon/watchconnector.h b/daemon/watchconnector.h index 07895b7..c7039a4 100644 --- a/daemon/watchconnector.h +++ b/daemon/watchconnector.h @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -215,6 +216,7 @@ signals: public slots: void deviceConnect(const QString &name, const QString &address); + void setIncreasedReconnectTimer(); void disconnect(); void reconnect(); -- cgit v1.2.3 From cda7a6f4a7da8945538d64b3d56f0bab543d55c4 Mon Sep 17 00:00:00 2001 From: Andrew Branson Date: Tue, 21 Apr 2015 14:14:17 +0200 Subject: Rename setIncreasedReconnectTimer to scheduleReconnect --- daemon/watchconnector.cpp | 6 +++--- daemon/watchconnector.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'daemon') diff --git a/daemon/watchconnector.cpp b/daemon/watchconnector.cpp index 891625b..a4bfb64 100644 --- a/daemon/watchconnector.cpp +++ b/daemon/watchconnector.cpp @@ -164,7 +164,7 @@ void WatchConnector::handleWatch(const QString &name, const QString &address) bool btOff = host.hostMode() == QBluetoothLocalDevice::HostPoweredOff; if (btOff) { qCDebug(l) << "Bluetooth switched off."; - setIncreasedReconnectTimer(); + scheduleReconnect(); return; } @@ -333,11 +333,11 @@ void WatchConnector::onDisconnected() writeData.clear(); // 3rd time around - user is not here, do not bother with resending last message } - setIncreasedReconnectTimer(); + scheduleReconnect(); } -void WatchConnector::setIncreasedReconnectTimer() +void WatchConnector::scheduleReconnect() { if (reconnectTimer.interval() < 10 * RECONNECT_TIMEOUT) { reconnectTimer.setInterval(reconnectTimer.interval() + RECONNECT_TIMEOUT); diff --git a/daemon/watchconnector.h b/daemon/watchconnector.h index c7039a4..4e6ed5d 100644 --- a/daemon/watchconnector.h +++ b/daemon/watchconnector.h @@ -216,7 +216,7 @@ signals: public slots: void deviceConnect(const QString &name, const QString &address); - void setIncreasedReconnectTimer(); + void scheduleReconnect(); void disconnect(); void reconnect(); -- cgit v1.2.3