-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp_main_page.c
688 lines (586 loc) · 20.7 KB
/
app_main_page.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
/**
* Copyright (c) 2020 Rockchip Electronics Co., Ltd
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <rtthread.h>
#include <stdio.h>
#include <math.h>
#include <dfs_posix.h>
#include "drv_heap.h"
#include "drv_display.h"
#include "hal_base.h"
#include "image_info.h"
#include "display.h"
#if defined(RT_USING_TOUCH_DRIVERS)
#include "touch.h"
#include "touchpanel.h"
#endif
#include "app_main.h"
#include "lib_imageprocess.h"
#ifdef RT_USING_FWANALYSIS
#include "rkpart.h"
#endif
/*
**************************************************************************************************
*
* Macro define
*
**************************************************************************************************
*/
/*
**************************************************************************************************
*
* Declaration
*
**************************************************************************************************
*/
void app_main_page_clock_update(void);
void app_main_page_weather_update(void);
void app_main_page_music_update(void);
/*
**************************************************************************************************
*
* Global static struct & data define
*
**************************************************************************************************
*/
struct app_page_data_t *app_main_page = RT_NULL;
app_disp_refrsh_param_t main_page_refrsh_param;
app_main_page_timer_cb_t main_page_timer_cb[CLOCK_HOR_PAGE_MAX] =
{
{RT_NULL, 0},
{app_main_page_clock_update, 1000},
{app_main_page_weather_update, 100},
{app_main_page_music_update, 300},
};
app_main_page_timer_cb_t main_page_leave[CLOCK_HOR_PAGE_MAX] =
{
{RT_NULL, 0},
{RT_NULL, 0},
{RT_NULL, 0},
{app_music_page_leave, 0},
};
/*
**************************************************************************************************
*
* Main page design
*
**************************************************************************************************
*/
rt_err_t app_main_page_qrcode_init(void *param)
{
return app_qrcode_init(param);
}
rt_err_t app_main_page_qrcode_design(void *param)
{
return app_qrcode_design(param);
}
rt_err_t app_main_page_clock_init(void *param)
{
return app_clock_init(param);
}
rt_err_t app_main_page_clock_design(void *param)
{
return app_clock_design(param);
}
static design_cb_t clock_design = {.cb = app_main_page_clock_design,};
static page_refrsh_request_param_t clock_refresh_request_param;
static rt_uint8_t clock_second_bk = 60;
void app_main_page_clock_update(void)
{
app_main_get_time(&app_main_data->tmr_data);
if (clock_second_bk == app_main_data->tmr_data->tm_sec)
{
return;
}
clock_second_bk = app_main_data->tmr_data->tm_sec;
app_design_request(0, &clock_design, NULL);
clock_refresh_request_param.page = app_main_page;
clock_refresh_request_param.page_num = 1;
app_refresh_request(&clock_refresh_request_param);
}
rt_err_t app_main_page_weather_init(void *param)
{
return app_weather_init(param);
}
static page_refrsh_request_param_t weather_refresh_request_param;
rt_err_t app_main_page_weather_design(void *param)
{
rt_err_t ret;
ret = app_weather_design(param);
if (ret == RT_EOK)
{
weather_refresh_request_param.page = app_main_page;
weather_refresh_request_param.page_num = 1;
app_refresh_request(&weather_refresh_request_param);
}
return ret;
}
static design_cb_t weather_design = {.cb = app_main_page_weather_design,};
void app_main_page_weather_update(void)
{
app_design_request(0, &weather_design, NULL);
}
rt_err_t app_main_page_music_init(void *param)
{
return app_music_init(param);
}
rt_err_t app_main_page_music_design(void *param)
{
return app_music_design(param);
}
static design_cb_t music_design = {.cb = app_music_picture_rotate,};
void app_main_page_music_update(void)
{
static uint32_t last_tick = 0;
if (app_main_data->play_state != PLAYER_STATE_RUNNING ||
((HAL_GetTick() - last_tick) < 300))
{
return;
}
last_tick = HAL_GetTick();
app_design_request(0, &music_design, NULL);
}
/*
**************************************************************************************************
*
* Display refresh
*
**************************************************************************************************
*/
/*
**************************************************************************************************
*
* Touch process
*
**************************************************************************************************
*/
//---------------------------------------------------------------------------------
// touch down & up callback
//---------------------------------------------------------------------------------
rt_err_t app_show_charging_anim(void *param)
{
app_main_touch_skip(RT_TOUCH_EVENT_UP);
app_charging_enable(NULL);
return RT_EOK;
}
static void page_qrcode_touch_down(void *param)
{
app_main_register_timeout_cb(app_show_charging_anim, NULL, 300);
}
static void page_qrcode_touch_up(void *param)
{
app_main_unregister_timeout_cb_if_is(app_show_charging_anim);
if (main_page_timer_cb[app_main_page->hor_page].cb)
{
app_main_timer_cb_register(main_page_timer_cb[app_main_page->hor_page].cb,
main_page_timer_cb[app_main_page->hor_page].cycle_ms);
}
}
static void page_clock_touch_down(void *param)
{
app_main_register_timeout_cb(app_preview_enter, NULL, 500);
}
static void page_clock_touch_up(void *param)
{
app_main_unregister_timeout_cb_if_is(app_preview_enter);
if (main_page_timer_cb[app_main_page->hor_page].cb)
{
app_main_timer_cb_register(main_page_timer_cb[app_main_page->hor_page].cb,
main_page_timer_cb[app_main_page->hor_page].cycle_ms);
}
}
static void page_music_touch_up(void *param)
{
struct app_main_data_t *pdata = (struct app_main_data_t *)param;
struct rt_touch_data *cur_p = &pdata->cur_point[0];
app_music_touch(cur_p);
if (main_page_timer_cb[app_main_page->hor_page].cb)
{
app_main_timer_cb_register(main_page_timer_cb[app_main_page->hor_page].cb,
main_page_timer_cb[app_main_page->hor_page].cycle_ms);
}
}
struct app_page_touch_ops page_touch_ops[CLOCK_HOR_PAGE_MAX] =
{
{page_qrcode_touch_down, page_qrcode_touch_up},
{page_clock_touch_down, page_clock_touch_up},
{NULL, NULL},
{NULL, page_music_touch_up},
};
static rt_err_t app_main_page_touch_down(void *param)
{
struct app_page_data_t *p_page = app_main_page;
app_main_timer_cb_unregister();
if (page_touch_ops[p_page->hor_page].touch_down)
{
page_touch_ops[p_page->hor_page].touch_down(param);
}
app_main_get_time(&app_main_data->tmr_data);
app_main_page_clock_design(NULL);
return RT_EOK;
}
static rt_err_t app_main_page_touch_up(void *param)
{
struct app_page_data_t *p_page = app_main_page;
if (page_touch_ops[p_page->hor_page].touch_up)
{
page_touch_ops[p_page->hor_page].touch_up(param);
}
else
{
if (main_page_timer_cb[p_page->hor_page].cb)
{
app_main_timer_cb_register(main_page_timer_cb[app_main_page->hor_page].cb,
main_page_timer_cb[app_main_page->hor_page].cycle_ms);
}
}
return RT_EOK;
}
//---------------------------------------------------------------------------------
// touch move lr
//---------------------------------------------------------------------------------
static rt_err_t app_main_page_move_lr_design(void *param);
static design_cb_t move_lr_touch_design = { .cb = app_main_page_move_lr_design, };
static page_refrsh_request_param_t move_lr_refr_param;
static rt_err_t app_main_page_move_lr_design(void *param)
{
struct app_page_data_t *p_page = app_main_page;
mov_design_param *tar = (mov_design_param *)param;
int turn_page;
p_page->hor_offset += TOUCH_MOVE_STEP * tar->dir;
if ((tar->dir > 0 && (p_page->hor_offset >= tar->offset)) ||
(tar->dir < 0 && (p_page->hor_offset <= tar->offset)))
{
turn_page = (tar->offset != (p_page->hor_page * p_page->hor_step));
if (turn_page)
{
if (main_page_leave[p_page->hor_page].cb)
{
main_page_leave[p_page->hor_page].cb();
}
p_page->hor_page += tar->dir;
if (p_page->hor_page < 0)
{
p_page->hor_page += CLOCK_HOR_PAGE_MAX;
}
if (p_page->hor_page >= CLOCK_HOR_PAGE_MAX)
{
p_page->hor_page -= CLOCK_HOR_PAGE_MAX;
}
#if (APP_PSRAM_END_RESERVE > 0)
g_app_info->page_index = p_page->hor_page;
#endif
}
p_page->hor_offset = p_page->hor_page * p_page->hor_step;
if (main_page_timer_cb[p_page->hor_page].cb)
{
app_main_timer_cb_register(main_page_timer_cb[app_main_page->hor_page].cb,
main_page_timer_cb[app_main_page->hor_page].cycle_ms);
}
app_main_touch_register(&main_page_touch_cb);
}
else
{
app_design_request(0, &move_lr_touch_design, param);
}
move_lr_refr_param.page = app_main_page;
move_lr_refr_param.page_num = 1;
app_refresh_request(&move_lr_refr_param);
return RT_EOK;
}
static void slide_lr_cb(int mov_fix)
{
struct app_page_data_t *page = app_main_page;
page->hor_offset -= mov_fix;
}
static rt_err_t app_main_page_touch_move_lr(void *param)
{
struct app_main_data_t *pdata = (struct app_main_data_t *)param;
struct app_page_data_t *page = app_main_page;
page->hor_offset = -pdata->xoffset;
page->hor_offset += page->hor_page * page->hor_step;
app_main_unregister_timeout_cb_if_is(app_show_charging_anim);
app_main_unregister_timeout_cb_if_is(app_preview_enter);
move_lr_refr_param.page = page;
move_lr_refr_param.page_num = 1;
move_lr_refr_param.cb = slide_lr_cb;
app_slide_refresh(&move_lr_refr_param);
return RT_EOK;
}
//---------------------------------------------------------------------------------
// touch move updn
//---------------------------------------------------------------------------------
static rt_err_t app_main_page_move_updn_design(void *param);
static design_cb_t move_updn_touch_design = { .cb = app_main_page_move_updn_design, };
static page_refrsh_request_param_t move_updn_design_refr_param;
static page_refrsh_request_param_t move_updn_refr_param;
static rt_err_t app_main_page_move_updn_design(void *param)
{
struct app_main_data_t *maindata = app_main_data;
struct app_page_data_t *p_page = app_main_page;
struct app_main_page_private *pdata = p_page->private;
struct app_page_data_t *t_page = p_page->top;
struct app_page_data_t *b_page = p_page->bottom;
struct app_page_data_t *n_page;
mov_design_param *tar = (mov_design_param *)param;
if (pdata->tar_page == VER_PAGE_BOTTOM)
n_page = b_page;
else
n_page = t_page;
n_page->ver_offset += TOUCH_MOVE_STEP * tar->dir;
if (((tar->dir > 0) && (n_page->ver_offset >= tar->offset)) ||
((tar->dir < 0) && (n_page->ver_offset <= tar->offset)))
{
n_page->ver_offset = tar->offset;
if (tar->offset != 0)
{
if (main_page_timer_cb[p_page->hor_page].cb)
{
app_main_timer_cb_register(main_page_timer_cb[app_main_page->hor_page].cb,
main_page_timer_cb[app_main_page->hor_page].cycle_ms);
}
app_main_touch_register(&main_page_touch_cb);
maindata->ver_page = VER_PAGE_NULL;
move_updn_design_refr_param.page = app_main_page;
move_updn_design_refr_param.page_num = 1;
}
else
{
if (main_page_leave[p_page->hor_page].cb)
{
main_page_leave[p_page->hor_page].cb();
}
n_page->hor_offset = 0;
n_page->hor_page = 0;
app_update_page(n_page);
move_updn_design_refr_param.page = n_page;
move_updn_design_refr_param.page_num = 1;
maindata->ver_page = pdata->tar_page;
if (pdata->tar_page == VER_PAGE_TOP)
{
app_main_touch_register(&app_funclist_main_touch_cb);
}
else
{
app_main_touch_register(&app_message_main_touch_cb);
app_message_page_new_message(NULL);
}
}
p_page->h = CLOCK_WIN_YRES;
p_page->fb = pdata->fb;
p_page->ver_offset = 0;
pdata->tar_page = VER_PAGE_NULL;
app_refresh_request(&move_updn_design_refr_param);
}
else
{
app_design_request(0, &move_updn_touch_design, param);
app_main_page->next = n_page;
move_updn_design_refr_param.page = app_main_page;
move_updn_design_refr_param.page_num = 2;
move_updn_design_refr_param.auto_resize = 1;
app_refresh_request(&move_updn_design_refr_param);
}
return RT_EOK;
}
rt_err_t app_main_page_touch_move_updn_start(void *param)
{
struct app_main_data_t *pdata = (struct app_main_data_t *)param;
struct rt_touch_data *down_p = &pdata->down_point[0];
if (((int32_t)down_p->y_coordinate >= CLOCK_WIN_YRES / 3) &&
((int32_t)down_p->y_coordinate <= CLOCK_WIN_YRES * 2 / 3))
{
return -RT_ERROR;
}
return RT_EOK;
}
static void slide_updn_cb(int mov_fix)
{
struct app_page_data_t *page = app_main_page;
struct app_main_page_private *pdata = page->private;
struct app_page_data_t *n_page;
if (pdata->tar_page == VER_PAGE_BOTTOM)
n_page = page->bottom;
else
n_page = page->top;
if (n_page != NULL)
{
n_page->ver_offset -= mov_fix;
if (n_page->ver_offset < -(DISP_YRES - 2))
n_page->ver_offset = -(DISP_YRES - 2);
if (n_page->ver_offset > (DISP_YRES - 2))
n_page->ver_offset = (DISP_YRES - 2);
}
}
rt_err_t app_main_page_touch_move_updn(void *param)
{
struct app_main_data_t *maindata = (struct app_main_data_t *)param;
struct app_page_data_t *p_page = app_main_page;
struct app_main_page_private *pdata = p_page->private;
struct app_page_data_t *n_page;
struct rt_touch_data *down_p = &maindata->down_point[0];
struct rt_touch_data *cur_p = &maindata->cur_point[0];
if (pdata->tar_page == VER_PAGE_NULL)
{
if (down_p->y_coordinate > cur_p->y_coordinate)
pdata->tar_page = VER_PAGE_BOTTOM;
else
pdata->tar_page = VER_PAGE_TOP;
}
if (pdata->tar_page == VER_PAGE_BOTTOM)
n_page = p_page->bottom;
else
n_page = p_page->top;
if (n_page == NULL)
{
pdata->tar_page = VER_PAGE_NULL;
return RT_EOK;
}
n_page->ver_offset = -maindata->yoffset + DISP_YRES * pdata->tar_page;
if (n_page->ver_offset < -(DISP_YRES - 2))
n_page->ver_offset = -(DISP_YRES - 2);
if (n_page->ver_offset > (DISP_YRES - 2))
n_page->ver_offset = (DISP_YRES - 2);
app_main_unregister_timeout_cb_if_is(app_show_charging_anim);
app_main_unregister_timeout_cb_if_is(app_preview_enter);
p_page->next = n_page;
move_updn_refr_param.page = p_page;
move_updn_refr_param.page_num = 2;
move_updn_refr_param.auto_resize = 1;
move_updn_refr_param.cb = slide_updn_cb;
app_slide_refresh(&move_updn_refr_param);
return RT_EOK;
}
//---------------------------------------------------------------------------------
// touch move(touch) up
//---------------------------------------------------------------------------------
static mov_design_param move_up_design_param;
static rt_err_t app_main_page_touch_move_up(void *param)
{
struct app_main_data_t *maindata = (struct app_main_data_t *)param;
struct app_main_page_private *pdata = app_main_page->private;
struct rt_touch_data *cur_p = &maindata->cur_point[0];
struct rt_touch_data *down_p = &maindata->down_point[0];
int tar_page;
app_main_unregister_timeout_cb_if_is(app_show_charging_anim);
app_main_unregister_timeout_cb_if_is(app_preview_enter);
app_slide_refresh_undo();
app_main_touch_unregister();
if (maindata->dir_mode == TOUCH_DIR_MODE_LR)
{
if (ABS((int32_t)down_p->x_coordinate - (int32_t)cur_p->x_coordinate) >= CLOCK_WIN_XRES / 3)
{
move_up_design_param.dir = down_p->x_coordinate > cur_p->x_coordinate ? 1 : -1;
tar_page = app_main_page->hor_page + move_up_design_param.dir;
}
else
{
move_up_design_param.dir = down_p->x_coordinate > cur_p->x_coordinate ? -1 : 1;
tar_page = app_main_page->hor_page;
}
move_up_design_param.offset = CLOCK_WIN_XRES * tar_page;
app_design_request(1, &move_lr_touch_design, &move_up_design_param);
}
else if (maindata->dir_mode == TOUCH_DIR_MODE_UPDN)
{
app_main_timer_cb_unregister();
if (ABS((int32_t)down_p->y_coordinate - (int32_t)cur_p->y_coordinate) >= CLOCK_WIN_YRES / 2)
{
move_up_design_param.dir = -pdata->tar_page;
move_up_design_param.offset = 0;
}
else
{
move_up_design_param.dir = pdata->tar_page;
move_up_design_param.offset = CLOCK_WIN_YRES * move_up_design_param.dir;
}
app_design_request(1, &move_updn_touch_design, &move_up_design_param);
}
else
{
app_main_touch_register(&main_page_touch_cb);
}
return RT_EOK;
}
struct app_touch_cb_t main_page_touch_cb =
{
.tp_touch_down = app_main_page_touch_down,
.tp_move_lr = app_main_page_touch_move_lr,
.tp_move_updn = app_main_page_touch_move_updn,
.tp_move_up = app_main_page_touch_move_up,
.tp_touch_up = app_main_page_touch_up,
.tp_move_updn_start = app_main_page_touch_move_updn_start,
};
/*
**************************************************************************************************
*
* Declaration
*
**************************************************************************************************
*/
static void app_main_page_mem_init(void)
{
struct app_page_data_t *page;
struct app_main_page_private *pdata;
app_main_page = page = (struct app_page_data_t *)rt_malloc(sizeof(struct app_page_data_t));
RT_ASSERT(page != RT_NULL);
rt_memset(page, 0, sizeof(struct app_page_data_t));
pdata = (struct app_main_page_private *)rt_malloc(sizeof(struct app_main_page_private));
RT_ASSERT(pdata != RT_NULL);
page->id = ID_MAIN;
page->fblen = CLOCK_WIN_FB_W * (CLOCK_WIN_FB_H + 1) * (CLOCK_WIN_COLOR_DEPTH >> 3);
page->fb = (rt_uint8_t *)rt_malloc_psram(page->fblen);
RT_ASSERT(page->fb != RT_NULL);
rt_memset(page->fb, 0, page->fblen);
page->w = CLOCK_WIN_XRES;
page->h = CLOCK_WIN_YRES;
page->vir_w = CLOCK_WIN_FB_W;
page->win_loop = 1;
page->hor_step = CLOCK_WIN_XRES;
page->win_id = APP_CLOCK_WIN_2;
page->win_layer = WIN_BOTTOM_LAYER;
page->format = RTGRAPHIC_PIXEL_FORMAT_RGB565;
page->private = pdata;
page->touch_cb = &main_page_touch_cb;
pdata->fb = page->fb;
pdata->tar_page = VER_PAGE_NULL;
}
void app_main_page_init(void)
{
app_main_page_mem_init();
app_main_page->hor_page = CLOCK_PAGE_FOC_ID;
app_main_page->hor_offset = app_main_page->hor_page * app_main_page->hor_step;
get_app_info(app_main_data);
rt_display_backlight_set(app_main_data->bl);
rk_imagelib_init();
struct image_st pd;
pd.width = CLOCK_WIN_XRES;
pd.height = CLOCK_WIN_YRES;
pd.stride = CLOCK_WIN_FB_W * (CLOCK_WIN_COLOR_DEPTH >> 3);
pd.format = app_main_page->format;
pd.pdata = app_main_page->fb + 0 * CLOCK_WIN_XRES * (CLOCK_WIN_COLOR_DEPTH >> 3);
app_main_page_qrcode_init(&pd);
app_main_page_qrcode_design(&pd);
pd.pdata = app_main_page->fb + 1 * CLOCK_WIN_XRES * (CLOCK_WIN_COLOR_DEPTH >> 3);
app_main_page_clock_init(&pd);
app_main_page_clock_design(&pd);
pd.pdata = app_main_page->fb + 2 * CLOCK_WIN_XRES * (CLOCK_WIN_COLOR_DEPTH >> 3);
app_main_page_weather_init(&pd);
app_main_page_weather_design(&pd);
pd.pdata = app_main_page->fb + 3 * CLOCK_WIN_XRES * (CLOCK_WIN_COLOR_DEPTH >> 3);
app_main_page_music_init(&pd);
app_main_page_music_design(&pd);
app_enter_page(app_main_page);
//register callback
if (main_page_timer_cb[app_main_page->hor_page].cb)
{
app_main_timer_cb_register(main_page_timer_cb[app_main_page->hor_page].cb,
main_page_timer_cb[app_main_page->hor_page].cycle_ms);
}
app_main_touch_register(&main_page_touch_cb);
#ifdef APP_WEARABLE_ANIM_AUTO_PLAY
app_main_register_timeout_cb(auto_play_init, NULL, 1000);
#endif
}