diff options
| author | Tomasz Sterna <tomek@xiaoka.com> | 2015-04-25 13:30:57 +0200 |
|---|---|---|
| committer | Tomasz Sterna <tomek@xiaoka.com> | 2015-04-25 13:30:57 +0200 |
| commit | f212fcc536aab7d51c21857ba80431af4b1ed6cc (patch) | |
| tree | a5558b048004e8ec6c0a058f4e5c418f525ee64a | |
| parent | d8deaf4385b20fa5e658dd0ef4cfc5631461e6fc (diff) | |
| parent | 7623fd462ab180684fd283006f5d989f7c1e3a8c (diff) | |
Merge pull request #53 from abranson/btFix
Check if Bluetooth is on before reconnecting
| -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 0ccd089..a4bfb64 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."; + scheduleReconnect(); + 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 } + scheduleReconnect(); + +} + +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 07895b7..4e6ed5d 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 scheduleReconnect(); void disconnect(); void reconnect(); |
