Skip to content

Commit 1bdf756

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

File tree

2 files changed

+55
-5
lines changed

2 files changed

+55
-5
lines changed

src/displayapp/screens/WatchFaceTerminal.cpp

+47-3
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,42 @@
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+
namespace {
19+
lv_color_t TemperatureColor(Pinetime::Controllers::SimpleWeatherService::Temperature temp) {
20+
if (temp.Celsius() <= 0) { // freezing
21+
return Colors::blue;
22+
} else if (temp.Celsius() <= 4) { // ice
23+
return LV_COLOR_CYAN;
24+
} else if (temp.Celsius() >= 27) { // hot
25+
return Colors::deepOrange;
26+
}
27+
return Colors::orange; // normal
28+
}
29+
}
30+
1531
WatchFaceTerminal::WatchFaceTerminal(Controllers::DateTime& dateTimeController,
1632
const Controllers::Battery& batteryController,
1733
const Controllers::Ble& bleController,
1834
Controllers::NotificationManager& notificationManager,
1935
Controllers::Settings& settingsController,
2036
Controllers::HeartRateController& heartRateController,
21-
Controllers::MotionController& motionController)
37+
Controllers::MotionController& motionController,
38+
Controllers::SimpleWeatherService& weatherService)
2239
: currentDateTime {{}},
2340
dateTimeController {dateTimeController},
2441
batteryController {batteryController},
2542
bleController {bleController},
2643
notificationManager {notificationManager},
2744
settingsController {settingsController},
2845
heartRateController {heartRateController},
29-
motionController {motionController} {
46+
motionController {motionController},
47+
weatherService {weatherService} {
3048
batteryValue = lv_label_create(lv_scr_act(), nullptr);
3149
lv_label_set_recolor(batteryValue, true);
3250
lv_obj_align(batteryValue, lv_scr_act(), LV_ALIGN_IN_LEFT_MID, 0, -20);
@@ -47,7 +65,7 @@ WatchFaceTerminal::WatchFaceTerminal(Controllers::DateTime& dateTimeController,
4765
lv_label_set_text_static(label_prompt_1, "user@watch:~ $ now");
4866

4967
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);
68+
lv_obj_align(label_prompt_2, lv_scr_act(), LV_ALIGN_IN_LEFT_MID, 0, 80);
5169
lv_label_set_text_static(label_prompt_2, "user@watch:~ $");
5270

5371
label_time = lv_label_create(lv_scr_act(), nullptr);
@@ -62,6 +80,10 @@ WatchFaceTerminal::WatchFaceTerminal(Controllers::DateTime& dateTimeController,
6280
lv_label_set_recolor(stepValue, true);
6381
lv_obj_align(stepValue, lv_scr_act(), LV_ALIGN_IN_LEFT_MID, 0, 0);
6482

83+
weather = lv_label_create(lv_scr_act(), nullptr);
84+
lv_label_set_recolor(weather, true);
85+
lv_obj_align(weather, lv_scr_act(), LV_ALIGN_IN_LEFT_MID, 0, 60);
86+
6587
taskRefresh = lv_task_create(RefreshTaskCallback, LV_DISP_DEF_REFR_PERIOD, LV_TASK_PRIO_MID, this);
6688
Refresh();
6789
}
@@ -148,4 +170,26 @@ void WatchFaceTerminal::Refresh() {
148170
if (stepCount.IsUpdated()) {
149171
lv_label_set_text_fmt(stepValue, "[STEP]#ee3377 %lu steps#", stepCount.Get());
150172
}
173+
174+
currentWeather = weatherService.Current();
175+
if (currentWeather.IsUpdated()) {
176+
auto optCurrentWeather = currentWeather.Get();
177+
if (optCurrentWeather) {
178+
int16_t temp = optCurrentWeather->temperature.Celsius();
179+
char tempUnit = 'C';
180+
lv_obj_set_style_local_text_color(weather, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, TemperatureColor(optCurrentWeather->temperature));
181+
if (settingsController.GetWeatherFormat() == Controllers::Settings::WeatherFormat::Imperial) {
182+
temp = optCurrentWeather->temperature.Fahrenheit();
183+
tempUnit = 'F';
184+
}
185+
lv_label_set_text_fmt(weather,
186+
"#ffffff [WTHR]#%d°%c %s",
187+
temp,
188+
tempUnit,
189+
// Change to GetSimpleCondition with pull request #2134 (Add shorter/simpler weather condition options)
190+
Symbols::GetCondition(optCurrentWeather->iconId));
191+
} else {
192+
lv_label_set_text(weather, "#ffffff [WTHR]---°");
193+
}
194+
}
151195
}

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)