Skip to content

Commit 2135e12

Browse files
authored
WatchFaceDigital: Add weather display
If weather is available, display the cloud icon and temperature.
1 parent a6cd367 commit 2135e12

File tree

2 files changed

+48
-3
lines changed

2 files changed

+48
-3
lines changed

src/displayapp/screens/WatchFaceDigital.cpp

+38-1
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@
44
#include <cstdio>
55
#include "displayapp/screens/NotificationIcon.h"
66
#include "displayapp/screens/Symbols.h"
7+
#include "displayapp/screens/WeatherSymbols.h"
78
#include "components/battery/BatteryController.h"
89
#include "components/ble/BleController.h"
910
#include "components/ble/NotificationManager.h"
1011
#include "components/heartrate/HeartRateController.h"
1112
#include "components/motion/MotionController.h"
13+
#include "components/ble/SimpleWeatherService.h"
1214
#include "components/settings/Settings.h"
1315

1416
using namespace Pinetime::Applications::Screens;
@@ -19,13 +21,15 @@ WatchFaceDigital::WatchFaceDigital(Controllers::DateTime& dateTimeController,
1921
Controllers::NotificationManager& notificationManager,
2022
Controllers::Settings& settingsController,
2123
Controllers::HeartRateController& heartRateController,
22-
Controllers::MotionController& motionController)
24+
Controllers::MotionController& motionController,
25+
Controllers::SimpleWeatherService& weatherService)
2326
: currentDateTime {{}},
2427
dateTimeController {dateTimeController},
2528
notificationManager {notificationManager},
2629
settingsController {settingsController},
2730
heartRateController {heartRateController},
2831
motionController {motionController},
32+
weatherService {weatherService},
2933
statusIcons(batteryController, bleController) {
3034

3135
statusIcons.Create();
@@ -35,6 +39,18 @@ WatchFaceDigital::WatchFaceDigital(Controllers::DateTime& dateTimeController,
3539
lv_label_set_text_static(notificationIcon, NotificationIcon::GetIcon(false));
3640
lv_obj_align(notificationIcon, nullptr, LV_ALIGN_IN_TOP_LEFT, 0, 0);
3741

42+
weatherIcon = lv_label_create(lv_scr_act(), nullptr);
43+
lv_obj_set_style_local_text_color(weatherIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_WHITE);
44+
lv_obj_set_style_local_text_font(weatherIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &fontawesome_weathericons);
45+
lv_label_set_text(weatherIcon, "");
46+
lv_obj_align(weatherIcon, nullptr, LV_ALIGN_IN_TOP_MID, -20, 0);
47+
lv_obj_set_auto_realign(weatherIcon, true);
48+
49+
temperature = lv_label_create(lv_scr_act(), nullptr);
50+
lv_obj_set_style_local_text_color(temperature, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_WHITE);
51+
lv_label_set_text(temperature, "");
52+
lv_obj_align(temperature, nullptr, LV_ALIGN_IN_TOP_MID, 20, 0);
53+
3854
label_date = lv_label_create(lv_scr_act(), nullptr);
3955
lv_obj_align(label_date, lv_scr_act(), LV_ALIGN_CENTER, 0, 60);
4056
lv_obj_set_style_local_text_color(label_date, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x999999));
@@ -153,4 +169,25 @@ void WatchFaceDigital::Refresh() {
153169
lv_obj_realign(stepValue);
154170
lv_obj_realign(stepIcon);
155171
}
172+
173+
currentWeather = weatherService.Current();
174+
if (currentWeather.IsUpdated()) {
175+
auto optCurrentWeather = currentWeather.Get();
176+
if (optCurrentWeather) {
177+
int16_t temp = optCurrentWeather->temperature;
178+
char tempUnit = 'C';
179+
if (settingsController.GetWeatherFormat() == Controllers::Settings::WeatherFormat::Imperial) {
180+
temp = Controllers::SimpleWeatherService::CelsiusToFahrenheit(temp);
181+
tempUnit = 'F';
182+
}
183+
temp = temp / 100 + (temp % 100 >= 50 ? 1 : 0);
184+
lv_label_set_text_fmt(temperature, "%d°%c", temp, tempUnit);
185+
lv_label_set_text(weatherIcon, Symbols::GetSymbol(optCurrentWeather->iconId));
186+
} else {
187+
lv_label_set_text_static(temperature, "");
188+
lv_label_set_text(weatherIcon, "");
189+
}
190+
lv_obj_realign(temperature);
191+
lv_obj_realign(weatherIcon);
192+
}
156193
}

src/displayapp/screens/WatchFaceDigital.h

+10-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <memory>
77
#include "displayapp/screens/Screen.h"
88
#include "components/datetime/DateTimeController.h"
9+
#include "components/ble/SimpleWeatherService.h"
910
#include "components/ble/BleController.h"
1011
#include "displayapp/widgets/StatusIcons.h"
1112
#include "utility/DirtyValue.h"
@@ -32,7 +33,8 @@ namespace Pinetime {
3233
Controllers::NotificationManager& notificationManager,
3334
Controllers::Settings& settingsController,
3435
Controllers::HeartRateController& heartRateController,
35-
Controllers::MotionController& motionController);
36+
Controllers::MotionController& motionController,
37+
Controllers::SimpleWeatherService& weather);
3638
~WatchFaceDigital() override;
3739

3840
void Refresh() override;
@@ -50,6 +52,8 @@ namespace Pinetime {
5052
Utility::DirtyValue<uint8_t> heartbeat {};
5153
Utility::DirtyValue<bool> heartbeatRunning {};
5254
Utility::DirtyValue<bool> notificationState {};
55+
Utility::DirtyValue<std::optional<Pinetime::Controllers::SimpleWeatherService::CurrentWeather>> currentWeather {};
56+
5357
using days = std::chrono::duration<int32_t, std::ratio<86400>>; // TODO: days is standard in c++20
5458
Utility::DirtyValue<std::chrono::time_point<std::chrono::system_clock, days>> currentDate;
5559

@@ -61,12 +65,15 @@ namespace Pinetime {
6165
lv_obj_t* stepIcon;
6266
lv_obj_t* stepValue;
6367
lv_obj_t* notificationIcon;
68+
lv_obj_t* weatherIcon;
69+
lv_obj_t* temperature;
6470

6571
Controllers::DateTime& dateTimeController;
6672
Controllers::NotificationManager& notificationManager;
6773
Controllers::Settings& settingsController;
6874
Controllers::HeartRateController& heartRateController;
6975
Controllers::MotionController& motionController;
76+
Controllers::SimpleWeatherService& weatherService;
7077

7178
lv_task_t* taskRefresh;
7279
Widgets::StatusIcons statusIcons;
@@ -85,7 +92,8 @@ namespace Pinetime {
8592
controllers.notificationManager,
8693
controllers.settingsController,
8794
controllers.heartRateController,
88-
controllers.motionController);
95+
controllers.motionController,
96+
*controllers.weatherController);
8997
};
9098

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

0 commit comments

Comments
 (0)