Skip to content

Commit

Permalink
port SimpleWeatherService to std::chrono::system_clock::now()
Browse files Browse the repository at this point in the history
  • Loading branch information
Lionel Elie Mamane committed Nov 9, 2024
1 parent 4c5e676 commit 9a951be
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/components/ble/NimbleController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down
7 changes: 4 additions & 3 deletions src/components/ble/SimpleWeatherService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <algorithm>
#include <array>
#include <cstring>
#include <chrono>
#include <nrf_log.h>

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

SimpleWeatherService::SimpleWeatherService(DateTime& dateTimeController) : dateTimeController(dateTimeController) {
SimpleWeatherService::SimpleWeatherService() {
}

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

std::optional<SimpleWeatherService::CurrentWeather> 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<std::chrono::seconds>(weatherTpSecond);
auto delta = currentTime - weatherTp;
Expand All @@ -141,7 +142,7 @@ std::optional<SimpleWeatherService::CurrentWeather> SimpleWeatherService::Curren

std::optional<SimpleWeatherService::Forecast> 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<std::chrono::seconds>(weatherTpSecond);
auto delta = currentTime - weatherTp;
Expand Down
6 changes: 1 addition & 5 deletions src/components/ble/SimpleWeatherService.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,14 @@
#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 {
namespace Controllers {

class SimpleWeatherService {
public:
explicit SimpleWeatherService(DateTime& dateTimeController);
explicit SimpleWeatherService();

void Init();

Expand Down Expand Up @@ -165,8 +163,6 @@ namespace Pinetime {

uint16_t eventHandle {};

Pinetime::Controllers::DateTime& dateTimeController;

std::optional<CurrentWeather> currentWeather;
std::optional<Forecast> forecast;
};
Expand Down

0 comments on commit 9a951be

Please sign in to comment.