Skip to content

Commit 1030f17

Browse files
committed
feat: support passing rotation angle as command line argument
1 parent 247c6d1 commit 1030f17

3 files changed

Lines changed: 32 additions & 2 deletions

File tree

lv_conf.defaults

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@ LV_OBJ_STYLE_CACHE 1
139139
# Gradients
140140
LV_USE_DRAW_SW_COMPLEX_GRADIENTS 1
141141

142+
LV_DRAW_TRANSFORM_USE_MATRIX 1
143+
142144
# Enable built-in fonts
143145
LV_FONT_MONTSERRAT_12 1
144146
LV_FONT_MONTSERRAT_14 1

src/lib/simulator_settings.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ extern "C" {
2222
/*********************
2323
* INCLUDES
2424
*********************/
25+
#include "lvgl/lvgl.h"
2526

2627
/*********************
2728
* DEFINES
@@ -34,6 +35,7 @@ extern "C" {
3435
typedef struct {
3536
uint32_t window_width;
3637
uint32_t window_height;
38+
lv_display_rotation_t rotation;
3739
bool maximize;
3840
bool fullscreen;
3941
} simulator_settings_t;

src/main.c

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ static void print_lvgl_version(void)
6060
*/
6161
static void print_usage(void)
6262
{
63-
fprintf(stdout, "\nlvglsim [-V] [-B] [-f] [-m] [-b backend_name] [-W window_width] [-H window_height]\n\n");
63+
fprintf(stdout,
64+
"\nlvglsim [-V] [-B] [-f] [-m] [-b backend_name] [-W window_width] [-H window_height] [-R rotation]\n\n");
6465
fprintf(stdout, "-V print LVGL version\n");
6566
fprintf(stdout, "-B list supported backends\n");
6667
fprintf(stdout, "-f fullscreen\n");
@@ -88,7 +89,7 @@ static void configure_simulator(int argc, char ** argv)
8889
settings.window_height = atoi(env_h ? env_h : "480");
8990

9091
/* Parse the command-line options. */
91-
while((opt = getopt(argc, argv, "b:fmW:H:BVh")) != -1) {
92+
while((opt = getopt(argc, argv, "b:fmW:H:R:BVh")) != -1) {
9293
switch(opt) {
9394
case 'h':
9495
print_usage();
@@ -120,6 +121,25 @@ static void configure_simulator(int argc, char ** argv)
120121
case 'H':
121122
settings.window_height = atoi(optarg);
122123
break;
124+
case 'R':
125+
switch(atoi(optarg)) {
126+
case 0:
127+
settings.rotation = LV_DISPLAY_ROTATION_0;
128+
break;
129+
case 90:
130+
settings.rotation = LV_DISPLAY_ROTATION_90;
131+
break;
132+
case 180:
133+
settings.rotation = LV_DISPLAY_ROTATION_180;
134+
break;
135+
case 270:
136+
settings.rotation = LV_DISPLAY_ROTATION_270;
137+
break;
138+
default:
139+
LV_LOG_WARN("Invalid rotation angle. Valid angles are {0, 90, 180, 270}");
140+
break;
141+
}
142+
break;
123143
case ':':
124144
print_usage();
125145
die("Option -%c requires an argument.\n", optopt);
@@ -149,6 +169,12 @@ int main(int argc, char ** argv)
149169
if(driver_backends_init_backend(selected_backend) == -1) {
150170
die("Failed to initialize display backend");
151171
}
172+
if(settings.rotation) {
173+
#if LV_DRAW_TRANSFORM_USE_MATRIX
174+
lv_display_set_matrix_rotation(NULL, true);
175+
#endif
176+
lv_display_set_rotation(NULL, settings.rotation);
177+
}
152178

153179
/* Enable for EVDEV support */
154180
#if LV_USE_EVDEV

0 commit comments

Comments
 (0)