From 0930f84305e6247a4165b99d3549422be97114c0 Mon Sep 17 00:00:00 2001 From: Jozef Mlich Date: Sat, 2 Nov 2024 15:24:16 +0100 Subject: [PATCH] Fixes #421: setTime upon connection to bangle.js --- daemon/src/devices/banglejsdevice.cpp | 19 +++++++++++++++++++ daemon/src/devices/banglejsdevice.h | 2 ++ 2 files changed, 21 insertions(+) diff --git a/daemon/src/devices/banglejsdevice.cpp b/daemon/src/devices/banglejsdevice.cpp index 36dea5ed..9533fb6c 100644 --- a/daemon/src/devices/banglejsdevice.cpp +++ b/daemon/src/devices/banglejsdevice.cpp @@ -175,6 +175,25 @@ void BangleJSDevice::initialise() } setConnectionState("authenticated"); + + setTime(); +} + +void BangleJSDevice::setTime() { + UARTService *uart = qobject_cast(service(UARTService::UUID_SERVICE_UART)); + if (!uart){ + return; + } + + qint64 ts; + +#if QT_VERSION >= QT_VERSION_CHECK(5, 8, 0) + ts = QDateTime::currentSecsSinceEpoch(); +#else + ts = QDateTime::currentDateTime().toTime_t(); +#endif + QString time_str("setTime(" + QString::number(ts) + ");\n"); + uart->tx(time_str.toUtf8()); } void BangleJSDevice::onPropertiesChanged(QString interface, QVariantMap map, QStringList list) diff --git a/daemon/src/devices/banglejsdevice.h b/daemon/src/devices/banglejsdevice.h index c2c2b512..37e06ec7 100644 --- a/daemon/src/devices/banglejsdevice.h +++ b/daemon/src/devices/banglejsdevice.h @@ -37,6 +37,8 @@ class BangleJSDevice : public AbstractDevice //Weather void sendWeather(CurrentWeather *weather) override; + void setTime(); + protected: virtual void onPropertiesChanged(QString interface, QVariantMap map, QStringList list);