#include #include #include #include #include #include #include #include "lvgl/lvgl.h" #define SDL_MAIN_HANDLED #include #define SDL_HOR_RES 800 #define SDL_VER_RES 480 #define DISP_BUF_SIZE (128 * 1024) #define UNUSED(p) (void)((p)) static const char *getenv_default(const char *name, const char *dflt); void _log_cb(lv_log_level_t level, const char *buf) { UNUSED(level); printf("%s", buf); fflush(stdout); } static const char *getenv_default(const char *name, const char *dflt) { return getenv(name) ? : dflt; } #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(); 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(); lv_linux_drm_set_file(disp, device, -1); } #elif LV_USE_SDL static void lv_linux_disp_init(void) { const int width = atoi(getenv("LV_SDL_VIDEO_WIDTH") ?: "800"); const int height = atoi(getenv("LV_SDL_VIDEO_HEIGHT") ?: "480"); lv_display_t *disp = lv_sdl_window_create(width, height); // lv_sdl_ linux_fbdev_set_file(display, "/dev/fb0"); lv_group_t *g = lv_group_create(); lv_group_set_default(g); lv_indev_t *mouse = lv_sdl_mouse_create(); lv_indev_set_group(mouse, lv_group_get_default()); lv_indev_t *mousewheel = lv_sdl_mousewheel_create(); lv_indev_set_group(mousewheel, lv_group_get_default()); lv_indev_t *keyboard = lv_sdl_keyboard_create(); lv_indev_set_group(keyboard, lv_group_get_default()); } #else #error Unsupported configuration #endif void lv_ex_draw_rect(void) { /* Maak een scherm */ lv_obj_t *scr = lv_scr_act(); /* Maak een rechthoek */ lv_obj_t *rect = lv_obj_create(scr); lv_obj_set_size(rect, 200, 100); // Stel de grootte in (breedte x hoogte) lv_obj_align(rect, LV_ALIGN_CENTER, 0, 0); // Plaats het in het midden van het scherm /* Stel de stijl van de rechthoek in (optioneel) */ lv_obj_set_style_bg_color(rect, lv_color_hex(0xFF0000), LV_PART_MAIN); // Stel de achtergrondkleur in op rood } int main(int argc, char *argv[]) { UNUSED(argc); UNUSED(argv); lv_init(); /* Linux display device init */ lv_linux_disp_init(); lv_log_register_print_cb(_log_cb); lv_fs_stdio_init(); lv_ex_draw_rect(); LV_LOG_USER("SDL driver set."); /*Handle LitlevGL tasks (tickless mode)*/ while (1) { // lv_tick_inc(5); lv_task_handler(); lv_timer_handler(); SDL_Delay(5); // usleep(5000); } return 0; }