1 /**
2  * @file lv_demos.c
3  *
4  */
5 
6 /*********************
7  *      INCLUDES
8  *********************/
9 #include "lv_demos.h"
10 
11 /*********************
12  *      DEFINES
13  *********************/
14 #define LV_DEMOS_COUNT (sizeof(demos_entry_info) / sizeof(demo_entry_info_t) - 1)
15 
16 /**********************
17  *      TYPEDEFS
18  **********************/
19 
20 typedef void (*demo_method_cb)(void);
21 
22 typedef struct  {
23     const char * name;
24     demo_method_cb entry_cb;
25 } demo_entry_info_t;
26 
27 /**********************
28  *  STATIC PROTOTYPES
29  **********************/
30 
31 /**********************
32  *  STATIC VARIABLES
33  **********************/
34 static const demo_entry_info_t demos_entry_info[] = {
35 #if LV_USE_DEMO_WIDGETS
36     { "widgets", .entry_cb = lv_demo_widgets },
37 #endif
38 
39 #if LV_USE_DEMO_MUSIC
40     { "music", .entry_cb = lv_demo_music },
41 #endif
42 #if LV_USE_DEMO_MULTILANG
43     { "multilang", .entry_cb = lv_demo_multilang },
44 #endif
45 
46 #if LV_USE_DEMO_STRESS
47     { "stress", .entry_cb = lv_demo_stress },
48 #endif
49 
50 #if LV_USE_DEMO_KEYPAD_AND_ENCODER
51     { "keypad_encoder", .entry_cb = lv_demo_keypad_encoder },
52 #endif
53 
54 #if LV_USE_DEMO_FLEX_LAYOUT
55     { "flex_layout", .entry_cb = lv_demo_flex_layout },
56 #endif
57 
58 #if LV_USE_DEMO_TRANSFORM
59     { "transform", .entry_cb = lv_demo_transform },
60 #endif
61 
62 #if LV_USE_DEMO_SCROLL
63     { "scroll", .entry_cb = lv_demo_scroll },
64 #endif
65 
66 #if LV_USE_DEMO_VECTOR_GRAPHIC && LV_USE_VECTOR_GRAPHIC
67     { "vector_graphic_buffered", .entry_cb = lv_demo_vector_graphic_buffered },
68 #endif
69 
70 #if LV_USE_DEMO_VECTOR_GRAPHIC && LV_USE_VECTOR_GRAPHIC
71     { "vector_graphic_not_buffered", .entry_cb = lv_demo_vector_graphic_not_buffered },
72 #endif
73 
74 #if LV_USE_DEMO_BENCHMARK
75     { "benchmark", .entry_cb = lv_demo_benchmark },
76 #endif
77 
78     { "", .entry_cb = NULL }
79 };
80 
81 /**********************
82  *      MACROS
83  **********************/
84 
85 /**********************
86  *   GLOBAL FUNCTIONS
87  **********************/
88 
lv_demos_create(char * info[],int size)89 bool lv_demos_create(char * info[], int size)
90 {
91     const int demos_count = LV_DEMOS_COUNT;
92 
93     if(demos_count <= 0) {
94         LV_LOG_ERROR("Please enable some lv_demos firstly!");
95         return false;
96     }
97 
98     const demo_entry_info_t * entry_info = NULL;
99     if(size <= 0) { /* default: first demo*/
100         entry_info = &demos_entry_info[0];
101     }
102     else if(entry_info == NULL && info) {
103         const char * name = info[0];
104         for(int i = 0; i < demos_count; i++) {
105             if(lv_strcmp(name, demos_entry_info[i].name) == 0) {
106                 entry_info = &demos_entry_info[i];
107             }
108         }
109     }
110 
111     if(entry_info == NULL) {
112         LV_LOG_ERROR("lv_demos create(%s) failure!", size > 0 ? info[0] : "");
113         return false;
114     }
115 
116     if(entry_info->entry_cb) {
117         entry_info->entry_cb();
118         return true;
119     }
120 
121     return false;
122 }
123 
lv_demos_show_help(void)124 void lv_demos_show_help(void)
125 {
126     int i;
127     const int demos_count = LV_DEMOS_COUNT;
128 
129     if(demos_count == 0) {
130         LV_LOG("lv_demos: no demo available!\n");
131         return;
132     }
133 
134     LV_LOG("\nUsage: lv_demos demo [parameters]\n");
135     LV_LOG("\ndemo list:\n");
136 
137     for(i = 0; i < demos_count; i++) {
138         LV_LOG("     %s \n", demos_entry_info[i].name);
139     }
140 }
141