-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
136 lines (109 loc) · 3.1 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
132
133
134
135
136
/**
* @file main
*
*/
/*********************
* INCLUDES
*********************/
#define _DEFAULT_SOURCE /* needed for usleep() */
#include <stdlib.h>
#include <unistd.h>
#include "lvgl/lvgl.h"
#include "lvgl/examples/lv_examples.h"
#include "lvgl/demos/lv_demos.h"
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
static lv_disp_t * hal_init(lv_coord_t w, lv_coord_t h);
/**********************
* STATIC VARIABLES
**********************/
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* VARIABLES
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
int SDL_main(int argc, char *argv[])
{
(void)argc; /*Unused*/
(void)argv; /*Unused*/
/*Initialize LVGL*/
lv_init();
/*Create a default group for keyboard navigation*/
lv_group_set_default(lv_group_create());
/*Initialize the HAL (display, input devices, tick) for LVGL*/
hal_init(240, 200);
// lv_example_switch_1();
// lv_example_calendar_1();
// lv_example_btnmatrix_2();
// lv_example_checkbox_1();
// lv_example_colorwheel_1();
// lv_example_chart_6();
// lv_example_table_2();
// lv_example_scroll_2();
// lv_example_textarea_1();
// lv_example_msgbox_1();
// lv_example_dropdown_2();
// lv_example_btn_1();
// lv_example_scroll_1();
// lv_example_tabview_1();
// lv_example_tabview_1();
// lv_example_flex_3();
// lv_example_label_1();
// lv_example_spinbox_1();
// lv_demo_widgets();
while(1) {
/* Periodically call the lv_task handler.
* It could be done in a timer interrupt or an OS task too.*/
lv_timer_handler();
usleep(5 * 1000);
}
return 0;
}
/**********************
* STATIC FUNCTIONS
**********************/
/**
* Initialize the Hardware Abstraction Layer (HAL) forLVGL
*/
static lv_disp_t * hal_init(lv_coord_t w, lv_coord_t h)
{
lv_disp_t * disp = lv_sdl_window_create(w, h);
lv_indev_t * mouse = lv_sdl_mouse_create();
lv_indev_set_group(mouse, lv_group_get_default());
lv_indev_set_disp(mouse, disp);
LV_IMG_DECLARE(mouse_cursor_icon); /*Declare the image file.*/
lv_obj_t * cursor_obj;
cursor_obj = lv_img_create(lv_scr_act()); /*Create an image object for the cursor */
lv_img_set_src(cursor_obj, &mouse_cursor_icon); /*Set the image source*/
lv_indev_set_cursor(mouse, cursor_obj); /*Connect the image object to the driver*/
lv_indev_t * mousewheel = lv_sdl_mousewheel_create();
lv_indev_set_disp(mousewheel, disp);
lv_indev_set_group(mousewheel, lv_group_get_default());
lv_indev_t * keyboard = lv_sdl_keyboard_create();
lv_indev_set_disp(keyboard, disp);
lv_indev_set_group(keyboard, lv_group_get_default());
return disp;
}