-
Notifications
You must be signed in to change notification settings - Fork 30
/
main.c
131 lines (105 loc) · 3.09 KB
/
main.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
/**
* @file main
*
*/
/*********************
* INCLUDES
*********************/
#include <stdlib.h>
#include <unistd.h>
#define SDL_MAIN_HANDLED /*To fix SDL's "undefined reference to WinMain" issue*/
#include <SDL2/SDL.h>
#include <emscripten.h>
#include "lvgl/lvgl.h"
#include "lvgl/demos/lv_demos.h"
#include "examplelist.h"
/*********************
* DEFINES
*********************/
/*On OSX SDL needs different handling*/
#if defined(__APPLE__) && defined(TARGET_OS_MAC)
# if __APPLE__ && TARGET_OS_MAC
#define SDL_APPLE
# endif
#endif
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
static void hal_init(void);
static int tick_thread(void * data);
static void memory_monitor(lv_timer_t * param);
/**********************
* STATIC VARIABLES
**********************/
int monitor_hor_res, monitor_ver_res;
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
void do_loop(void *arg);
/* Allows disabling CHOSEN_DEMO */
static void lv_example_noop(void) {
}
int main(int argc, char ** argv)
{
extern const struct lv_ci_example lv_ci_example_list[];
const struct lv_ci_example *ex = NULL;
monitor_hor_res = atoi(argv[1]);
monitor_ver_res = atoi(argv[2]);
/* Check if a specific example is wanted (not "default") */
if(argc >= 4 && strcmp(ex->name, "default")) {
for(ex = &lv_ci_example_list[0]; ex->name != NULL; ex++) {
if(!strcmp(ex->name, argv[3])) {
break;
}
}
if(ex->name == NULL) {
fprintf(stderr, "Unable to find requested example\n");
}
}
printf("Starting with screen resolution of %dx%d px\n", monitor_hor_res, monitor_ver_res);
/*Initialize LittlevGL*/
lv_init();
/*Initialize the HAL (display, input devices, tick) for LittlevGL*/
hal_init();
/*Load a demo*/
if(ex != NULL && ex->fn != NULL) {
ex->fn();
} else {
extern void CHOSEN_DEMO(void);
CHOSEN_DEMO();
}
emscripten_set_main_loop_arg(do_loop, NULL, -1, true);
}
void do_loop(void *arg)
{
/* Periodically call the lv_task handler.
* It could be done in a timer interrupt or an OS task too.*/
lv_task_handler();
}
/**********************
* STATIC FUNCTIONS
**********************/
/**
* Initialize the Hardware Abstraction Layer (HAL) for the Littlev graphics library
*/
static void hal_init(void)
{
lv_display_t * disp = lv_sdl_window_create(monitor_hor_res, monitor_ver_res);
lv_group_t * g = lv_group_create();
lv_group_set_default(g);
lv_sdl_mouse_create();
lv_sdl_mousewheel_create();
lv_sdl_keyboard_create();
lv_indev_t * mouse = lv_sdl_mouse_create();
lv_indev_set_group(mouse, lv_group_get_default());
lv_indev_t * mousewheel = lv_sdl_mousewheel_create();
lv_indev_set_group(mousewheel, lv_group_get_default());
lv_indev_t * keyboard = lv_sdl_keyboard_create();
lv_indev_set_group(keyboard, lv_group_get_default());
}