Skip to content

Commit 5bd8fbd

Browse files
committed
Add weather to the terminal watchface
1 parent d69cfcf commit 5bd8fbd

File tree

2 files changed

+42
-5
lines changed

2 files changed

+42
-5
lines changed

src/displayapp/screens/WatchFaceTerminal.cpp

+34-3
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,30 @@
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+
1519
WatchFaceTerminal::WatchFaceTerminal(Controllers::DateTime& dateTimeController,
1620
const Controllers::Battery& batteryController,
1721
const Controllers::Ble& bleController,
1822
Controllers::NotificationManager& notificationManager,
1923
Controllers::Settings& settingsController,
2024
Controllers::HeartRateController& heartRateController,
21-
Controllers::MotionController& motionController)
25+
Controllers::MotionController& motionController,
26+
Controllers::SimpleWeatherService& weatherService)
2227
: currentDateTime {{}},
2328
dateTimeController {dateTimeController},
2429
batteryController {batteryController},
2530
bleController {bleController},
2631
notificationManager {notificationManager},
2732
settingsController {settingsController},
2833
heartRateController {heartRateController},
29-
motionController {motionController} {
34+
motionController {motionController},
35+
weatherService {weatherService} {
3036
batteryValue = lv_label_create(lv_scr_act(), nullptr);
3137
lv_label_set_recolor(batteryValue, true);
3238
lv_obj_align(batteryValue, lv_scr_act(), LV_ALIGN_IN_LEFT_MID, 0, -20);
@@ -47,7 +53,7 @@ WatchFaceTerminal::WatchFaceTerminal(Controllers::DateTime& dateTimeController,
4753
lv_label_set_text_static(label_prompt_1, "user@watch:~ $ now");
4854

4955
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);
56+
lv_obj_align(label_prompt_2, lv_scr_act(), LV_ALIGN_IN_LEFT_MID, 0, 80);
5157
lv_label_set_text_static(label_prompt_2, "user@watch:~ $");
5258

5359
label_time = lv_label_create(lv_scr_act(), nullptr);
@@ -62,6 +68,10 @@ WatchFaceTerminal::WatchFaceTerminal(Controllers::DateTime& dateTimeController,
6268
lv_label_set_recolor(stepValue, true);
6369
lv_obj_align(stepValue, lv_scr_act(), LV_ALIGN_IN_LEFT_MID, 0, 0);
6470

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

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)