From ce608254ab1f8ccd24fabfa403aae1748a001e6e Mon Sep 17 00:00:00 2001 From: Lionel Elie Mamane Date: Sat, 9 Nov 2024 20:07:01 +0100 Subject: [PATCH] port SimpleWeatherService to std::chrono::system_clock::now() --- src/components/ble/NimbleController.cpp | 2 +- src/components/ble/SimpleWeatherService.cpp | 7 ++++--- src/components/ble/SimpleWeatherService.h | 6 +----- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/components/ble/NimbleController.cpp b/src/components/ble/NimbleController.cpp index 5059007ab9..0a25b81335 100644 --- a/src/components/ble/NimbleController.cpp +++ b/src/components/ble/NimbleController.cpp @@ -43,7 +43,7 @@ NimbleController::NimbleController(Pinetime::System::SystemTask& systemTask, alertNotificationClient {systemTask, notificationManager}, currentTimeService {dateTimeController}, musicService {*this}, - weatherService {dateTimeController}, + weatherService {}, batteryInformationService {batteryController}, immediateAlertService {systemTask, notificationManager}, heartRateService {*this, heartRateController}, diff --git a/src/components/ble/SimpleWeatherService.cpp b/src/components/ble/SimpleWeatherService.cpp index 51baf5433f..d45d6c186e 100644 --- a/src/components/ble/SimpleWeatherService.cpp +++ b/src/components/ble/SimpleWeatherService.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include using namespace Pinetime::Controllers; @@ -80,7 +81,7 @@ int WeatherCallback(uint16_t /*connHandle*/, uint16_t /*attrHandle*/, struct ble return static_cast(arg)->OnCommand(ctxt); } -SimpleWeatherService::SimpleWeatherService(DateTime& dateTimeController) : dateTimeController(dateTimeController) { +SimpleWeatherService::SimpleWeatherService() { } void SimpleWeatherService::Init() { @@ -127,7 +128,7 @@ int SimpleWeatherService::OnCommand(struct ble_gatt_access_ctxt* ctxt) { std::optional SimpleWeatherService::Current() const { if (currentWeather) { - auto currentTime = dateTimeController.CurrentDateTime().time_since_epoch(); + auto currentTime = std::chrono::system_clock::now().time_since_epoch(); auto weatherTpSecond = std::chrono::seconds {currentWeather->timestamp}; auto weatherTp = std::chrono::duration_cast(weatherTpSecond); auto delta = currentTime - weatherTp; @@ -141,7 +142,7 @@ std::optional SimpleWeatherService::Curren std::optional SimpleWeatherService::GetForecast() const { if (forecast) { - auto currentTime = dateTimeController.CurrentDateTime().time_since_epoch(); + auto currentTime = std::chrono::system_clock::now().time_since_epoch(); auto weatherTpSecond = std::chrono::seconds {forecast->timestamp}; auto weatherTp = std::chrono::duration_cast(weatherTpSecond); auto delta = currentTime - weatherTp; diff --git a/src/components/ble/SimpleWeatherService.h b/src/components/ble/SimpleWeatherService.h index 0f8c181bd3..6ad214574a 100644 --- a/src/components/ble/SimpleWeatherService.h +++ b/src/components/ble/SimpleWeatherService.h @@ -31,8 +31,6 @@ #undef max #undef min -#include "components/datetime/DateTimeController.h" - int WeatherCallback(uint16_t connHandle, uint16_t attrHandle, struct ble_gatt_access_ctxt* ctxt, void* arg); namespace Pinetime { @@ -40,7 +38,7 @@ namespace Pinetime { class SimpleWeatherService { public: - explicit SimpleWeatherService(DateTime& dateTimeController); + explicit SimpleWeatherService(); void Init(); @@ -165,8 +163,6 @@ namespace Pinetime { uint16_t eventHandle {}; - Pinetime::Controllers::DateTime& dateTimeController; - std::optional currentWeather; std::optional forecast; };