forked from lvgl/lv_port_linux
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
159 lines (139 loc) · 4.06 KB
/
main.c
File metadata and controls
159 lines (139 loc) · 4.06 KB
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
/*******************************************************************
*
* main.c - LVGL simulator for GNU/Linux
*
* Based on the original file from the repository
*
* @note eventually this file won't contain a main function and will
* become a library supporting all major operating systems
*
* To see how each driver is initialized check the
* 'src/lib/display_backends' directory
*
* - Clean up
* - Support for multiple backends at once
* 2025 EDGEMTech Ltd.
*
* Author: EDGEMTech Ltd, Erik Tagirov (erik.tagirov@edgemtech.ch)
*
******************************************************************/
#include <unistd.h>
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "lvgl/lvgl.h"
#include "lvgl/demos/lv_demos.h"
#include "src/lib/driver_backends.h"
#include "src/lib/simulator_util.h"
#include "src/lib/simulator_settings.h"
/* Internal functions */
static void configure_simulator(int argc, char **argv);
static void print_lvgl_version(void);
static void print_usage(void);
/* contains the name of the selected backend if user
* has specified one on the command line */
static char *selected_backend;
/* Global simulator settings, defined in lv_linux_backend.c */
extern simulator_settings_t settings;
/**
* @brief Print LVGL version
*/
static void print_lvgl_version(void)
{
fprintf(stdout, "%d.%d.%d-%s\n",
LVGL_VERSION_MAJOR,
LVGL_VERSION_MINOR,
LVGL_VERSION_PATCH,
LVGL_VERSION_INFO);
}
/**
* @brief Print usage information
*/
static void print_usage(void)
{
fprintf(stdout, "\nlvglsim [-V] [-B] [-b backend_name] [-W window_width] [-H window_height]\n\n");
fprintf(stdout, "-V print LVGL version\n");
fprintf(stdout, "-B list supported backends\n");
}
/**
* @brief Configure simulator
* @description process arguments recieved by the program to select
* appropriate options
* @param argc the count of arguments in argv
* @param argv The arguments
*/
static void configure_simulator(int argc, char **argv)
{
int opt = 0;
selected_backend = NULL;
driver_backends_register();
const char *env_w = getenv("LV_SIM_WINDOW_WIDTH");
const char *env_h = getenv("LV_SIM_WINDOW_HEIGHT");
/* Default values */
settings.window_width = 480;
settings.window_height = 800;
/* Parse the command-line options. */
while ((opt = getopt (argc, argv, "b:fmW:H:BVh")) != -1) {
switch (opt) {
case 'h':
print_usage();
exit(EXIT_SUCCESS);
break;
case 'V':
print_lvgl_version();
exit(EXIT_SUCCESS);
break;
case 'B':
driver_backends_print_supported();
exit(EXIT_SUCCESS);
break;
case 'b':
if (driver_backends_is_supported(optarg) == 0) {
die("error no such backend: %s\n", optarg);
}
selected_backend = strdup(optarg);
break;
case 'W':
settings.window_width = atoi(optarg);
break;
case 'H':
settings.window_height = atoi(optarg);
break;
case ':':
print_usage();
die("Option -%c requires an argument.\n", optopt);
break;
case '?':
print_usage();
die("Unknown option -%c.\n", optopt);
}
}
}
/**
* @brief entry point
* @description start a demo
* @param argc the count of arguments in argv
* @param argv The arguments
*/
int main(int argc, char **argv)
{
configure_simulator(argc, argv);
/* Initialize LVGL. */
lv_init();
/* Initialize the configured backend */
if (driver_backends_init_backend(selected_backend) == -1) {
die("Failed to initialize display backend");
}
/* Enable for EVDEV support */
#if LV_USE_EVDEV
if (driver_backends_init_backend("EVDEV") == -1) {
die("Failed to initialize evdev");
}
#endif
/*Create a Demo*/
lv_demo_benchmark();
/* Enter the run loop of the selected backend */
driver_backends_run_loop();
return 0;
}