Skip to content

Commit 701ef33

Browse files
committed
Add weather to the terminal watch face
1 parent 43d1126 commit 701ef33

File tree

2 files changed

+38
-5
lines changed

2 files changed

+38
-5
lines changed

src/displayapp/screens/WatchFaceTerminal.cpp

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
#include "components/heartrate/HeartRateController.h"
99
#include "components/motion/MotionController.h"
1010
#include "components/settings/Settings.h"
11+
#include "components/ble/SimpleWeatherService.h"
12+
#include "displayapp/screens/WeatherSymbols.h"
1113
#include "displayapp/InfiniTimeTheme.h"
1214

1315
using namespace Pinetime::Applications::Screens;
@@ -18,15 +20,17 @@ WatchFaceTerminal::WatchFaceTerminal(Controllers::DateTime& dateTimeController,
1820
Controllers::NotificationManager& notificationManager,
1921
Controllers::Settings& settingsController,
2022
Controllers::HeartRateController& heartRateController,
21-
Controllers::MotionController& motionController)
23+
Controllers::MotionController& motionController,
24+
Controllers::SimpleWeatherService& weatherService)
2225
: currentDateTime {{}},
2326
dateTimeController {dateTimeController},
2427
batteryController {batteryController},
2528
bleController {bleController},
2629
notificationManager {notificationManager},
2730
settingsController {settingsController},
2831
heartRateController {heartRateController},
29-
motionController {motionController} {
32+
motionController {motionController},
33+
weatherService {weatherService} {
3034

3135
container = lv_cont_create(lv_scr_act(), nullptr);
3236
lv_cont_set_layout(container, LV_LAYOUT_COLUMN_LEFT);
@@ -56,14 +60,17 @@ WatchFaceTerminal::WatchFaceTerminal(Controllers::DateTime& dateTimeController,
5660
heartbeatValue = lv_label_create(container, nullptr);
5761
lv_label_set_recolor(heartbeatValue, true);
5862

63+
weather = lv_label_create(container, nullptr);
64+
lv_label_set_recolor(weather, true);
65+
5966
connectState = lv_label_create(container, nullptr);
6067
lv_label_set_recolor(connectState, true);
6168

6269
label_prompt_2 = lv_label_create(container, nullptr);
6370
lv_obj_set_style_local_text_color(label_prompt_2, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, Colors::lightGray);
6471
lv_label_set_text_static(label_prompt_2, "user@watch:~ $");
6572

66-
lv_obj_align(container, nullptr, LV_ALIGN_IN_TOP_LEFT, 0, 20);
73+
lv_obj_align(container, nullptr, LV_ALIGN_IN_TOP_LEFT, 0, 10);
6774

6875
taskRefresh = lv_task_create(RefreshTaskCallback, LV_DISP_DEF_REFR_PERIOD, LV_TASK_PRIO_MID, this);
6976
Refresh();
@@ -147,6 +154,26 @@ void WatchFaceTerminal::Refresh() {
147154
}
148155
}
149156

157+
currentWeather = weatherService.Current();
158+
if (currentWeather.IsUpdated()) {
159+
auto optCurrentWeather = currentWeather.Get();
160+
if (optCurrentWeather) {
161+
int16_t temp = optCurrentWeather->temperature.Celsius();
162+
char tempUnit = 'C';
163+
if (settingsController.GetWeatherFormat() == Controllers::Settings::WeatherFormat::Imperial) {
164+
temp = optCurrentWeather->temperature.Fahrenheit();
165+
tempUnit = 'F';
166+
}
167+
lv_label_set_text_fmt(weather,
168+
"[WTHR]#ffdd00 %d°%c %s#",
169+
temp,
170+
tempUnit,
171+
Symbols::GetSimpleCondition(optCurrentWeather->iconId));
172+
} else {
173+
lv_label_set_text(weather, "[WTHR]#ffdd00 ---");
174+
}
175+
}
176+
150177
bleState = bleController.IsConnected();
151178
bleRadioEnabled = bleController.IsRadioEnabled();
152179
if (bleState.IsUpdated() || bleRadioEnabled.IsUpdated()) {

src/displayapp/screens/WatchFaceTerminal.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "displayapp/screens/Screen.h"
99
#include "components/datetime/DateTimeController.h"
1010
#include "utility/DirtyValue.h"
11+
#include "components/ble/SimpleWeatherService.h"
1112

1213
namespace Pinetime {
1314
namespace Controllers {
@@ -30,7 +31,8 @@ namespace Pinetime {
3031
Controllers::NotificationManager& notificationManager,
3132
Controllers::Settings& settingsController,
3233
Controllers::HeartRateController& heartRateController,
33-
Controllers::MotionController& motionController);
34+
Controllers::MotionController& motionController,
35+
Controllers::SimpleWeatherService& weatherService);
3436
~WatchFaceTerminal() override;
3537

3638
void Refresh() override;
@@ -46,6 +48,7 @@ namespace Pinetime {
4648
Utility::DirtyValue<bool> heartbeatRunning {};
4749
Utility::DirtyValue<bool> notificationState {};
4850
Utility::DirtyValue<std::chrono::time_point<std::chrono::system_clock, std::chrono::days>> currentDate;
51+
Utility::DirtyValue<std::optional<Controllers::SimpleWeatherService::CurrentWeather>> currentWeather {};
4952

5053
lv_obj_t* container;
5154
lv_obj_t* notificationIcon;
@@ -56,6 +59,7 @@ namespace Pinetime {
5659
lv_obj_t* stepValue;
5760
lv_obj_t* heartbeatValue;
5861
lv_obj_t* connectState;
62+
lv_obj_t* weather;
5963
lv_obj_t* label_prompt_2;
6064

6165
Controllers::DateTime& dateTimeController;
@@ -65,6 +69,7 @@ namespace Pinetime {
6569
Controllers::Settings& settingsController;
6670
Controllers::HeartRateController& heartRateController;
6771
Controllers::MotionController& motionController;
72+
Controllers::SimpleWeatherService& weatherService;
6873

6974
lv_task_t* taskRefresh;
7075
};
@@ -82,7 +87,8 @@ namespace Pinetime {
8287
controllers.notificationManager,
8388
controllers.settingsController,
8489
controllers.heartRateController,
85-
controllers.motionController);
90+
controllers.motionController,
91+
*controllers.weatherController);
8692
};
8793

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

0 commit comments

Comments
 (0)