Skip to content

Commit 12a866f

Browse files
Finomniscfriedt
authored andcommitted
samples: lvgl: Refactor screen_transparency sample
The LVGL screen_transparency sample was refactored in two ways: - Remove old obsolete display initialization code. LVGL does not even react to this code because LVGL color format is determined during LVGL initialization, which comes before main(). Further, the way it is written right now is incompatible with `AL_88` color. - Add some RGB color text for demonstration purposes. Signed-off-by: Martin Stumpf <[email protected]>
1 parent 7472a79 commit 12a866f

File tree

1 file changed

+14
-18
lines changed
  • samples/modules/lvgl/screen_transparency/src

1 file changed

+14
-18
lines changed

samples/modules/lvgl/screen_transparency/src/main.c

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -27,36 +27,32 @@ static void initialize_gui(void)
2727
/* Create a label, set its text and align it to the center */
2828
label = lv_label_create(lv_screen_active());
2929
lv_label_set_text(label, "Hello, world!");
30-
lv_obj_set_style_text_color(lv_screen_active(), lv_color_hex(0xff00ff), LV_PART_MAIN);
31-
lv_obj_align(label, LV_ALIGN_CENTER, 0, 0);
30+
lv_obj_set_style_text_color(label, lv_color_hex(0xff00ff), LV_PART_MAIN);
31+
lv_obj_align(label, LV_ALIGN_CENTER, 0, -20);
32+
label = lv_label_create(lv_screen_active());
33+
lv_label_set_text(label, "RED");
34+
lv_obj_set_style_text_color(label, lv_color_hex(0xff0000), LV_PART_MAIN);
35+
lv_obj_align(label, LV_ALIGN_CENTER, -70, 20);
36+
label = lv_label_create(lv_screen_active());
37+
lv_label_set_text(label, "GREEN");
38+
lv_obj_set_style_text_color(label, lv_color_hex(0x00ff00), LV_PART_MAIN);
39+
lv_obj_align(label, LV_ALIGN_CENTER, 0, 20);
40+
label = lv_label_create(lv_screen_active());
41+
lv_label_set_text(label, "BLUE");
42+
lv_obj_set_style_text_color(label, lv_color_hex(0x0000ff), LV_PART_MAIN);
43+
lv_obj_align(label, LV_ALIGN_CENTER, 70, 20);
3244
}
3345

3446
int main(void)
3547
{
36-
int err;
3748
const struct device *display_dev;
38-
struct display_capabilities display_caps;
3949

4050
display_dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_display));
4151
if (!device_is_ready(display_dev)) {
4252
LOG_ERR("Device not ready, aborting test");
4353
return -ENODEV;
4454
}
4555

46-
display_get_capabilities(display_dev, &display_caps);
47-
if (!(display_caps.supported_pixel_formats & PIXEL_FORMAT_ARGB_8888)) {
48-
LOG_ERR("Display does not support ARGB8888 mode");
49-
return -ENOTSUP;
50-
}
51-
52-
if (PIXEL_FORMAT_ARGB_8888 != display_caps.current_pixel_format) {
53-
err = display_set_pixel_format(display_dev, PIXEL_FORMAT_ARGB_8888);
54-
if (err != 0) {
55-
LOG_ERR("Failed to set ARGB8888 pixel format");
56-
return err;
57-
}
58-
}
59-
6056
initialize_gui();
6157

6258
lv_timer_handler();

0 commit comments

Comments
 (0)