Skip to content

Commit 9f38743

Browse files
committed
WatchFaceAnalog: Add weather widget
1 parent 743ab9e commit 9f38743

File tree

2 files changed

+48
-5
lines changed

2 files changed

+48
-5
lines changed

src/displayapp/screens/WatchFaceAnalog.cpp

+39-3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
#include "displayapp/screens/BleIcon.h"
66
#include "displayapp/screens/Symbols.h"
77
#include "displayapp/screens/NotificationIcon.h"
8+
#include "displayapp/screens/WeatherSymbols.h"
9+
#include "components/ble/SimpleWeatherService.h"
810
#include "components/heartrate/HeartRateController.h"
911
#include "components/motion/MotionController.h"
1012
#include "components/settings/Settings.h"
@@ -49,7 +51,8 @@ WatchFaceAnalog::WatchFaceAnalog(Controllers::DateTime& dateTimeController,
4951
Controllers::NotificationManager& notificationManager,
5052
Controllers::Settings& settingsController,
5153
Controllers::HeartRateController& heartRateController,
52-
Controllers::MotionController& motionController)
54+
Controllers::MotionController& motionController,
55+
Controllers::SimpleWeatherService& weatherService)
5356
: currentDateTime {{}},
5457
batteryIcon(true),
5558
dateTimeController {dateTimeController},
@@ -58,7 +61,8 @@ WatchFaceAnalog::WatchFaceAnalog(Controllers::DateTime& dateTimeController,
5861
notificationManager {notificationManager},
5962
settingsController {settingsController},
6063
heartRateController {heartRateController},
61-
motionController {motionController} {
64+
motionController {motionController},
65+
weatherService {weatherService} {
6266

6367
sHour = 99;
6468
sMinute = 99;
@@ -117,13 +121,25 @@ WatchFaceAnalog::WatchFaceAnalog(Controllers::DateTime& dateTimeController,
117121
lv_obj_align(notificationIcon, nullptr, LV_ALIGN_IN_TOP_LEFT, 0, 0);
118122

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

130+
if (settingsController.IsWidgetOn(Pinetime::Controllers::Settings::Widget::Weather)) {
131+
weatherIcon = lv_label_create(lv_scr_act(), nullptr);
132+
lv_obj_set_style_local_text_color(weatherIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, Colors::lightGray);
133+
lv_obj_set_style_local_text_font(weatherIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &fontawesome_weathericons);
134+
lv_label_set_text(weatherIcon, "");
135+
lv_obj_align(weatherIcon, nullptr, LV_ALIGN_CENTER, -50, -12);
136+
137+
temperature = lv_label_create(lv_scr_act(), nullptr);
138+
lv_obj_set_style_local_text_color(temperature, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, Colors::lightGray);
139+
lv_label_set_text(temperature, "");
140+
lv_obj_align(temperature, nullptr, LV_ALIGN_CENTER, -50, 12);
141+
}
142+
127143
minute_body = lv_line_create(lv_scr_act(), nullptr);
128144
minute_body_trace = lv_line_create(lv_scr_act(), nullptr);
129145
hour_body = lv_line_create(lv_scr_act(), nullptr);
@@ -317,4 +333,24 @@ void WatchFaceAnalog::Refresh() {
317333
lv_obj_realign(stepIcon);
318334
}
319335
}
336+
337+
if (settingsController.IsWidgetOn(Pinetime::Controllers::Settings::Widget::Weather)) {
338+
currentWeather = weatherService.Current();
339+
if (currentWeather.IsUpdated()) {
340+
auto optCurrentWeather = currentWeather.Get();
341+
if (optCurrentWeather) {
342+
int16_t temp = optCurrentWeather->temperature.Celsius();
343+
char tempUnit = 'C';
344+
if (settingsController.GetWeatherFormat() == Controllers::Settings::WeatherFormat::Imperial) {
345+
temp = optCurrentWeather->temperature.Fahrenheit();
346+
tempUnit = 'F';
347+
}
348+
lv_label_set_text_fmt(temperature, "%d°%c", temp, tempUnit);
349+
lv_label_set_text(weatherIcon, Symbols::GetSymbol(optCurrentWeather->iconId));
350+
} else {
351+
lv_label_set_text_static(temperature, "");
352+
lv_label_set_text(weatherIcon, "");
353+
}
354+
}
355+
}
320356
}

src/displayapp/screens/WatchFaceAnalog.h

+9-2
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)