From c94a59e7d3e0f9929171263412033a56872c168a Mon Sep 17 00:00:00 2001 From: Jean-François Milants Date: Sat, 9 Dec 2023 20:39:08 +0100 Subject: SimpleWeather service : new weather implementation This new implementation of the weather feature provides a new BLE API and a new weather service. The API uses a single characteristic that allows companion apps to write the weather conditions (current and forecast for the next 5 days). The SimpleWeather service exposes those data as std::optional fields. This new implementation replaces the previous WeahterService. The API is documented in docs/SimpleWeatherService.md. --- src/displayapp/Controllers.h | 4 +- src/displayapp/DisplayApp.cpp | 3 +- src/displayapp/DisplayApp.h | 3 +- src/displayapp/screens/StopWatch.cpp | 2 + src/displayapp/screens/WatchFacePineTimeStyle.cpp | 46 ++++++++++++----------- src/displayapp/screens/WatchFacePineTimeStyle.h | 10 ++--- src/displayapp/screens/Weather.cpp | 2 +- src/displayapp/screens/Weather.h | 2 +- 8 files changed, 38 insertions(+), 34 deletions(-) (limited to 'src/displayapp') diff --git a/src/displayapp/Controllers.h b/src/displayapp/Controllers.h index df6b2284..9992426c 100644 --- a/src/displayapp/Controllers.h +++ b/src/displayapp/Controllers.h @@ -20,7 +20,7 @@ namespace Pinetime { class MotionController; class AlarmController; class BrightnessController; - class WeatherService; + class SimpleWeatherService; class FS; class Timer; class MusicService; @@ -43,7 +43,7 @@ namespace Pinetime { Pinetime::Controllers::MotionController& motionController; Pinetime::Controllers::AlarmController& alarmController; Pinetime::Controllers::BrightnessController& brightnessController; - Pinetime::Controllers::WeatherService* weatherController; + Pinetime::Controllers::SimpleWeatherService* weatherController; Pinetime::Controllers::FS& filesystem; Pinetime::Controllers::Timer& timer; Pinetime::System::SystemTask* systemTask; diff --git a/src/displayapp/DisplayApp.cpp b/src/displayapp/DisplayApp.cpp index 3b34d7b8..28ce0bab 100644 --- a/src/displayapp/DisplayApp.cpp +++ b/src/displayapp/DisplayApp.cpp @@ -28,7 +28,6 @@ #include "displayapp/screens/Steps.h" #include "displayapp/screens/PassKey.h" #include "displayapp/screens/Error.h" -#include "displayapp/screens/Weather.h" #include "drivers/Cst816s.h" #include "drivers/St7789.h" @@ -607,7 +606,7 @@ void DisplayApp::Register(Pinetime::System::SystemTask* systemTask) { this->controllers.systemTask = systemTask; } -void DisplayApp::Register(Pinetime::Controllers::WeatherService* weatherService) { +void DisplayApp::Register(Pinetime::Controllers::SimpleWeatherService* weatherService) { this->controllers.weatherController = weatherService; } diff --git a/src/displayapp/DisplayApp.h b/src/displayapp/DisplayApp.h index 7dbac850..349ca014 100644 --- a/src/displayapp/DisplayApp.h +++ b/src/displayapp/DisplayApp.h @@ -39,6 +39,7 @@ namespace Pinetime { class HeartRateController; class MotionController; class TouchHandler; + class SimpleWeatherService; } namespace System { @@ -74,7 +75,7 @@ namespace Pinetime { void SetFullRefresh(FullRefreshDirections direction); void Register(Pinetime::System::SystemTask* systemTask); - void Register(Pinetime::Controllers::WeatherService* weatherService); + void Register(Pinetime::Controllers::SimpleWeatherService* weatherService); void Register(Pinetime::Controllers::MusicService* musicService); void Register(Pinetime::Controllers::NavigationService* NavigationService); diff --git a/src/displayapp/screens/StopWatch.cpp b/src/displayapp/screens/StopWatch.cpp index f0359da4..bdb3fde6 100644 --- a/src/displayapp/screens/StopWatch.cpp +++ b/src/displayapp/screens/StopWatch.cpp @@ -5,6 +5,8 @@ using namespace Pinetime::Applications::Screens; +constexpr int Pinetime::Applications::Screens::StopWatch::maxLapCount; + namespace { TimeSeparated_t convertTicksToTimeSegments(const TickType_t timeElapsed) { // Centiseconds diff --git a/src/displayapp/screens/WatchFacePineTimeStyle.cpp b/src/displayapp/screens/WatchFacePineTimeStyle.cpp index 250a745c..65122493 100644 --- a/src/displayapp/screens/WatchFacePineTimeStyle.cpp +++ b/src/displayapp/screens/WatchFacePineTimeStyle.cpp @@ -33,7 +33,7 @@ #include "components/motion/MotionController.h" #include "components/settings/Settings.h" #include "displayapp/DisplayApp.h" -#include "components/ble/weather/WeatherService.h" +#include "components/ble/SimpleWeatherService.h" using namespace Pinetime::Applications::Screens; @@ -42,6 +42,21 @@ namespace { auto* screen = static_cast(obj->user_data); screen->UpdateSelected(obj, event); } + + const char* GetIcon(const Pinetime::Controllers::SimpleWeatherService::Icons icon) { + switch (icon) { + case Pinetime::Controllers::SimpleWeatherService::Icons::Sun: return Symbols::sun; break; + case Pinetime::Controllers::SimpleWeatherService::Icons::CloudsSun: return Symbols::cloudSun; break; + case Pinetime::Controllers::SimpleWeatherService::Icons::Clouds: return Symbols::cloud; break; + case Pinetime::Controllers::SimpleWeatherService::Icons::BrokenClouds: return Symbols::cloud; break; // TODO missing symbol + case Pinetime::Controllers::SimpleWeatherService::Icons::Thunderstorm: return Symbols::cloud; break; // TODO missing symbol + case Pinetime::Controllers::SimpleWeatherService::Icons::Snow: return Symbols::cloud; break; // TODO missing symbol + case Pinetime::Controllers::SimpleWeatherService::Icons::CloudShowerHeavy: return Symbols::cloudShowersHeavy; break; + case Pinetime::Controllers::SimpleWeatherService::Icons::CloudSunRain: return Symbols::cloudSunRain; break; + case Pinetime::Controllers::SimpleWeatherService::Icons::Smog: return Symbols::smog; break; + default: return Symbols::ban; break; + } + } } WatchFacePineTimeStyle::WatchFacePineTimeStyle(Controllers::DateTime& dateTimeController, @@ -50,7 +65,7 @@ WatchFacePineTimeStyle::WatchFacePineTimeStyle(Controllers::DateTime& dateTimeCo Controllers::NotificationManager& notificationManager, Controllers::Settings& settingsController, Controllers::MotionController& motionController, - Controllers::WeatherService& weatherService) + Controllers::SimpleWeatherService& weatherService) : currentDateTime {{}}, batteryIcon(false), dateTimeController {dateTimeController}, @@ -537,29 +552,18 @@ void WatchFacePineTimeStyle::Refresh() { } } - if (weatherService.GetCurrentTemperature()->timestamp != 0 && weatherService.GetCurrentClouds()->timestamp != 0 && - weatherService.GetCurrentPrecipitation()->timestamp != 0) { - nowTemp = (weatherService.GetCurrentTemperature()->temperature / 100); - clouds = (weatherService.GetCurrentClouds()->amount); - precip = (weatherService.GetCurrentPrecipitation()->amount); - if (nowTemp.IsUpdated()) { - lv_label_set_text_fmt(temperature, "%d°", nowTemp.Get()); - if ((clouds <= 30) && (precip == 0)) { - lv_label_set_text(weatherIcon, Symbols::sun); - } else if ((clouds >= 70) && (clouds <= 90) && (precip == 1)) { - lv_label_set_text(weatherIcon, Symbols::cloudSunRain); - } else if ((clouds > 90) && (precip == 0)) { - lv_label_set_text(weatherIcon, Symbols::cloud); - } else if ((clouds > 70) && (precip >= 2)) { - lv_label_set_text(weatherIcon, Symbols::cloudShowersHeavy); - } else { - lv_label_set_text(weatherIcon, Symbols::cloudSun); - }; + currentWeather = weatherService.Current(); + + if (currentWeather.IsUpdated()) { + auto optCurrentWeather = currentWeather.Get(); + if (optCurrentWeather) { + lv_label_set_text_fmt(temperature, "%d°", optCurrentWeather->temperature); + lv_label_set_text(weatherIcon, GetIcon(optCurrentWeather->iconId)); lv_obj_realign(temperature); lv_obj_realign(weatherIcon); } } else { - lv_label_set_text_static(temperature, "--"); + lv_label_set_text(temperature, "--"); lv_label_set_text(weatherIcon, Symbols::ban); lv_obj_realign(temperature); lv_obj_realign(weatherIcon); diff --git a/src/displayapp/screens/WatchFacePineTimeStyle.h b/src/displayapp/screens/WatchFacePineTimeStyle.h index dd079fed..72537095 100644 --- a/src/displayapp/screens/WatchFacePineTimeStyle.h +++ b/src/displayapp/screens/WatchFacePineTimeStyle.h @@ -9,7 +9,7 @@ #include "displayapp/screens/BatteryIcon.h" #include "displayapp/Colors.h" #include "components/datetime/DateTimeController.h" -#include "components/ble/weather/WeatherService.h" +#include "components/ble/SimpleWeatherService.h" #include "components/ble/BleController.h" #include "utility/DirtyValue.h" @@ -33,7 +33,7 @@ namespace Pinetime { Controllers::NotificationManager& notificationManager, Controllers::Settings& settingsController, Controllers::MotionController& motionController, - Controllers::WeatherService& weather); + Controllers::SimpleWeatherService& weather); ~WatchFacePineTimeStyle() override; bool OnTouchEvent(TouchEvents event) override; @@ -61,9 +61,7 @@ namespace Pinetime { Utility::DirtyValue> currentDateTime {}; Utility::DirtyValue stepCount {}; Utility::DirtyValue notificationState {}; - Utility::DirtyValue nowTemp {}; - int16_t clouds = 0; - int16_t precip = 0; + Utility::DirtyValue> currentWeather {}; static Pinetime::Controllers::Settings::Colors GetNext(Controllers::Settings::Colors color); static Pinetime::Controllers::Settings::Colors GetPrevious(Controllers::Settings::Colors color); @@ -114,7 +112,7 @@ namespace Pinetime { Controllers::NotificationManager& notificationManager; Controllers::Settings& settingsController; Controllers::MotionController& motionController; - Controllers::WeatherService& weatherService; + Controllers::SimpleWeatherService& weatherService; void SetBatteryIcon(); void CloseMenu(); diff --git a/src/displayapp/screens/Weather.cpp b/src/displayapp/screens/Weather.cpp index 4921174c..dfeb1d41 100644 --- a/src/displayapp/screens/Weather.cpp +++ b/src/displayapp/screens/Weather.cpp @@ -17,7 +17,7 @@ */ #include "Weather.h" #include -#include +#include #include "Label.h" #include "components/battery/BatteryController.h" #include "components/ble/BleController.h" diff --git a/src/displayapp/screens/Weather.h b/src/displayapp/screens/Weather.h index 84177ea6..6b2599c8 100644 --- a/src/displayapp/screens/Weather.h +++ b/src/displayapp/screens/Weather.h @@ -1,7 +1,7 @@ #pragma once #include -#include "components/ble/weather/WeatherService.h" +#include "components/ble/weather/SimpleWeatherService.h" #include "Screen.h" #include "ScreenList.h" #include "displayapp/Apps.h" -- cgit v1.2.3-70-g09d2