diff options
| author | Tomasz Sterna <tomek@xiaoka.com> | 2015-05-14 12:07:25 +0200 |
|---|---|---|
| committer | Tomasz Sterna <tomek@xiaoka.com> | 2015-05-14 12:07:25 +0200 |
| commit | 37bc0ef733843f27eb6228f3ee149094e7f62383 (patch) | |
| tree | 4484b2e7b92d864873adf57916c29b5dfb1285cf | |
| parent | fcf581d9723ae6dfbd7fdeb45c1a614d0b18c68d (diff) | |
| parent | 2d50346f06e5be31557cb4718ff94cd650c1a210 (diff) | |
Merge pull request #66 from abranson/master
Automatically synchronize time with watch; Fixes #46
| -rw-r--r-- | daemon/watchconnector.cpp | 12 | ||||
| -rw-r--r-- | daemon/watchconnector.h | 1 |
2 files changed, 11 insertions, 2 deletions
diff --git a/daemon/watchconnector.cpp b/daemon/watchconnector.cpp index a4bfb64..2c17a0b 100644 --- a/daemon/watchconnector.cpp +++ b/daemon/watchconnector.cpp @@ -68,6 +68,9 @@ WatchConnector::WatchConnector(QObject *parent) : { reconnectTimer.setSingleShot(true); connect(&reconnectTimer, SIGNAL(timeout()), SLOT(reconnect())); + timeSyncTimer.setSingleShot(true); + connect(&timeSyncTimer, SIGNAL(timeout()), SLOT(time())); + timeSyncTimer.setInterval(4 * 60 * 60 * 1000); // sync time every 4 hours firmwareMapping.insert(UNKNOWN, "unknown"); firmwareMapping.insert(PEBBLE_ONE_EV1, "ev1"); @@ -151,7 +154,8 @@ void WatchConnector::disconnect() socket->close(); socket->deleteLater(); reconnectTimer.stop(); - qCDebug(l) << "stopped reconnect timer"; + timeSyncTimer.stop(); + qCDebug(l) << "stopped timers"; } void WatchConnector::handleWatch(const QString &name, const QString &address) @@ -312,6 +316,7 @@ void WatchConnector::onConnected() sendMessage(watchVERSION, QByteArray(1, 0)); emit connectedChanged(); if (name() != _last_name) emit nameChanged(); + time(); } } @@ -332,7 +337,7 @@ void WatchConnector::onDisconnected() if (not writeData.isEmpty() && reconnectTimer.interval() > RECONNECT_TIMEOUT) { writeData.clear(); // 3rd time around - user is not here, do not bother with resending last message } - + timeSyncTimer.stop(); scheduleReconnect(); } @@ -476,6 +481,8 @@ void WatchConnector::ping(uint cookie) void WatchConnector::time() { + qCDebug(l) << "Synchronizing time"; + timeSyncTimer.stop(); QByteArray res; QDateTime UTC(QDateTime::currentDateTimeUtc()); QDateTime local(UTC.toLocalTime()); @@ -489,6 +496,7 @@ void WatchConnector::time() res.append((char)((val >> 8) & 0xff)); res.append((char)(val & 0xff)); sendMessage(watchTIME, res); + timeSyncTimer.start(); } QString WatchConnector::timeStamp() diff --git a/daemon/watchconnector.h b/daemon/watchconnector.h index 4e6ed5d..f9576a3 100644 --- a/daemon/watchconnector.h +++ b/daemon/watchconnector.h @@ -261,6 +261,7 @@ private: bool is_connected; QByteArray writeData; QTimer reconnectTimer; + QTimer timeSyncTimer; QString _last_name; QString _last_address; WatchVersions _versions; |
