Skip to content

Commit d54ae36

Browse files
committed
WatchFaceAnalog: Add weather widget
1 parent 6c1f628 commit d54ae36

File tree

2 files changed

+51
-5
lines changed

2 files changed

+51
-5
lines changed

src/displayapp/screens/WatchFaceAnalog.cpp

+42-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,27 @@ 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;
343+
char tempUnit = 'C';
344+
if (settingsController.GetWeatherFormat() == Controllers::Settings::WeatherFormat::Imperial) {
345+
temp = Controllers::SimpleWeatherService::CelsiusToFahrenheit(temp);
346+
tempUnit = 'F';
347+
}
348+
temp = temp / 100 + (temp % 100 >= 50 ? 1 : 0);
349+
lv_label_set_text_fmt(temperature, "%d°%c", temp, tempUnit);
350+
lv_label_set_text(weatherIcon, Symbols::GetSymbol(optCurrentWeather->iconId));
351+
} else {
352+
lv_label_set_text_static(temperature, "");
353+
lv_label_set_text(weatherIcon, "");
354+
}
355+
lv_obj_realign(temperature);
356+
lv_obj_realign(weatherIcon);
357+
}
358+
}
320359
}

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;
@@ -51,6 +53,7 @@ namespace Pinetime {
5153
Utility::DirtyValue<bool> notificationState {false};
5254
using days = std::chrono::duration<int32_t, std::ratio<86400>>; // TODO: days is standard in c++20
5355
Utility::DirtyValue<std::chrono::time_point<std::chrono::system_clock, days>> currentDate;
56+
Utility::DirtyValue<std::optional<Pinetime::Controllers::SimpleWeatherService::CurrentWeather>> currentWeather {};
5457

5558
lv_obj_t* minor_scales;
5659
lv_obj_t* major_scales;
@@ -84,6 +87,8 @@ namespace Pinetime {
8487
lv_obj_t* heartbeatValue;
8588
lv_obj_t* stepIcon;
8689
lv_obj_t* stepValue;
90+
lv_obj_t* weatherIcon;
91+
lv_obj_t* temperature;
8792

8893
BatteryIcon batteryIcon;
8994

@@ -94,6 +99,7 @@ namespace Pinetime {
9499
Controllers::Settings& settingsController;
95100
Controllers::HeartRateController& heartRateController;
96101
Controllers::MotionController& motionController;
102+
Controllers::SimpleWeatherService& weatherService;
97103

98104
void UpdateClock();
99105
void SetBatteryIcon();
@@ -114,7 +120,8 @@ namespace Pinetime {
114120
controllers.notificationManager,
115121
controllers.settingsController,
116122
controllers.heartRateController,
117-
controllers.motionController);
123+
controllers.motionController,
124+
*controllers.weatherController);
118125
};
119126

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

0 commit comments

Comments
 (0)