xref: /OK3568_Linux_fs/app/lvgl_demo/lv_demo/main.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /*
2  * Copyright (c) 2021 Rockchip, Inc. All Rights Reserved.
3  *
4  *  Licensed under the Apache License, Version 2.0 (the "License");
5  *  you may not use this file except in compliance with the License.
6  *  You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *  Unless required by applicable law or agreed to in writing, software
11  *  distributed under the License is distributed on an "AS IS" BASIS,
12  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *  See the License for the specific language governing permissions and
14  *  limitations under the License.
15  */
16 
17 #include <lvgl/lvgl.h>
18 #include <lvgl/lv_conf.h>
19 
20 #include "main.h"
21 #include "hal_sdl.h"
22 #include "hal_drm.h"
23 
24 static int g_indev_rotation = 90;
25 static int g_disp_rotation = LV_DISP_ROT_90;
26 
27 static int quit = 0;
28 
29 #if LV_USE_DEMO_WIDGETS
30 extern void lv_demo_widgets(void);
31 #elif LV_USE_DEMO_KEYPAD_AND_ENCODER
32 extern void lv_demo_keypad_encoder(void);
33 #elif LV_USE_DEMO_BENCHMARK
34 extern void lv_demo_benchmark(void);
35 #elif LV_USE_DEMO_STRESS
36 extern void lv_demo_stress(void);
37 #elif LV_USE_DEMO_MUSIC
38 extern void lv_demo_music(void);
39 #endif
40 
sigterm_handler(int sig)41 static void sigterm_handler(int sig) {
42     fprintf(stderr, "signal %d\n", sig);
43     quit = 1;
44 }
45 
app_disp_rotation(void)46 int app_disp_rotation(void)
47 {
48     return g_disp_rotation;
49 }
50 
lvgl_init(void)51 static void lvgl_init(void)
52 {
53     lv_init();
54 
55 #ifdef USE_SDL_GPU
56     hal_sdl_init(0, 0, g_disp_rotation);
57 #else
58     hal_drm_init(0, 0, g_disp_rotation);
59 #endif
60     lv_port_fs_init();
61     lv_port_indev_init(g_indev_rotation);
62 }
63 
main(int argc,char ** argv)64 int main(int argc, char **argv)
65 {
66 #define FPS     0
67 #if FPS
68     float maxfps = 0.0, minfps = 1000.0;
69     float fps;
70     float fps0 = 0, fps1 = 0;
71     uint32_t st, et;
72     uint32_t st0 = 0, et0;
73 #endif
74     signal(SIGINT, sigterm_handler);
75     lvgl_init();
76 
77 #if LV_USE_DEMO_WIDGETS
78     lv_demo_widgets();
79 #elif LV_USE_DEMO_KEYPAD_AND_ENCODER
80     lv_demo_keypad_encoder();
81 #elif LV_USE_DEMO_BENCHMARK
82     lv_demo_benchmark();
83 #elif LV_USE_DEMO_STRESS
84     lv_demo_stress();
85 #elif LV_USE_DEMO_MUSIC
86     lv_demo_music();
87 #endif
88 
89     while(!quit) {
90 #if FPS
91         st = clock_ms();
92 #endif
93         lv_task_handler();
94 #if FPS
95         et = clock_ms();
96         fps = 1000 / (et - st);
97         if (fps != 0.0 && fps < minfps) {
98             minfps = fps;
99             printf("Update minfps %f\n", minfps);
100         }
101         if (fps < 60 && fps > maxfps) {
102             maxfps = fps;
103             printf("Update maxfps %f\n", maxfps);
104         }
105         if (fps > 0.0 && fps < 60) {
106             fps0 = (fps0 + fps) / 2;
107             fps1 = (fps0 + fps1) / 2;
108         }
109         et0 = clock_ms();
110         if ((et0 - st0) > 1000) {
111             printf("avg:%f\n", fps1);
112             st0 = et0;
113         }
114 #endif
115         usleep(100);
116     }
117 
118     return 0;
119 }
120