1 /**
2 * @file lv_demo_smartwatch_weather.c
3 * Weather screen layout & functions. Shows the current weather details as well as
4 * hourly and daily forecasts.
5 */
6
7 /*********************
8 * INCLUDES
9 *********************/
10 #include "lv_demo_smartwatch.h"
11 #if LV_USE_DEMO_SMARTWATCH
12
13 #include "lv_demo_smartwatch_private.h"
14 #include "lv_demo_smartwatch_weather.h"
15
16 /*********************
17 * DEFINES
18 *********************/
19
20 /**********************
21 * TYPEDEFS
22 **********************/
23
24 /**********************
25 * STATIC PROTOTYPES
26 **********************/
27 static void create_screen_weather(void);
28 static void weather_screen_event_cb(lv_event_t * e);
29
30 static void set_weather_icon(lv_obj_t * obj, uint8_t id, bool day);
31 static const lv_img_dsc_t * get_weather_icon(uint8_t id, bool day);
32 /**********************
33 * STATIC VARIABLES
34 **********************/
35 static lv_obj_t * weather_screen;
36 static lv_obj_t * weather_panel;
37 static lv_obj_t * weather_city;
38 static lv_obj_t * weather_current_icon;
39 static lv_obj_t * weather_current_temp;
40 static lv_obj_t * weather_update_time;
41 static lv_obj_t * weather_daily_panel;
42 static lv_obj_t * weather_hourly_panel;
43 static lv_obj_t * weather_forecast_daily;
44 static lv_obj_t * weather_forecast_hourly;
45 static lv_obj_t * info_daily;
46 static lv_obj_t * info_hourly;
47
48 static const lv_image_dsc_t * weather_day_icons[] = {
49 &img_weather_day_0,
50 &img_weather_day_1,
51 &img_weather_day_2,
52 &img_weather_day_3,
53 &img_weather_day_4,
54 &img_weather_day_5,
55 &img_weather_day_6,
56 &img_weather_day_7
57 };
58
59 static const lv_image_dsc_t * weather_night_icons[] = {
60 &img_weather_night_0,
61 &img_weather_night_1,
62 &img_weather_night_2,
63 &img_weather_night_3,
64 &img_weather_night_4,
65 &img_weather_night_5,
66 &img_weather_night_6,
67 &img_weather_night_7,
68 };
69
70 static const char * week_days[7] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
71
72 /**********************
73 * MACROS
74 **********************/
75
76 /**********************
77 * GLOBAL FUNCTIONS
78 **********************/
79
lv_demo_smartwatch_weather_create(void)80 void lv_demo_smartwatch_weather_create(void)
81 {
82 create_screen_weather();
83
84 /* add demo weather parameters */
85 lv_demo_smartwatch_set_weather(22, 0, true, 14, 24, "Nairobi");
86
87 lv_demo_smartwatch_weather_daily_clear();
88 for(int i = 0; i < 7; i++) {
89 lv_demo_smartwatch_weather_add_daily(i, 20 - 1, i);
90 }
91
92 lv_demo_smartwatch_weather_hourly_clear();
93 lv_demo_smartwatch_weather_add_hourly(0, 1, 0, 0, 0, 0, true);
94 for(int h = 0; h < 4; h++) {
95 lv_demo_smartwatch_weather_add_hourly(h * 6, h, 20 + h, 50 - h, 30 + h, h, false);
96 }
97 }
98
lv_demo_smartwatch_weather_load(lv_screen_load_anim_t anim_type,uint32_t time,uint32_t delay)99 void lv_demo_smartwatch_weather_load(lv_screen_load_anim_t anim_type, uint32_t time, uint32_t delay)
100 {
101 lv_screen_load_anim(weather_screen, anim_type, time, delay, false);
102 }
103
lv_demo_smartwatch_set_weather(int temp,uint8_t icon,bool day,int hour,int minute,const char * city)104 void lv_demo_smartwatch_set_weather(int temp, uint8_t icon, bool day, int hour, int minute, const char * city)
105 {
106 lv_label_set_text(weather_city, city);
107 lv_label_set_text_fmt(weather_update_time, "Updated at\n%02d:%02d", hour, minute);
108 lv_label_set_text_fmt(weather_current_temp, "%d°C", temp);
109
110 set_weather_icon(weather_current_icon, icon, day);
111
112 /* also update weather in the default watchface */
113 lv_demo_smartwatch_home_set_weather(temp, get_weather_icon(icon, day));
114 }
115
lv_demo_smartwatch_weather_daily_clear(void)116 void lv_demo_smartwatch_weather_daily_clear(void)
117 {
118 lv_obj_clean(weather_forecast_daily);
119 lv_obj_remove_flag(info_daily, LV_OBJ_FLAG_HIDDEN);
120 }
121
lv_demo_smartwatch_weather_hourly_clear(void)122 void lv_demo_smartwatch_weather_hourly_clear(void)
123 {
124 lv_obj_clean(weather_forecast_hourly);
125 lv_obj_remove_flag(info_hourly, LV_OBJ_FLAG_HIDDEN);
126 }
127
lv_demo_smartwatch_weather_add_daily(int day,int temp,int id)128 void lv_demo_smartwatch_weather_add_daily(int day, int temp, int id)
129 {
130 lv_obj_t * panel = lv_obj_create(weather_forecast_daily);
131 lv_obj_set_width(panel, lv_pct(85));
132 lv_obj_set_height(panel, 40);
133 lv_obj_set_align(panel, LV_ALIGN_CENTER);
134 lv_obj_set_flex_flow(panel, LV_FLEX_FLOW_ROW);
135 lv_obj_set_flex_align(panel, LV_FLEX_ALIGN_SPACE_AROUND, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER);
136 lv_obj_remove_flag(panel, LV_OBJ_FLAG_SCROLLABLE);
137 lv_obj_set_style_radius(panel, 0, LV_PART_MAIN | LV_STATE_DEFAULT);
138 lv_obj_set_style_bg_color(panel, lv_color_hex(0x000000), LV_PART_MAIN | LV_STATE_DEFAULT);
139 lv_obj_set_style_bg_opa(panel, 0, LV_PART_MAIN | LV_STATE_DEFAULT);
140 lv_obj_set_style_border_color(panel, lv_color_hex(0xFFFFFF), LV_PART_MAIN | LV_STATE_DEFAULT);
141 lv_obj_set_style_border_opa(panel, 255, LV_PART_MAIN | LV_STATE_DEFAULT);
142 lv_obj_set_style_border_width(panel, 1, LV_PART_MAIN | LV_STATE_DEFAULT);
143 lv_obj_set_style_border_side(panel, LV_BORDER_SIDE_BOTTOM, LV_PART_MAIN | LV_STATE_DEFAULT);
144 lv_obj_set_style_pad_left(panel, 5, LV_PART_MAIN | LV_STATE_DEFAULT);
145 lv_obj_set_style_pad_right(panel, 5, LV_PART_MAIN | LV_STATE_DEFAULT);
146 lv_obj_set_style_pad_top(panel, 0, LV_PART_MAIN | LV_STATE_DEFAULT);
147 lv_obj_set_style_pad_bottom(panel, 10, LV_PART_MAIN | LV_STATE_DEFAULT);
148
149 lv_obj_t * label_day = lv_label_create(panel);
150 lv_obj_set_width(label_day, 68);
151 lv_obj_set_height(label_day, LV_SIZE_CONTENT);
152 lv_obj_set_x(label_day, -56);
153 lv_obj_set_y(label_day, 3);
154 lv_obj_set_align(label_day, LV_ALIGN_CENTER);
155 lv_label_set_long_mode(label_day, LV_LABEL_LONG_CLIP);
156 lv_label_set_text(label_day, week_days[day % 7]);
157 lv_obj_set_style_text_font(label_day, &lv_font_montserrat_20, LV_PART_MAIN | LV_STATE_DEFAULT);
158
159 lv_obj_t * icon = lv_image_create(panel);
160 lv_obj_set_width(icon, LV_SIZE_CONTENT);
161 lv_obj_set_height(icon, LV_SIZE_CONTENT);
162 lv_obj_set_align(icon, LV_ALIGN_CENTER);
163 lv_obj_add_flag(icon, LV_OBJ_FLAG_ADV_HITTEST);
164 lv_obj_remove_flag(icon, LV_OBJ_FLAG_SCROLLABLE);
165 lv_image_set_scale(icon, 150);
166 set_weather_icon(icon, id, true);
167
168 lv_obj_t * label = lv_label_create(panel);
169 lv_obj_set_width(label, 58);
170 lv_obj_set_height(label, LV_SIZE_CONTENT);
171 lv_obj_set_x(label, 68);
172 lv_obj_set_y(label, 3);
173 lv_obj_set_align(label, LV_ALIGN_CENTER);
174 lv_label_set_long_mode(label, LV_LABEL_LONG_CLIP);
175 lv_label_set_text_fmt(label, "%d°C", temp);
176 lv_obj_set_style_text_font(label, &lv_font_montserrat_20, LV_PART_MAIN | LV_STATE_DEFAULT);
177
178 lv_obj_add_flag(info_daily, LV_OBJ_FLAG_HIDDEN);
179 }
180
lv_demo_smartwatch_weather_add_hourly(int hour,int id,int temp,int humidity,int wind,int uv,bool info)181 void lv_demo_smartwatch_weather_add_hourly(int hour, int id, int temp, int humidity, int wind, int uv, bool info)
182 {
183 lv_obj_t * panel = lv_obj_create(weather_forecast_hourly);
184 lv_obj_set_width(panel, 100);
185 lv_obj_set_height(panel, 184);
186 lv_obj_set_align(panel, LV_ALIGN_CENTER);
187 lv_obj_set_flex_flow(panel, LV_FLEX_FLOW_COLUMN);
188 lv_obj_set_flex_align(panel, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER);
189 lv_obj_remove_flag(panel, LV_OBJ_FLAG_SCROLLABLE);
190 lv_obj_set_style_bg_color(panel, lv_color_hex(0x000000), LV_PART_MAIN | LV_STATE_DEFAULT);
191 lv_obj_set_style_bg_opa(panel, 255, LV_PART_MAIN | LV_STATE_DEFAULT);
192 lv_obj_set_style_border_color(panel, lv_color_hex(0xFFFFFF), LV_PART_MAIN | LV_STATE_DEFAULT);
193 lv_obj_set_style_border_opa(panel, 255, LV_PART_MAIN | LV_STATE_DEFAULT);
194 lv_obj_set_style_border_width(panel, info ? 0 : 1, LV_PART_MAIN | LV_STATE_DEFAULT);
195
196 lv_obj_t * hour_label = lv_label_create(panel);
197 lv_obj_set_width(hour_label, 80);
198 lv_obj_set_height(hour_label, LV_SIZE_CONTENT);
199 lv_obj_set_align(hour_label, LV_ALIGN_CENTER);
200 lv_label_set_text_fmt(hour_label, info ? "Hour" : "%02d:00", hour);
201 lv_obj_set_style_text_align(hour_label, LV_TEXT_ALIGN_CENTER, LV_PART_MAIN | LV_STATE_DEFAULT);
202 lv_obj_set_style_text_font(hour_label, &lv_font_montserrat_16, LV_PART_MAIN | LV_STATE_DEFAULT);
203 lv_obj_set_style_border_color(hour_label, lv_color_hex(0xFFFFFF), LV_PART_MAIN | LV_STATE_DEFAULT);
204 lv_obj_set_style_border_opa(hour_label, 255, LV_PART_MAIN | LV_STATE_DEFAULT);
205 lv_obj_set_style_border_width(hour_label, 1, LV_PART_MAIN | LV_STATE_DEFAULT);
206 lv_obj_set_style_border_side(hour_label, LV_BORDER_SIDE_BOTTOM, LV_PART_MAIN | LV_STATE_DEFAULT);
207
208 lv_obj_t * hour_icon = lv_image_create(panel);
209 lv_obj_set_width(hour_icon, 40);
210 lv_obj_set_height(hour_icon, 40);
211 lv_obj_set_align(hour_icon, LV_ALIGN_CENTER);
212 lv_obj_add_flag(hour_icon, LV_OBJ_FLAG_CLICKABLE);
213 lv_obj_remove_flag(hour_icon, LV_OBJ_FLAG_SCROLLABLE);
214 lv_image_set_scale(hour_icon, 140);
215 set_weather_icon(hour_icon, id, true);
216
217 lv_obj_t * temp_label = lv_label_create(panel);
218 lv_obj_set_width(temp_label, LV_SIZE_CONTENT);
219 lv_obj_set_height(temp_label, LV_SIZE_CONTENT);
220 lv_obj_set_align(temp_label, LV_ALIGN_CENTER);
221 lv_label_set_text_fmt(temp_label, info ? "Temperature" : "%d°C", temp);
222 lv_obj_set_style_text_font(temp_label, &lv_font_montserrat_14, LV_PART_MAIN | LV_STATE_DEFAULT);
223
224 lv_obj_t * humidity_label = lv_label_create(panel);
225 lv_obj_set_width(humidity_label, LV_SIZE_CONTENT);
226 lv_obj_set_height(humidity_label, LV_SIZE_CONTENT);
227 lv_obj_set_align(humidity_label, LV_ALIGN_CENTER);
228 lv_label_set_text_fmt(humidity_label, info ? "Humidity" : "%d%%", humidity);
229 lv_obj_set_style_text_font(humidity_label, &lv_font_montserrat_14, LV_PART_MAIN | LV_STATE_DEFAULT);
230
231 lv_obj_t * wind_label = lv_label_create(panel);
232 lv_obj_set_width(wind_label, LV_SIZE_CONTENT);
233 lv_obj_set_height(wind_label, LV_SIZE_CONTENT);
234 lv_obj_set_align(wind_label, LV_ALIGN_CENTER);
235 lv_label_set_text_fmt(wind_label, info ? "Wind Speed" : "%d km/h", wind);
236 lv_obj_set_style_text_font(wind_label, &lv_font_montserrat_14, LV_PART_MAIN | LV_STATE_DEFAULT);
237
238 lv_obj_t * uv_label = lv_label_create(panel);
239 lv_obj_set_width(uv_label, LV_SIZE_CONTENT);
240 lv_obj_set_height(uv_label, LV_SIZE_CONTENT);
241 lv_obj_set_align(uv_label, LV_ALIGN_CENTER);
242 lv_label_set_text_fmt(uv_label, info ? "UV" : "%d", uv);
243 lv_obj_set_style_text_font(uv_label, &lv_font_montserrat_14, LV_PART_MAIN | LV_STATE_DEFAULT);
244
245 lv_obj_add_flag(info_hourly, LV_OBJ_FLAG_HIDDEN);
246 }
247
248 /**********************
249 * STATIC FUNCTIONS
250 **********************/
251
create_screen_weather(void)252 static void create_screen_weather(void)
253 {
254
255 weather_screen = lv_tileview_create(NULL);
256 lv_obj_set_scrollbar_mode(weather_screen, LV_SCROLLBAR_MODE_AUTO);
257 lv_obj_set_style_bg_color(weather_screen, lv_color_hex(0x000000), LV_PART_MAIN | LV_STATE_DEFAULT);
258 lv_obj_set_style_bg_opa(weather_screen, 255, LV_PART_MAIN | LV_STATE_DEFAULT);
259
260
261 weather_panel = lv_tileview_add_tile(weather_screen, 0, 0, LV_DIR_BOTTOM | LV_DIR_RIGHT);
262 lv_obj_set_width(weather_panel, lv_pct(100));
263 lv_obj_set_height(weather_panel, lv_pct(100));
264 lv_obj_set_align(weather_panel, LV_ALIGN_CENTER);
265 lv_obj_remove_flag(weather_panel, LV_OBJ_FLAG_SCROLLABLE);
266 lv_obj_set_style_radius(weather_panel, 0, LV_PART_MAIN | LV_STATE_DEFAULT);
267 lv_obj_set_style_bg_color(weather_panel, lv_color_hex(0xFFFFFF), LV_PART_MAIN | LV_STATE_DEFAULT);
268 lv_obj_set_style_bg_opa(weather_panel, 0, LV_PART_MAIN | LV_STATE_DEFAULT);
269 lv_obj_set_style_border_width(weather_panel, 0, LV_PART_MAIN | LV_STATE_DEFAULT);
270
271 weather_city = lv_label_create(weather_panel);
272 lv_obj_set_width(weather_city, LV_SIZE_CONTENT);
273 lv_obj_set_height(weather_city, LV_SIZE_CONTENT);
274 lv_obj_set_x(weather_city, -3);
275 lv_obj_set_y(weather_city, -85);
276 lv_obj_set_align(weather_city, LV_ALIGN_CENTER);
277 lv_label_set_text(weather_city, "");
278 lv_obj_set_style_text_font(weather_city, &lv_font_montserrat_20, LV_PART_MAIN | LV_STATE_DEFAULT);
279
280 weather_current_icon = lv_image_create(weather_panel);
281 lv_image_set_src(weather_current_icon, &img_weather_day_0);
282 lv_obj_set_width(weather_current_icon, LV_SIZE_CONTENT);
283 lv_obj_set_height(weather_current_icon, LV_SIZE_CONTENT);
284 lv_obj_set_x(weather_current_icon, 0);
285 lv_obj_set_y(weather_current_icon, -29);
286 lv_obj_set_align(weather_current_icon, LV_ALIGN_CENTER);
287 lv_obj_add_flag(weather_current_icon, LV_OBJ_FLAG_ADV_HITTEST);
288 lv_obj_remove_flag(weather_current_icon, LV_OBJ_FLAG_SCROLLABLE);
289 lv_image_set_scale(weather_current_icon, 400);
290
291 weather_current_temp = lv_label_create(weather_panel);
292 lv_obj_set_width(weather_current_temp, LV_SIZE_CONTENT);
293 lv_obj_set_height(weather_current_temp, LV_SIZE_CONTENT);
294 lv_obj_set_x(weather_current_temp, 0);
295 lv_obj_set_y(weather_current_temp, 44);
296 lv_obj_set_align(weather_current_temp, LV_ALIGN_CENTER);
297 lv_label_set_text(weather_current_temp, "--°C");
298 lv_obj_set_style_text_font(weather_current_temp, &lv_font_montserrat_46, LV_PART_MAIN | LV_STATE_DEFAULT);
299
300 weather_update_time = lv_label_create(weather_panel);
301 lv_obj_set_width(weather_update_time, LV_SIZE_CONTENT);
302 lv_obj_set_height(weather_update_time, LV_SIZE_CONTENT);
303 lv_obj_set_x(weather_update_time, 0);
304 lv_obj_set_y(weather_update_time, 97);
305 lv_obj_set_align(weather_update_time, LV_ALIGN_CENTER);
306 lv_label_set_text(weather_update_time, "unavailable\n--:--");
307 lv_obj_set_style_text_align(weather_update_time, LV_TEXT_ALIGN_CENTER, LV_PART_MAIN | LV_STATE_DEFAULT);
308
309 weather_daily_panel = lv_tileview_add_tile(weather_screen, 1, 0, LV_DIR_LEFT);
310 lv_obj_set_width(weather_daily_panel, lv_pct(100));
311 lv_obj_set_height(weather_daily_panel, lv_pct(100));
312
313 weather_forecast_daily = lv_obj_create(weather_daily_panel);
314 lv_obj_set_width(weather_forecast_daily, lv_pct(100));
315 lv_obj_set_height(weather_forecast_daily, lv_pct(100));
316 lv_obj_set_align(weather_forecast_daily, LV_ALIGN_TOP_MID);
317 lv_obj_set_flex_flow(weather_forecast_daily, LV_FLEX_FLOW_COLUMN);
318 lv_obj_set_flex_align(weather_forecast_daily, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER);
319 lv_obj_set_scrollbar_mode(weather_forecast_daily, LV_SCROLLBAR_MODE_OFF);
320 lv_obj_set_scroll_dir(weather_forecast_daily, LV_DIR_VER);
321 lv_obj_set_style_radius(weather_forecast_daily, 0, LV_PART_MAIN | LV_STATE_DEFAULT);
322 lv_obj_set_style_bg_color(weather_forecast_daily, lv_color_hex(0x000000), LV_PART_MAIN | LV_STATE_DEFAULT);
323 lv_obj_set_style_bg_opa(weather_forecast_daily, 0, LV_PART_MAIN | LV_STATE_DEFAULT);
324 lv_obj_set_style_border_width(weather_forecast_daily, 0, LV_PART_MAIN | LV_STATE_DEFAULT);
325 lv_obj_set_style_pad_left(weather_forecast_daily, 0, LV_PART_MAIN | LV_STATE_DEFAULT);
326 lv_obj_set_style_pad_right(weather_forecast_daily, 0, LV_PART_MAIN | LV_STATE_DEFAULT);
327 lv_obj_set_style_pad_top(weather_forecast_daily, 50, LV_PART_MAIN | LV_STATE_DEFAULT);
328 lv_obj_set_style_pad_bottom(weather_forecast_daily, 100, LV_PART_MAIN | LV_STATE_DEFAULT);
329
330 info_daily = lv_label_create(weather_daily_panel);
331 lv_obj_set_width(info_daily, 180);
332 lv_obj_set_height(info_daily, LV_SIZE_CONTENT);
333 lv_obj_set_align(info_daily, LV_ALIGN_CENTER);
334 lv_label_set_text(info_daily,
335 "Weather information has not yet been synced. Connect the device to Chronos app to get weather info. Make sure to enable it in the app settings.");
336
337 weather_hourly_panel = lv_tileview_add_tile(weather_screen, 0, 1, LV_DIR_TOP);
338 lv_obj_set_width(weather_hourly_panel, lv_pct(100));
339 lv_obj_set_height(weather_hourly_panel, lv_pct(100));
340
341 weather_forecast_hourly = lv_obj_create(weather_hourly_panel);
342 lv_obj_set_width(weather_forecast_hourly, lv_pct(100));
343 lv_obj_set_height(weather_forecast_hourly, lv_pct(100));
344 lv_obj_set_align(weather_forecast_hourly, LV_ALIGN_CENTER);
345 lv_obj_set_flex_flow(weather_forecast_hourly, LV_FLEX_FLOW_ROW);
346 lv_obj_set_flex_align(weather_forecast_hourly, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_CENTER);
347 lv_obj_set_scrollbar_mode(weather_forecast_hourly, LV_SCROLLBAR_MODE_OFF);
348 lv_obj_set_scroll_dir(weather_forecast_hourly, LV_DIR_HOR);
349 lv_obj_set_style_radius(weather_forecast_hourly, 0, LV_PART_MAIN | LV_STATE_DEFAULT);
350 lv_obj_set_style_bg_color(weather_forecast_hourly, lv_color_hex(0x000000), LV_PART_MAIN | LV_STATE_DEFAULT);
351 lv_obj_set_style_bg_opa(weather_forecast_hourly, 255, LV_PART_MAIN | LV_STATE_DEFAULT);
352 lv_obj_set_style_border_width(weather_forecast_hourly, 0, LV_PART_MAIN | LV_STATE_DEFAULT);
353 lv_obj_set_style_pad_left(weather_forecast_hourly, 50, LV_PART_MAIN | LV_STATE_DEFAULT);
354 lv_obj_set_style_pad_right(weather_forecast_hourly, 100, LV_PART_MAIN | LV_STATE_DEFAULT);
355 lv_obj_set_style_pad_top(weather_forecast_hourly, 0, LV_PART_MAIN | LV_STATE_DEFAULT);
356 lv_obj_set_style_pad_bottom(weather_forecast_hourly, 0, LV_PART_MAIN | LV_STATE_DEFAULT);
357 lv_obj_set_style_pad_column(weather_forecast_hourly, 10, LV_PART_MAIN | LV_STATE_DEFAULT);
358
359 info_hourly = lv_label_create(weather_hourly_panel);
360 lv_obj_set_width(info_hourly, 180);
361 lv_obj_set_height(info_hourly, LV_SIZE_CONTENT);
362 lv_obj_set_align(info_hourly, LV_ALIGN_CENTER);
363 lv_label_set_text(info_hourly,
364 "Weather information has not yet been synced. Connect the device to Chronos app to get weather info. Make sure to enable it in the app settings.");
365
366 lv_obj_add_event_cb(weather_forecast_daily, lv_demo_smartwatch_scroll_event, LV_EVENT_ALL, NULL);
367 lv_obj_add_event_cb(weather_screen, weather_screen_event_cb, LV_EVENT_ALL, NULL);
368 }
369
weather_screen_event_cb(lv_event_t * e)370 static void weather_screen_event_cb(lv_event_t * e)
371 {
372
373 lv_event_code_t event_code = lv_event_get_code(e);
374
375 if(event_code == LV_EVENT_SCREEN_LOAD_START) {
376
377 lv_obj_scroll_by(weather_forecast_daily, 0, 1, LV_ANIM_OFF);
378 lv_obj_scroll_by(weather_forecast_daily, 0, -1, LV_ANIM_OFF);
379
380
381 lv_obj_set_scrollbar_mode(weather_screen, lv_demo_smartwatch_get_scrollbar_mode());
382 lv_obj_set_scrollbar_mode(weather_forecast_daily, lv_demo_smartwatch_get_scrollbar_mode());
383 lv_obj_set_scrollbar_mode(weather_forecast_hourly, lv_demo_smartwatch_get_scrollbar_mode());
384
385 lv_tileview_set_tile_by_index(weather_screen, 0, 0, LV_ANIM_OFF);
386
387 if(lv_demo_smartwatch_get_load_app_list()) {
388 lv_demo_smartwatch_show_scroll_hint(LV_DIR_LEFT | LV_DIR_BOTTOM | LV_DIR_RIGHT);
389 }
390 else {
391 lv_demo_smartwatch_show_scroll_hint(LV_DIR_TOP | LV_DIR_BOTTOM | LV_DIR_RIGHT);
392 }
393
394 }
395
396 if(event_code == LV_EVENT_VALUE_CHANGED) {
397 if(lv_tileview_get_tile_active(weather_screen) == weather_panel) {
398 if(lv_demo_smartwatch_get_load_app_list()) {
399 lv_demo_smartwatch_show_scroll_hint(LV_DIR_LEFT | LV_DIR_BOTTOM | LV_DIR_RIGHT);
400 }
401 else {
402 lv_demo_smartwatch_show_scroll_hint(LV_DIR_TOP | LV_DIR_BOTTOM | LV_DIR_RIGHT);
403 }
404 }
405 else if(lv_tileview_get_tile_active(weather_screen) == weather_daily_panel) {
406 lv_demo_smartwatch_show_scroll_hint(LV_DIR_LEFT);
407 }
408 else if(lv_tileview_get_tile_active(weather_screen) == weather_hourly_panel) {
409 lv_demo_smartwatch_show_scroll_hint(LV_DIR_TOP);
410 }
411
412 }
413
414
415 if(lv_tileview_get_tile_active(weather_screen) == weather_panel) {
416 if(event_code == LV_EVENT_GESTURE && lv_indev_get_gesture_dir(lv_indev_active()) == LV_DIR_BOTTOM) {
417
418 if(!lv_demo_smartwatch_get_load_app_list()) {
419 lv_demo_smartwatch_home_load(LV_SCR_LOAD_ANIM_MOVE_BOTTOM, 500, 0);
420 }
421 else {
422 LV_LOG_WARN("Swipe right to exit");
423 lv_demo_smartwatch_show_scroll_hint(LV_DIR_LEFT | LV_DIR_BOTTOM | LV_DIR_RIGHT);
424 }
425 }
426 if(event_code == LV_EVENT_GESTURE && lv_indev_get_gesture_dir(lv_indev_active()) == LV_DIR_RIGHT) {
427 if(lv_demo_smartwatch_get_load_app_list()) {
428 lv_demo_smartwatch_list_load(LV_SCR_LOAD_ANIM_MOVE_RIGHT, 500, 0);
429 }
430 else {
431 LV_LOG_WARN("Swipe down to exit");
432 lv_demo_smartwatch_show_scroll_hint(LV_DIR_TOP | LV_DIR_BOTTOM | LV_DIR_RIGHT);
433 }
434 }
435 }
436
437 if(lv_tileview_get_tile_active(weather_screen) == weather_daily_panel) {
438 if(event_code == LV_EVENT_GESTURE && lv_indev_get_gesture_dir(lv_indev_active()) != LV_DIR_RIGHT) {
439 lv_demo_smartwatch_show_scroll_hint(LV_DIR_LEFT);
440 }
441 }
442
443 if(lv_tileview_get_tile_active(weather_screen) == weather_hourly_panel) {
444 if(event_code == LV_EVENT_GESTURE && lv_indev_get_gesture_dir(lv_indev_active()) != LV_DIR_BOTTOM) {
445 lv_demo_smartwatch_show_scroll_hint(LV_DIR_TOP);
446 }
447 }
448
449
450 }
451
set_weather_icon(lv_obj_t * obj,uint8_t id,bool day)452 static void set_weather_icon(lv_obj_t * obj, uint8_t id, bool day)
453 {
454 lv_image_set_src(obj, day ? weather_day_icons[id % 8] : weather_night_icons[id % 8]);
455 }
456
get_weather_icon(uint8_t id,bool day)457 static const lv_img_dsc_t * get_weather_icon(uint8_t id, bool day)
458 {
459 return day ? weather_day_icons[id % 8] : weather_night_icons[id % 8];
460 }
461
462 #endif /*LV_USE_DEMO_SMARTWATCH*/
463