Skip to content

Commit ce60825

Browse files
author
Lionel Elie Mamane
committed
port SimpleWeatherService to std::chrono::system_clock::now()
1 parent ed63972 commit ce60825

File tree

3 files changed

+6
-9
lines changed

3 files changed

+6
-9
lines changed

src/components/ble/NimbleController.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ NimbleController::NimbleController(Pinetime::System::SystemTask& systemTask,
4343
alertNotificationClient {systemTask, notificationManager},
4444
currentTimeService {dateTimeController},
4545
musicService {*this},
46-
weatherService {dateTimeController},
46+
weatherService {},
4747
batteryInformationService {batteryController},
4848
immediateAlertService {systemTask, notificationManager},
4949
heartRateService {*this, heartRateController},

src/components/ble/SimpleWeatherService.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <algorithm>
2222
#include <array>
2323
#include <cstring>
24+
#include <chrono>
2425
#include <nrf_log.h>
2526

2627
using namespace Pinetime::Controllers;
@@ -80,7 +81,7 @@ int WeatherCallback(uint16_t /*connHandle*/, uint16_t /*attrHandle*/, struct ble
8081
return static_cast<Pinetime::Controllers::SimpleWeatherService*>(arg)->OnCommand(ctxt);
8182
}
8283

83-
SimpleWeatherService::SimpleWeatherService(DateTime& dateTimeController) : dateTimeController(dateTimeController) {
84+
SimpleWeatherService::SimpleWeatherService() {
8485
}
8586

8687
void SimpleWeatherService::Init() {
@@ -127,7 +128,7 @@ int SimpleWeatherService::OnCommand(struct ble_gatt_access_ctxt* ctxt) {
127128

128129
std::optional<SimpleWeatherService::CurrentWeather> SimpleWeatherService::Current() const {
129130
if (currentWeather) {
130-
auto currentTime = dateTimeController.CurrentDateTime().time_since_epoch();
131+
auto currentTime = std::chrono::system_clock::now().time_since_epoch();
131132
auto weatherTpSecond = std::chrono::seconds {currentWeather->timestamp};
132133
auto weatherTp = std::chrono::duration_cast<std::chrono::seconds>(weatherTpSecond);
133134
auto delta = currentTime - weatherTp;
@@ -141,7 +142,7 @@ std::optional<SimpleWeatherService::CurrentWeather> SimpleWeatherService::Curren
141142

142143
std::optional<SimpleWeatherService::Forecast> SimpleWeatherService::GetForecast() const {
143144
if (forecast) {
144-
auto currentTime = dateTimeController.CurrentDateTime().time_since_epoch();
145+
auto currentTime = std::chrono::system_clock::now().time_since_epoch();
145146
auto weatherTpSecond = std::chrono::seconds {forecast->timestamp};
146147
auto weatherTp = std::chrono::duration_cast<std::chrono::seconds>(weatherTpSecond);
147148
auto delta = currentTime - weatherTp;

src/components/ble/SimpleWeatherService.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,14 @@
3131
#undef max
3232
#undef min
3333

34-
#include "components/datetime/DateTimeController.h"
35-
3634
int WeatherCallback(uint16_t connHandle, uint16_t attrHandle, struct ble_gatt_access_ctxt* ctxt, void* arg);
3735

3836
namespace Pinetime {
3937
namespace Controllers {
4038

4139
class SimpleWeatherService {
4240
public:
43-
explicit SimpleWeatherService(DateTime& dateTimeController);
41+
explicit SimpleWeatherService();
4442

4543
void Init();
4644

@@ -165,8 +163,6 @@ namespace Pinetime {
165163

166164
uint16_t eventHandle {};
167165

168-
Pinetime::Controllers::DateTime& dateTimeController;
169-
170166
std::optional<CurrentWeather> currentWeather;
171167
std::optional<Forecast> forecast;
172168
};

0 commit comments

Comments
 (0)