9
9
#include " components/heartrate/HeartRateController.h"
10
10
#include " components/motion/MotionController.h"
11
11
#include " components/settings/Settings.h"
12
+ #include " components/ble/SimpleWeatherService.h"
13
+ #include " displayapp/screens/WeatherSymbols.h"
14
+ #include " displayapp/InfiniTimeTheme.h"
12
15
13
16
using namespace Pinetime ::Applications::Screens;
14
17
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
+
15
31
WatchFaceTerminal::WatchFaceTerminal (Controllers::DateTime& dateTimeController,
16
32
const Controllers::Battery& batteryController,
17
33
const Controllers::Ble& bleController,
18
34
Controllers::NotificationManager& notificationManager,
19
35
Controllers::Settings& settingsController,
20
36
Controllers::HeartRateController& heartRateController,
21
- Controllers::MotionController& motionController)
37
+ Controllers::MotionController& motionController,
38
+ Controllers::SimpleWeatherService& weatherService)
22
39
: currentDateTime {{}},
23
40
dateTimeController {dateTimeController},
24
41
batteryController {batteryController},
25
42
bleController {bleController},
26
43
notificationManager {notificationManager},
27
44
settingsController {settingsController},
28
45
heartRateController {heartRateController},
29
- motionController {motionController} {
46
+ motionController {motionController},
47
+ weatherService {weatherService} {
30
48
batteryValue = lv_label_create (lv_scr_act (), nullptr );
31
49
lv_label_set_recolor (batteryValue, true );
32
50
lv_obj_align (batteryValue, lv_scr_act (), LV_ALIGN_IN_LEFT_MID, 0 , -20 );
@@ -47,7 +65,7 @@ WatchFaceTerminal::WatchFaceTerminal(Controllers::DateTime& dateTimeController,
47
65
lv_label_set_text_static (label_prompt_1, " user@watch:~ $ now" );
48
66
49
67
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 );
51
69
lv_label_set_text_static (label_prompt_2, " user@watch:~ $" );
52
70
53
71
label_time = lv_label_create (lv_scr_act (), nullptr );
@@ -62,6 +80,10 @@ WatchFaceTerminal::WatchFaceTerminal(Controllers::DateTime& dateTimeController,
62
80
lv_label_set_recolor (stepValue, true );
63
81
lv_obj_align (stepValue, lv_scr_act (), LV_ALIGN_IN_LEFT_MID, 0 , 0 );
64
82
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
+
65
87
taskRefresh = lv_task_create (RefreshTaskCallback, LV_DISP_DEF_REFR_PERIOD, LV_TASK_PRIO_MID, this );
66
88
Refresh ();
67
89
}
@@ -148,4 +170,26 @@ void WatchFaceTerminal::Refresh() {
148
170
if (stepCount.IsUpdated ()) {
149
171
lv_label_set_text_fmt (stepValue, " [STEP]#ee3377 %lu steps#" , stepCount.Get ());
150
172
}
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
+ }
151
195
}
0 commit comments