diff options
| author | Andrew Branson <andrew.branson@cern.ch> | 2015-04-21 12:47:07 +0200 |
|---|---|---|
| committer | Andrew Branson <andrew.branson@cern.ch> | 2015-04-21 12:47:07 +0200 |
| commit | bcbc550fa4603a2d394b267cab0a5ccf035ba633 (patch) | |
| tree | 6e4faec14ec4664c49f3be6269b3b5f6c448fe90 | |
| parent | 78f037bd6f6c15e71d7a3b6c096c51c8f4345641 (diff) | |
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)
| -rw-r--r-- | daemon/watchconnector.cpp | 16 | ||||
| -rw-r--r-- | daemon/watchconnector.h | 2 |
2 files changed, 18 insertions, 0 deletions
diff --git a/daemon/watchconnector.cpp b/daemon/watchconnector.cpp index 8d1dbac..9b5a41d 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 18f5fba..c56d861 100644 --- a/daemon/watchconnector.h +++ b/daemon/watchconnector.h @@ -9,6 +9,7 @@ #include <QTimer> #include <QDateTime> #include <QBluetoothDeviceInfo> +#include <QBluetoothLocalDevice> #include <QBluetoothSocket> #include <QBluetoothServiceInfo> #include <QLoggingCategory> @@ -215,6 +216,7 @@ signals: public slots: void deviceConnect(const QString &name, const QString &address); + void setIncreasedReconnectTimer(); void disconnect(); void reconnect(); |
