Advertisement
Guest User

Untitled

a guest
Jun 17th, 2025
5
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.14 KB | None | 0 0
  1. #define CONFIG_TFT_HEIGHT 240 // usally defind in kconfig or whatever
  2. #define CONFIG_TFT_WIDTH 240 // usally defind in kconfig or whatever
  3.  
  4. #define DRAW_BUF_SIZE (CONFIG_TFT_WIDTH * CONFIG_TFT_HEIGHT / 10 * (LV_COLOR_DEPTH / 8)) // 1/10th buffer size is min required
  5.  
  6. static uint32_t my_tick_get_cb(void) { // Tells LVGL how long the program has been running
  7. return millis(); // for esp-idf use `esp_timer_get_time() / 1000;` instead
  8. }
  9.  
  10. void my_disp_flush(lv_display_t * disp, const lv_area_t *area, void * px_map) { // Lets LVGL draw onto an area of the display
  11. uint32_t w = (area->x2 - area->x1 + 1);
  12. uint32_t h = (area->y2 - area->y1 + 1);
  13.  
  14. // Draw buffer into "area->x1, area->y1, w, h"
  15.  
  16. lv_disp_flush_ready(disp);
  17. }
  18.  
  19. void init_lvgl() {
  20. lv_init();
  21. lv_tick_set_cb(my_tick_get_cb);
  22.  
  23. uint8_t* draw_buf = (uint8_t*)malloc(DRAW_BUF_SIZE);
  24. lv_display_t * disp;
  25. disp = lv_display_create(CONFIG_TFT_HEIGHT, CONFIG_TFT_WIDTH);
  26. lv_display_set_flush_cb(disp, (lv_display_flush_cb_t)my_disp_flush);
  27. lv_display_set_buffers(disp, draw_buf, NULL, DRAW_BUF_SIZE, LV_DISPLAY_RENDER_MODE_PARTIAL);
  28.  
  29. lv_indev_t * indev = lv_indev_create();
  30. lv_indev_set_type(indev, LV_INDEV_TYPE_POINTER); /*Touchpad should have POINTER type*/
  31. }
  32.  
  33. void app_main() {
  34. init_lvgl();
  35.  
  36. lv_obj_t * spinner_screen = lv_obj_create(NULL); // Create an emtpy screen (like a div in HTML)
  37. lv_obj_set_size(spinner_screen, CONFIG_TFT_HEIGHT, CONFIG_TFT_WIDTH); // set size so it take up whole display
  38. lv_obj_set_pos(spinner_screen, 0, 0); // Set the top-left of the screen to the top-left of the display
  39.  
  40. lv_obj_t * spinner = lv_spinner_create(spinner_screen); // Create a spinner widget with the `spinner_screen` as a parent
  41. lv_obj_set_size(spinner, 100, 100);
  42. lv_obj_center(spinner); // Center the spinner inside the parent
  43. lv_spinner_set_anim_params(spinner, 5000, 200); // Check docs for more info (https://docs.lvgl.io/9.2/API/widgets/spinner/lv_spinner.html#_CPPv426lv_spinner_set_anim_paramsP8lv_obj_t8uint32_t8uint32_t)
  44.  
  45. lv_obj_t * label_screen = lv_obj_create(NULL);
  46. lv_obj_set_size(label_screen, CONFIG_TFT_HEIGHT, CONFIG_TFT_WIDTH);
  47. lv_obj_set_pos(label_screen, 0, 0);
  48.  
  49. lv_obj_t * label = lv_label_create(label_screen);
  50. lv_label_set_text(label, "HELLO WORLD!");
  51. lv_obj_set_width(label, 150);
  52. lv_obj_set_style_text_align(label, LV_TEXT_ALIGN_CENTER, 0);
  53. lv_obj_align(label, LV_ALIGN_CENTER, 0, -40);
  54.  
  55. lv_screen_load(spinner_screen);
  56.  
  57. bool switch_screen_flag = true;
  58. while (true) {
  59. lv_timer_handler(); /* let the UI do its work */
  60. vTaskDelay( 10 ); // `delay` for arduino
  61.  
  62. if (switch_screen_flag && millis() > 5000) {
  63. switch_screen_flag = false;
  64.  
  65. // Load the label screen after 5s of run time, by fading it in for 1s.
  66. lv_screen_load_anim(label_screen, LV_SCR_LOAD_ANIM_FADE_IN, 1000, 0, false); // Check docs for more info (https://docs.lvgl.io/9.2/API/display/lv_display.html#_CPPv419lv_screen_load_animP8lv_obj_t21lv_screen_load_anim_t8uint32_t8uint32_tb)
  67. }
  68. }
  69.  
  70. }
  71.  
  72.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement