From 82e79629d18fc12f10ed920408ed837dd21a1209 Mon Sep 17 00:00:00 2001 From: Victor Kareh Date: Thu, 7 Sep 2023 16:41:27 -0400 Subject: [PATCH] WatchFaceDigital: Add weather display If weather is available, display the cloud icon and temperature. --- src/displayapp/screens/Clock.cpp | 3 +- src/displayapp/screens/WatchFaceDigital.cpp | 44 ++++++++++++++++++++- src/displayapp/screens/WatchFaceDigital.h | 10 ++++- 3 files changed, 54 insertions(+), 3 deletions(-) diff --git a/src/displayapp/screens/Clock.cpp b/src/displayapp/screens/Clock.cpp index 4219b090db..1edf4eddd3 100644 --- a/src/displayapp/screens/Clock.cpp +++ b/src/displayapp/screens/Clock.cpp @@ -80,7 +80,8 @@ std::unique_ptr Clock::WatchFaceDigitalScreen() { notificationManager, settingsController, heartRateController, - motionController); + motionController, + weatherService); } std::unique_ptr Clock::WatchFaceAnalogScreen() { diff --git a/src/displayapp/screens/WatchFaceDigital.cpp b/src/displayapp/screens/WatchFaceDigital.cpp index ca53691b12..18dabd8548 100644 --- a/src/displayapp/screens/WatchFaceDigital.cpp +++ b/src/displayapp/screens/WatchFaceDigital.cpp @@ -9,6 +9,7 @@ #include "components/ble/NotificationManager.h" #include "components/heartrate/HeartRateController.h" #include "components/motion/MotionController.h" +#include "components/ble/weather/WeatherService.h" #include "components/settings/Settings.h" using namespace Pinetime::Applications::Screens; @@ -19,13 +20,15 @@ WatchFaceDigital::WatchFaceDigital(Controllers::DateTime& dateTimeController, Controllers::NotificationManager& notificationManager, Controllers::Settings& settingsController, Controllers::HeartRateController& heartRateController, - Controllers::MotionController& motionController) + Controllers::MotionController& motionController, + Controllers::WeatherService& weatherService) : currentDateTime {{}}, dateTimeController {dateTimeController}, notificationManager {notificationManager}, settingsController {settingsController}, heartRateController {heartRateController}, motionController {motionController}, + weatherService {weatherService}, statusIcons(batteryController, bleController) { statusIcons.Create(); @@ -35,6 +38,17 @@ WatchFaceDigital::WatchFaceDigital(Controllers::DateTime& dateTimeController, lv_label_set_text_static(notificationIcon, NotificationIcon::GetIcon(false)); lv_obj_align(notificationIcon, nullptr, LV_ALIGN_IN_TOP_LEFT, 0, 0); + weatherIcon = lv_label_create(lv_scr_act(), nullptr); + lv_obj_set_style_local_text_color(weatherIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_WHITE); + lv_obj_set_style_local_text_font(weatherIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &fontawesome_weathericons); + lv_label_set_text(weatherIcon, ""); + lv_obj_align(weatherIcon, nullptr, LV_ALIGN_IN_TOP_MID, -20, 0); + lv_obj_set_auto_realign(weatherIcon, true); + + temperature = lv_label_create(lv_scr_act(), nullptr); + lv_obj_set_style_local_text_color(temperature, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_WHITE); + lv_obj_align(temperature, nullptr, LV_ALIGN_IN_TOP_MID, 20, 0); + label_date = lv_label_create(lv_scr_act(), nullptr); lv_obj_align(label_date, lv_scr_act(), LV_ALIGN_CENTER, 0, 60); lv_obj_set_style_local_text_color(label_date, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x999999)); @@ -153,4 +167,32 @@ void WatchFaceDigital::Refresh() { lv_obj_realign(stepValue); lv_obj_realign(stepIcon); } + + 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); + }; + lv_obj_realign(temperature); + lv_obj_realign(weatherIcon); + } + } else { + lv_label_set_text_static(temperature, ""); + lv_label_set_text(weatherIcon, ""); + lv_obj_realign(temperature); + lv_obj_realign(weatherIcon); + } } diff --git a/src/displayapp/screens/WatchFaceDigital.h b/src/displayapp/screens/WatchFaceDigital.h index f2409880e9..b46459dec3 100644 --- a/src/displayapp/screens/WatchFaceDigital.h +++ b/src/displayapp/screens/WatchFaceDigital.h @@ -6,6 +6,7 @@ #include #include "displayapp/screens/Screen.h" #include "components/datetime/DateTimeController.h" +#include "components/ble/weather/WeatherService.h" #include "components/ble/BleController.h" #include "displayapp/widgets/StatusIcons.h" #include "utility/DirtyValue.h" @@ -31,7 +32,8 @@ namespace Pinetime { Controllers::NotificationManager& notificationManager, Controllers::Settings& settingsController, Controllers::HeartRateController& heartRateController, - Controllers::MotionController& motionController); + Controllers::MotionController& motionController, + Controllers::WeatherService& weather); ~WatchFaceDigital() override; void Refresh() override; @@ -49,6 +51,9 @@ namespace Pinetime { Utility::DirtyValue heartbeat {}; Utility::DirtyValue heartbeatRunning {}; Utility::DirtyValue notificationState {}; + Utility::DirtyValue nowTemp {}; + int16_t clouds = 0; + int16_t precip = 0; using days = std::chrono::duration>; // TODO: days is standard in c++20 Utility::DirtyValue> currentDate; @@ -60,12 +65,15 @@ namespace Pinetime { lv_obj_t* stepIcon; lv_obj_t* stepValue; lv_obj_t* notificationIcon; + lv_obj_t* weatherIcon; + lv_obj_t* temperature; Controllers::DateTime& dateTimeController; Controllers::NotificationManager& notificationManager; Controllers::Settings& settingsController; Controllers::HeartRateController& heartRateController; Controllers::MotionController& motionController; + Controllers::WeatherService& weatherService; lv_task_t* taskRefresh; Widgets::StatusIcons statusIcons;