Skip to content

Commit 232e496

Browse files
committed
Add weather to the terminal watchface
1 parent 7b39d81 commit 232e496

File tree

2 files changed

+41
-5
lines changed

2 files changed

+41
-5
lines changed

src/displayapp/screens/WatchFaceTerminal.cpp

+33-3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
#include "components/heartrate/HeartRateController.h"
1010
#include "components/motion/MotionController.h"
1111
#include "components/settings/Settings.h"
12+
#include "components/ble/SimpleWeatherService.h"
13+
#include "displayapp/screens/WeatherSymbols.h"
14+
#include "displayapp/InfiniTimeTheme.h"
1215

1316
using namespace Pinetime::Applications::Screens;
1417

@@ -18,15 +21,17 @@ WatchFaceTerminal::WatchFaceTerminal(Controllers::DateTime& dateTimeController,
1821
Controllers::NotificationManager& notificationManager,
1922
Controllers::Settings& settingsController,
2023
Controllers::HeartRateController& heartRateController,
21-
Controllers::MotionController& motionController)
24+
Controllers::MotionController& motionController,
25+
Controllers::SimpleWeatherService& weatherService)
2226
: currentDateTime {{}},
2327
dateTimeController {dateTimeController},
2428
batteryController {batteryController},
2529
bleController {bleController},
2630
notificationManager {notificationManager},
2731
settingsController {settingsController},
2832
heartRateController {heartRateController},
29-
motionController {motionController} {
33+
motionController {motionController},
34+
weatherService {weatherService} {
3035
batteryValue = lv_label_create(lv_scr_act(), nullptr);
3136
lv_label_set_recolor(batteryValue, true);
3237
lv_obj_align(batteryValue, lv_scr_act(), LV_ALIGN_IN_LEFT_MID, 0, -20);
@@ -47,7 +52,7 @@ WatchFaceTerminal::WatchFaceTerminal(Controllers::DateTime& dateTimeController,
4752
lv_label_set_text_static(label_prompt_1, "user@watch:~ $ now");
4853

4954
label_prompt_2 = lv_label_create(lv_scr_act(), nullptr);
50-
lv_obj_align(label_prompt_2, lv_scr_act(), LV_ALIGN_IN_LEFT_MID, 0, 60);
55+
lv_obj_align(label_prompt_2, lv_scr_act(), LV_ALIGN_IN_LEFT_MID, 0, 80);
5156
lv_label_set_text_static(label_prompt_2, "user@watch:~ $");
5257

5358
label_time = lv_label_create(lv_scr_act(), nullptr);
@@ -62,6 +67,10 @@ WatchFaceTerminal::WatchFaceTerminal(Controllers::DateTime& dateTimeController,
6267
lv_label_set_recolor(stepValue, true);
6368
lv_obj_align(stepValue, lv_scr_act(), LV_ALIGN_IN_LEFT_MID, 0, 0);
6469

70+
weather = lv_label_create(lv_scr_act(), nullptr);
71+
lv_label_set_recolor(weather, true);
72+
lv_obj_align(weather, lv_scr_act(), LV_ALIGN_IN_LEFT_MID, 0, 60);
73+
6574
taskRefresh = lv_task_create(RefreshTaskCallback, LV_DISP_DEF_REFR_PERIOD, LV_TASK_PRIO_MID, this);
6675
Refresh();
6776
}
@@ -148,4 +157,25 @@ void WatchFaceTerminal::Refresh() {
148157
if (stepCount.IsUpdated()) {
149158
lv_label_set_text_fmt(stepValue, "[STEP]#ee3377 %lu steps#", stepCount.Get());
150159
}
160+
161+
currentWeather = weatherService.Current();
162+
if (currentWeather.IsUpdated()) {
163+
auto optCurrentWeather = currentWeather.Get();
164+
if (optCurrentWeather) {
165+
int16_t temp = optCurrentWeather->temperature.Celsius();
166+
char tempUnit = 'C';
167+
if (settingsController.GetWeatherFormat() == Controllers::Settings::WeatherFormat::Imperial) {
168+
temp = optCurrentWeather->temperature.Fahrenheit();
169+
tempUnit = 'F';
170+
}
171+
lv_label_set_text_fmt(weather,
172+
"[WTHR]#ffdd00 %d°%c %s#",
173+
temp,
174+
tempUnit,
175+
// Change to GetSimpleCondition with pull request #2134 (Add shorter/simpler weather condition options)
176+
Symbols::GetCondition(optCurrentWeather->iconId));
177+
} else {
178+
lv_label_set_text(weather, "[WTHR]#ffdd00 ---°");
179+
}
180+
}
151181
}

src/displayapp/screens/WatchFaceTerminal.h

+8-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <displayapp/Controllers.h>
88
#include "displayapp/screens/Screen.h"
99
#include "components/datetime/DateTimeController.h"
10+
#include "components/ble/SimpleWeatherService.h"
1011
#include "utility/DirtyValue.h"
1112

1213
namespace Pinetime {
@@ -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* label_time;
5154
lv_obj_t* label_date;
@@ -56,6 +59,7 @@ namespace Pinetime {
5659
lv_obj_t* stepValue;
5760
lv_obj_t* notificationIcon;
5861
lv_obj_t* connectState;
62+
lv_obj_t* weather;
5963

6064
Controllers::DateTime& dateTimeController;
6165
const Controllers::Battery& batteryController;
@@ -64,6 +68,7 @@ namespace Pinetime {
6468
Controllers::Settings& settingsController;
6569
Controllers::HeartRateController& heartRateController;
6670
Controllers::MotionController& motionController;
71+
Controllers::SimpleWeatherService& weatherService;
6772

6873
lv_task_t* taskRefresh;
6974
};
@@ -81,7 +86,8 @@ namespace Pinetime {
8186
controllers.notificationManager,
8287
controllers.settingsController,
8388
controllers.heartRateController,
84-
controllers.motionController);
89+
controllers.motionController,
90+
*controllers.weatherController);
8591
};
8692

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

0 commit comments

Comments
 (0)