WatchFaceAnalog: Add weather widget

This commit is contained in:
Victor Kareh 2024-01-11 12:55:16 -05:00
parent a9a4d587e8
commit 291920e6ad
2 changed files with 51 additions and 5 deletions

View file

@ -5,6 +5,8 @@
#include "displayapp/screens/BleIcon.h" #include "displayapp/screens/BleIcon.h"
#include "displayapp/screens/Symbols.h" #include "displayapp/screens/Symbols.h"
#include "displayapp/screens/NotificationIcon.h" #include "displayapp/screens/NotificationIcon.h"
#include "displayapp/screens/WeatherSymbols.h"
#include "components/ble/SimpleWeatherService.h"
#include "components/heartrate/HeartRateController.h" #include "components/heartrate/HeartRateController.h"
#include "components/motion/MotionController.h" #include "components/motion/MotionController.h"
#include "components/settings/Settings.h" #include "components/settings/Settings.h"
@ -49,7 +51,8 @@ WatchFaceAnalog::WatchFaceAnalog(Controllers::DateTime& dateTimeController,
Controllers::NotificationManager& notificationManager, Controllers::NotificationManager& notificationManager,
Controllers::Settings& settingsController, Controllers::Settings& settingsController,
Controllers::HeartRateController& heartRateController, Controllers::HeartRateController& heartRateController,
Controllers::MotionController& motionController) Controllers::MotionController& motionController,
Controllers::SimpleWeatherService& weatherService)
: currentDateTime {{}}, : currentDateTime {{}},
batteryIcon(true), batteryIcon(true),
dateTimeController {dateTimeController}, dateTimeController {dateTimeController},
@ -58,7 +61,8 @@ WatchFaceAnalog::WatchFaceAnalog(Controllers::DateTime& dateTimeController,
notificationManager {notificationManager}, notificationManager {notificationManager},
settingsController {settingsController}, settingsController {settingsController},
heartRateController {heartRateController}, heartRateController {heartRateController},
motionController {motionController} { motionController {motionController},
weatherService {weatherService} {
sHour = 99; sHour = 99;
sMinute = 99; sMinute = 99;
@ -117,13 +121,25 @@ WatchFaceAnalog::WatchFaceAnalog(Controllers::DateTime& dateTimeController,
lv_obj_align(notificationIcon, nullptr, LV_ALIGN_IN_TOP_LEFT, 0, 0); lv_obj_align(notificationIcon, nullptr, LV_ALIGN_IN_TOP_LEFT, 0, 0);
// Date - Day / Week day // Date - Day / Week day
label_date_day = lv_label_create(lv_scr_act(), nullptr); 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_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_text_fmt(label_date_day, "%s\n%02i", dateTimeController.DayOfWeekShortToString(), dateTimeController.Day());
lv_label_set_align(label_date_day, LV_LABEL_ALIGN_CENTER); lv_label_set_align(label_date_day, LV_LABEL_ALIGN_CENTER);
lv_obj_align(label_date_day, nullptr, LV_ALIGN_CENTER, 50, 0); 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 = lv_line_create(lv_scr_act(), nullptr);
minute_body_trace = 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); hour_body = lv_line_create(lv_scr_act(), nullptr);
@ -317,4 +333,27 @@ void WatchFaceAnalog::Refresh() {
lv_obj_realign(stepIcon); 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);
}
}
} }

View file

@ -9,6 +9,7 @@
#include "components/battery/BatteryController.h" #include "components/battery/BatteryController.h"
#include "components/ble/BleController.h" #include "components/ble/BleController.h"
#include "components/ble/NotificationManager.h" #include "components/ble/NotificationManager.h"
#include "components/ble/SimpleWeatherService.h"
#include "displayapp/screens/BatteryIcon.h" #include "displayapp/screens/BatteryIcon.h"
#include "utility/DirtyValue.h" #include "utility/DirtyValue.h"
@ -33,7 +34,8 @@ namespace Pinetime {
Controllers::NotificationManager& notificationManager, Controllers::NotificationManager& notificationManager,
Controllers::Settings& settingsController, Controllers::Settings& settingsController,
Controllers::HeartRateController& heartRateController, Controllers::HeartRateController& heartRateController,
Controllers::MotionController& motionController); Controllers::MotionController& motionController,
Controllers::SimpleWeatherService& weather);
~WatchFaceAnalog() override; ~WatchFaceAnalog() override;
void Refresh() override; void Refresh() override;
@ -50,6 +52,7 @@ namespace Pinetime {
Utility::DirtyValue<bool> heartbeatRunning {}; Utility::DirtyValue<bool> heartbeatRunning {};
Utility::DirtyValue<bool> notificationState {false}; Utility::DirtyValue<bool> notificationState {false};
Utility::DirtyValue<std::chrono::time_point<std::chrono::system_clock, std::chrono::days>> currentDate; Utility::DirtyValue<std::chrono::time_point<std::chrono::system_clock, std::chrono::days>> currentDate;
Utility::DirtyValue<std::optional<Pinetime::Controllers::SimpleWeatherService::CurrentWeather>> currentWeather {};
lv_obj_t* minor_scales; lv_obj_t* minor_scales;
lv_obj_t* major_scales; lv_obj_t* major_scales;
@ -83,6 +86,8 @@ namespace Pinetime {
lv_obj_t* heartbeatValue; lv_obj_t* heartbeatValue;
lv_obj_t* stepIcon; lv_obj_t* stepIcon;
lv_obj_t* stepValue; lv_obj_t* stepValue;
lv_obj_t* weatherIcon;
lv_obj_t* temperature;
BatteryIcon batteryIcon; BatteryIcon batteryIcon;
@ -93,6 +98,7 @@ namespace Pinetime {
Controllers::Settings& settingsController; Controllers::Settings& settingsController;
Controllers::HeartRateController& heartRateController; Controllers::HeartRateController& heartRateController;
Controllers::MotionController& motionController; Controllers::MotionController& motionController;
Controllers::SimpleWeatherService& weatherService;
void UpdateClock(); void UpdateClock();
void SetBatteryIcon(); void SetBatteryIcon();
@ -113,7 +119,8 @@ namespace Pinetime {
controllers.notificationManager, controllers.notificationManager,
controllers.settingsController, controllers.settingsController,
controllers.heartRateController, controllers.heartRateController,
controllers.motionController); controllers.motionController,
*controllers.weatherController);
}; };
static bool IsAvailable(Pinetime::Controllers::FS& /*filesystem*/) { static bool IsAvailable(Pinetime::Controllers::FS& /*filesystem*/) {