Skip to content

Commit 5a0ad54

Browse files
committed
WatchFaceAnalog: Add weather widget
1 parent 55a515b commit 5a0ad54

File tree

2 files changed

+48
-5
lines changed

2 files changed

+48
-5
lines changed

src/displayapp/screens/WatchFaceAnalog.cpp

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
#include "displayapp/screens/BleIcon.h"
77
#include "displayapp/screens/Symbols.h"
88
#include "displayapp/screens/NotificationIcon.h"
9+
#include "displayapp/screens/WeatherSymbols.h"
10+
#include "components/ble/SimpleWeatherService.h"
911
#include "components/heartrate/HeartRateController.h"
1012
#include "components/motion/MotionController.h"
1113
#include "components/settings/Settings.h"
@@ -52,7 +54,8 @@ WatchFaceAnalog::WatchFaceAnalog(Controllers::DateTime& dateTimeController,
5254
Controllers::NotificationManager& notificationManager,
5355
Controllers::Settings& settingsController,
5456
Controllers::HeartRateController& heartRateController,
55-
Controllers::MotionController& motionController)
57+
Controllers::MotionController& motionController,
58+
Controllers::SimpleWeatherService& weatherService)
5659
: currentDateTime {{}},
5760
batteryIcon(true),
5861
dateTimeController {dateTimeController},
@@ -61,7 +64,8 @@ WatchFaceAnalog::WatchFaceAnalog(Controllers::DateTime& dateTimeController,
6164
notificationManager {notificationManager},
6265
settingsController {settingsController},
6366
heartRateController {heartRateController},
64-
motionController {motionController} {
67+
motionController {motionController},
68+
weatherService {weatherService} {
6569

6670
sHour = 99;
6771
sMinute = 99;
@@ -120,13 +124,25 @@ WatchFaceAnalog::WatchFaceAnalog(Controllers::DateTime& dateTimeController,
120124
lv_obj_align(notificationIcon, nullptr, LV_ALIGN_IN_TOP_LEFT, 0, 0);
121125

122126
// Date - Day / Week day
123-
124127
label_date_day = lv_label_create(lv_scr_act(), nullptr);
125128
lv_obj_set_style_local_text_color(label_date_day, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, Colors::orange);
126129
lv_label_set_text_fmt(label_date_day, "%s\n%02i", dateTimeController.DayOfWeekShortToString(), dateTimeController.Day());
127130
lv_label_set_align(label_date_day, LV_LABEL_ALIGN_CENTER);
128131
lv_obj_align(label_date_day, nullptr, LV_ALIGN_CENTER, 50, 0);
129132

133+
if (settingsController.IsWidgetOn(Pinetime::Controllers::Settings::Widget::Weather)) {
134+
weatherIcon = lv_label_create(lv_scr_act(), nullptr);
135+
lv_obj_set_style_local_text_color(weatherIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, Colors::lightGray);
136+
lv_obj_set_style_local_text_font(weatherIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &fontawesome_weathericons);
137+
lv_label_set_text(weatherIcon, "");
138+
lv_obj_align(weatherIcon, nullptr, LV_ALIGN_CENTER, -50, -12);
139+
140+
temperature = lv_label_create(lv_scr_act(), nullptr);
141+
lv_obj_set_style_local_text_color(temperature, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, Colors::lightGray);
142+
lv_label_set_text(temperature, "");
143+
lv_obj_align(temperature, nullptr, LV_ALIGN_CENTER, -50, 12);
144+
}
145+
130146
minute_body = lv_line_create(lv_scr_act(), nullptr);
131147
minute_body_trace = lv_line_create(lv_scr_act(), nullptr);
132148
hour_body = lv_line_create(lv_scr_act(), nullptr);
@@ -320,4 +336,24 @@ void WatchFaceAnalog::Refresh() {
320336
lv_obj_realign(stepIcon);
321337
}
322338
}
339+
340+
if (settingsController.IsWidgetOn(Pinetime::Controllers::Settings::Widget::Weather)) {
341+
currentWeather = weatherService.Current();
342+
if (currentWeather.IsUpdated()) {
343+
auto optCurrentWeather = currentWeather.Get();
344+
if (optCurrentWeather) {
345+
int16_t temp = optCurrentWeather->temperature.Celsius();
346+
char tempUnit = 'C';
347+
if (settingsController.GetWeatherFormat() == Controllers::Settings::WeatherFormat::Imperial) {
348+
temp = optCurrentWeather->temperature.Fahrenheit();
349+
tempUnit = 'F';
350+
}
351+
lv_label_set_text_fmt(temperature, "%d°%c", temp, tempUnit);
352+
lv_label_set_text(weatherIcon, Symbols::GetSymbol(optCurrentWeather->iconId, weatherService.IsNight()));
353+
} else {
354+
lv_label_set_text_static(temperature, "");
355+
lv_label_set_text(weatherIcon, "");
356+
}
357+
}
358+
}
323359
}

src/displayapp/screens/WatchFaceAnalog.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "components/battery/BatteryController.h"
1010
#include "components/ble/BleController.h"
1111
#include "components/ble/NotificationManager.h"
12+
#include "components/ble/SimpleWeatherService.h"
1213
#include "displayapp/screens/BatteryIcon.h"
1314
#include "utility/DirtyValue.h"
1415

@@ -33,7 +34,8 @@ namespace Pinetime {
3334
Controllers::NotificationManager& notificationManager,
3435
Controllers::Settings& settingsController,
3536
Controllers::HeartRateController& heartRateController,
36-
Controllers::MotionController& motionController);
37+
Controllers::MotionController& motionController,
38+
Controllers::SimpleWeatherService& weather);
3739
~WatchFaceAnalog() override;
3840

3941
void Refresh() override;
@@ -50,6 +52,7 @@ namespace Pinetime {
5052
Utility::DirtyValue<bool> heartbeatRunning {};
5153
Utility::DirtyValue<bool> notificationState {false};
5254
Utility::DirtyValue<std::chrono::time_point<std::chrono::system_clock, std::chrono::days>> currentDate;
55+
Utility::DirtyValue<std::optional<Pinetime::Controllers::SimpleWeatherService::CurrentWeather>> currentWeather {};
5356

5457
lv_obj_t* minor_scales;
5558
lv_obj_t* major_scales;
@@ -83,6 +86,8 @@ namespace Pinetime {
8386
lv_obj_t* heartbeatValue;
8487
lv_obj_t* stepIcon;
8588
lv_obj_t* stepValue;
89+
lv_obj_t* weatherIcon;
90+
lv_obj_t* temperature;
8691

8792
BatteryIcon batteryIcon;
8893

@@ -93,6 +98,7 @@ namespace Pinetime {
9398
Controllers::Settings& settingsController;
9499
Controllers::HeartRateController& heartRateController;
95100
Controllers::MotionController& motionController;
101+
Controllers::SimpleWeatherService& weatherService;
96102

97103
void UpdateClock();
98104
void SetBatteryIcon();
@@ -113,7 +119,8 @@ namespace Pinetime {
113119
controllers.notificationManager,
114120
controllers.settingsController,
115121
controllers.heartRateController,
116-
controllers.motionController);
122+
controllers.motionController,
123+
*controllers.weatherController);
117124
};
118125

119126
static bool IsAvailable(Pinetime::Controllers::FS& /*filesystem*/) {

0 commit comments

Comments
 (0)