diff --git a/src/displayapp/screens/WatchFaceAnalog.cpp b/src/displayapp/screens/WatchFaceAnalog.cpp index d2376b19c1..7fd1add154 100644 --- a/src/displayapp/screens/WatchFaceAnalog.cpp +++ b/src/displayapp/screens/WatchFaceAnalog.cpp @@ -5,6 +5,8 @@ #include "displayapp/screens/BleIcon.h" #include "displayapp/screens/Symbols.h" #include "displayapp/screens/NotificationIcon.h" +#include "displayapp/screens/WeatherSymbols.h" +#include "components/ble/SimpleWeatherService.h" #include "components/heartrate/HeartRateController.h" #include "components/motion/MotionController.h" #include "components/settings/Settings.h" @@ -49,7 +51,8 @@ WatchFaceAnalog::WatchFaceAnalog(Controllers::DateTime& dateTimeController, Controllers::NotificationManager& notificationManager, Controllers::Settings& settingsController, Controllers::HeartRateController& heartRateController, - Controllers::MotionController& motionController) + Controllers::MotionController& motionController, + Controllers::SimpleWeatherService& weatherService) : currentDateTime {{}}, batteryIcon(true), dateTimeController {dateTimeController}, @@ -58,7 +61,8 @@ WatchFaceAnalog::WatchFaceAnalog(Controllers::DateTime& dateTimeController, notificationManager {notificationManager}, settingsController {settingsController}, heartRateController {heartRateController}, - motionController {motionController} { + motionController {motionController}, + weatherService {weatherService} { sHour = 99; sMinute = 99; @@ -117,13 +121,25 @@ WatchFaceAnalog::WatchFaceAnalog(Controllers::DateTime& dateTimeController, lv_obj_align(notificationIcon, nullptr, LV_ALIGN_IN_TOP_LEFT, 0, 0); // Date - Day / Week day - label_date_day = lv_label_create(lv_scr_act(), nullptr); lv_obj_set_style_local_text_color(label_date_day, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, Colors::orange); lv_label_set_text_fmt(label_date_day, "%s\n%02i", dateTimeController.DayOfWeekShortToString(), dateTimeController.Day()); lv_label_set_align(label_date_day, LV_LABEL_ALIGN_CENTER); lv_obj_align(label_date_day, nullptr, LV_ALIGN_CENTER, 50, 0); + if (settingsController.IsWidgetOn(Pinetime::Controllers::Settings::Widget::Weather)) { + weatherIcon = lv_label_create(lv_scr_act(), nullptr); + lv_obj_set_style_local_text_color(weatherIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, Colors::lightGray); + 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_CENTER, -50, -12); + + temperature = lv_label_create(lv_scr_act(), nullptr); + lv_obj_set_style_local_text_color(temperature, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, Colors::lightGray); + lv_label_set_text(temperature, ""); + lv_obj_align(temperature, nullptr, LV_ALIGN_CENTER, -50, 12); + } + minute_body = lv_line_create(lv_scr_act(), nullptr); minute_body_trace = lv_line_create(lv_scr_act(), nullptr); hour_body = lv_line_create(lv_scr_act(), nullptr); @@ -317,4 +333,27 @@ void WatchFaceAnalog::Refresh() { lv_obj_realign(stepIcon); } } + + if (settingsController.IsWidgetOn(Pinetime::Controllers::Settings::Widget::Weather)) { + currentWeather = weatherService.Current(); + if (currentWeather.IsUpdated()) { + auto optCurrentWeather = currentWeather.Get(); + if (optCurrentWeather) { + int16_t temp = optCurrentWeather->temperature; + char tempUnit = 'C'; + if (settingsController.GetWeatherFormat() == Controllers::Settings::WeatherFormat::Imperial) { + temp = Controllers::SimpleWeatherService::CelsiusToFahrenheit(temp); + tempUnit = 'F'; + } + temp = temp / 100 + (temp % 100 >= 50 ? 1 : 0); + lv_label_set_text_fmt(temperature, "%d°%c", temp, tempUnit); + lv_label_set_text(weatherIcon, Symbols::GetSymbol(optCurrentWeather->iconId)); + } 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/WatchFaceAnalog.h b/src/displayapp/screens/WatchFaceAnalog.h index 9430351dde..90c58e8678 100644 --- a/src/displayapp/screens/WatchFaceAnalog.h +++ b/src/displayapp/screens/WatchFaceAnalog.h @@ -9,6 +9,7 @@ #include "components/battery/BatteryController.h" #include "components/ble/BleController.h" #include "components/ble/NotificationManager.h" +#include "components/ble/SimpleWeatherService.h" #include "displayapp/screens/BatteryIcon.h" #include "utility/DirtyValue.h" @@ -33,7 +34,8 @@ namespace Pinetime { Controllers::NotificationManager& notificationManager, Controllers::Settings& settingsController, Controllers::HeartRateController& heartRateController, - Controllers::MotionController& motionController); + Controllers::MotionController& motionController, + Controllers::SimpleWeatherService& weather); ~WatchFaceAnalog() override; void Refresh() override; @@ -50,6 +52,7 @@ namespace Pinetime { Utility::DirtyValue heartbeatRunning {}; Utility::DirtyValue notificationState {false}; Utility::DirtyValue> currentDate; + Utility::DirtyValue> currentWeather {}; lv_obj_t* minor_scales; lv_obj_t* major_scales; @@ -83,6 +86,8 @@ namespace Pinetime { lv_obj_t* heartbeatValue; lv_obj_t* stepIcon; lv_obj_t* stepValue; + lv_obj_t* weatherIcon; + lv_obj_t* temperature; BatteryIcon batteryIcon; @@ -93,6 +98,7 @@ namespace Pinetime { Controllers::Settings& settingsController; Controllers::HeartRateController& heartRateController; Controllers::MotionController& motionController; + Controllers::SimpleWeatherService& weatherService; void UpdateClock(); void SetBatteryIcon(); @@ -113,7 +119,8 @@ namespace Pinetime { controllers.notificationManager, controllers.settingsController, controllers.heartRateController, - controllers.motionController); + controllers.motionController, + *controllers.weatherController); }; static bool IsAvailable(Pinetime::Controllers::FS& /*filesystem*/) {