forked from lvgl/lv_port_linux
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
168 lines (138 loc) · 4.08 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
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
#include <unistd.h>
#include <pthread.h>
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include "lvgl/lvgl.h"
#include "lvgl/demos/lv_demos.h"
#if LV_USE_WAYLAND
#include "backends/interface.h"
#endif
uint16_t window_width;
uint16_t window_height;
bool fullscreen;
bool maximize;
static void configure_simulator(int argc, char **argv);
static const char *getenv_default(const char *name, const char *dflt)
{
return getenv(name) ? : dflt;
}
#if LV_USE_EVDEV
static void lv_linux_init_input_pointer(lv_display_t *disp)
{
/* Enables a pointer (touchscreen/mouse) input device
* Use 'evtest' to find the correct input device. /dev/input/by-id/ is recommended if possible
* Use /dev/input/by-id/my-mouse-or-touchscreen or /dev/input/eventX
*/
const char *input_device = getenv("LV_LINUX_EVDEV_POINTER_DEVICE");
if (input_device == NULL) {
fprintf(stderr, "please set the LV_LINUX_EVDEV_POINTER_DEVICE environment variable\n");
exit(1);
}
lv_indev_t *touch = lv_evdev_create(LV_INDEV_TYPE_POINTER, input_device);
lv_indev_set_display(touch, disp);
/* Set the cursor icon */
LV_IMAGE_DECLARE(mouse_cursor_icon);
lv_obj_t * cursor_obj = lv_image_create(lv_screen_active());
lv_image_set_src(cursor_obj, &mouse_cursor_icon);
lv_indev_set_cursor(touch, cursor_obj);
}
#endif
#if LV_USE_LINUX_FBDEV
static void lv_linux_disp_init(void)
{
const char *device = getenv_default("LV_LINUX_FBDEV_DEVICE", "/dev/fb0");
lv_display_t * disp = lv_linux_fbdev_create();
#if LV_USE_EVDEV
lv_linux_init_input_pointer(disp);
#endif
lv_linux_fbdev_set_file(disp, device);
}
#elif LV_USE_LINUX_DRM
static void lv_linux_disp_init(void)
{
const char *device = getenv_default("LV_LINUX_DRM_CARD", "/dev/dri/card0");
lv_display_t * disp = lv_linux_drm_create();
#if LV_USE_EVDEV
lv_linux_init_input_pointer(disp);
#endif
lv_linux_drm_set_file(disp, device, -1);
}
#elif LV_USE_SDL
static void lv_linux_disp_init(void)
{
lv_sdl_window_create(window_width, window_height);
}
#elif LV_USE_WAYLAND
/* see backend/wayland.c */
#else
#error Unsupported configuration
#endif
#if LV_USE_WAYLAND == 0
void lv_linux_run_loop(void)
{
uint32_t idle_time;
/*Handle LVGL tasks*/
while(1) {
idle_time = lv_timer_handler(); /*Returns the time to the next timer execution*/
usleep(idle_time * 1000);
}
}
#endif
/*
* Process command line arguments and environment
* variables to configure the simulator
*/
static void configure_simulator(int argc, char **argv)
{
int opt = 0;
bool err = false;
/* Default values */
fullscreen = maximize = false;
window_width = atoi(getenv("LV_SIM_WINDOW_WIDTH") ? : "800");
window_height = atoi(getenv("LV_SIM_WINDOW_HEIGHT") ? : "480");
/* Parse the command-line options. */
while ((opt = getopt (argc, argv, "fmw:h:")) != -1) {
switch (opt) {
case 'f':
fullscreen = true;
if (LV_USE_WAYLAND == 0) {
fprintf(stderr, "The SDL driver doesn't support fullscreen mode on start\n");
exit(1);
}
break;
case 'm':
maximize = true;
if (LV_USE_WAYLAND == 0) {
fprintf(stderr, "The SDL driver doesn't support maximized mode on start\n");
exit(1);
}
break;
case 'w':
window_width = atoi(optarg);
break;
case 'h':
window_height = atoi(optarg);
break;
case ':':
fprintf (stderr, "Option -%c requires an argument.\n", optopt);
exit(1);
case '?':
fprintf (stderr, "Unknown option -%c.\n", optopt);
exit(1);
}
}
}
int main(int argc, char **argv)
{
configure_simulator(argc, argv);
/* Initialize LVGL. */
lv_init();
/* Initialize the configured backend SDL2, FBDEV, libDRM or wayland */
lv_linux_disp_init();
/*Create a Demo*/
lv_demo_widgets();
lv_demo_widgets_start_slideshow();
lv_linux_run_loop();
return 0;
}