From f408bc1c71ba3f4ecf2b3c0ad142a05ca50d6625 Mon Sep 17 00:00:00 2001 From: locker98 Date: Thu, 9 May 2024 09:37:33 -0400 Subject: [PATCH] added code for weather in g7710 watchface --- .../screens/WatchFaceCasioStyleG7710.cpp | 27 ++++++++++++++++++- .../screens/WatchFaceCasioStyleG7710.h | 8 ++++-- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/src/displayapp/screens/WatchFaceCasioStyleG7710.cpp b/src/displayapp/screens/WatchFaceCasioStyleG7710.cpp index b842e75c..5b1b1996 100644 --- a/src/displayapp/screens/WatchFaceCasioStyleG7710.cpp +++ b/src/displayapp/screens/WatchFaceCasioStyleG7710.cpp @@ -11,6 +11,7 @@ #include "components/ble/NotificationManager.h" #include "components/motion/MotionController.h" #include "components/settings/Settings.h" +#include "components/ble/SimpleWeatherService.h" using namespace Pinetime::Applications::Screens; WatchFaceCasioStyleG7710::WatchFaceCasioStyleG7710(Controllers::DateTime& dateTimeController, @@ -19,7 +20,8 @@ WatchFaceCasioStyleG7710::WatchFaceCasioStyleG7710(Controllers::DateTime& dateTi Controllers::NotificationManager& notificatioManager, Controllers::Settings& settingsController, Controllers::MotionController& motionController, - Controllers::FS& filesystem) + Controllers::FS& filesystem + Controllers::SimpleWeatherService& weatherService) : currentDateTime {{}}, batteryIcon(false), dateTimeController {dateTimeController}, @@ -27,6 +29,7 @@ WatchFaceCasioStyleG7710::WatchFaceCasioStyleG7710(Controllers::DateTime& dateTi bleController {bleController}, notificatioManager {notificatioManager}, settingsController {settingsController}, + weatherService {weatherService}, motionController {motionController} { lfs_file f = {}; @@ -292,6 +295,28 @@ void WatchFaceCasioStyleG7710::Refresh() { lv_obj_realign(stepValue); lv_obj_realign(stepValue); } + + + 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); + } } bool WatchFaceCasioStyleG7710::IsAvailable(Pinetime::Controllers::FS& filesystem) { diff --git a/src/displayapp/screens/WatchFaceCasioStyleG7710.h b/src/displayapp/screens/WatchFaceCasioStyleG7710.h index c9305a71..b1250aa3 100644 --- a/src/displayapp/screens/WatchFaceCasioStyleG7710.h +++ b/src/displayapp/screens/WatchFaceCasioStyleG7710.h @@ -11,6 +11,7 @@ #include "components/ble/BleController.h" #include "utility/DirtyValue.h" #include "displayapp/apps/Apps.h" +#include "components/ble/SimpleWeatherService.h" namespace Pinetime { namespace Controllers { @@ -32,7 +33,8 @@ namespace Pinetime { Controllers::NotificationManager& notificatioManager, Controllers::Settings& settingsController, Controllers::MotionController& motionController, - Controllers::FS& filesystem); + Controllers::FS& filesystem, + Controllers::SimpleWeatherService& weather); ~WatchFaceCasioStyleG7710() override; void Refresh() override; @@ -88,6 +90,7 @@ namespace Pinetime { Controllers::NotificationManager& notificatioManager; Controllers::Settings& settingsController; Controllers::MotionController& motionController; + Controllers::SimpleWeatherService& weatherService; lv_task_t* taskRefresh; lv_font_t* font_dot40 = nullptr; @@ -108,7 +111,8 @@ namespace Pinetime { controllers.notificationManager, controllers.settingsController, controllers.motionController, - controllers.filesystem); + controllers.filesystem, + *controllers.weatherController); }; static bool IsAvailable(Pinetime::Controllers::FS& filesystem) {