Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define CONFIG_TFT_HEIGHT 240 // usally defind in kconfig or whatever
- #define CONFIG_TFT_WIDTH 240 // usally defind in kconfig or whatever
- #define DRAW_BUF_SIZE (CONFIG_TFT_WIDTH * CONFIG_TFT_HEIGHT / 10 * (LV_COLOR_DEPTH / 8)) // 1/10th buffer size is min required
- static uint32_t my_tick_get_cb(void) { // Tells LVGL how long the program has been running
- return millis(); // for esp-idf use `esp_timer_get_time() / 1000;` instead
- }
- 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
- uint32_t w = (area->x2 - area->x1 + 1);
- uint32_t h = (area->y2 - area->y1 + 1);
- // Draw buffer into "area->x1, area->y1, w, h"
- lv_disp_flush_ready(disp);
- }
- void init_lvgl() {
- lv_init();
- lv_tick_set_cb(my_tick_get_cb);
- uint8_t* draw_buf = (uint8_t*)malloc(DRAW_BUF_SIZE);
- lv_display_t * disp;
- disp = lv_display_create(CONFIG_TFT_HEIGHT, CONFIG_TFT_WIDTH);
- lv_display_set_flush_cb(disp, (lv_display_flush_cb_t)my_disp_flush);
- lv_display_set_buffers(disp, draw_buf, NULL, DRAW_BUF_SIZE, LV_DISPLAY_RENDER_MODE_PARTIAL);
- lv_indev_t * indev = lv_indev_create();
- lv_indev_set_type(indev, LV_INDEV_TYPE_POINTER); /*Touchpad should have POINTER type*/
- }
- void app_main() {
- init_lvgl();
- lv_obj_t * spinner_screen = lv_obj_create(NULL); // Create an emtpy screen (like a div in HTML)
- lv_obj_set_size(spinner_screen, CONFIG_TFT_HEIGHT, CONFIG_TFT_WIDTH); // set size so it take up whole display
- lv_obj_set_pos(spinner_screen, 0, 0); // Set the top-left of the screen to the top-left of the display
- lv_obj_t * spinner = lv_spinner_create(spinner_screen); // Create a spinner widget with the `spinner_screen` as a parent
- lv_obj_set_size(spinner, 100, 100);
- lv_obj_center(spinner); // Center the spinner inside the parent
- 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)
- lv_obj_t * label_screen = lv_obj_create(NULL);
- lv_obj_set_size(label_screen, CONFIG_TFT_HEIGHT, CONFIG_TFT_WIDTH);
- lv_obj_set_pos(label_screen, 0, 0);
- lv_obj_t * label = lv_label_create(label_screen);
- lv_label_set_text(label, "HELLO WORLD!");
- lv_obj_set_width(label, 150);
- lv_obj_set_style_text_align(label, LV_TEXT_ALIGN_CENTER, 0);
- lv_obj_align(label, LV_ALIGN_CENTER, 0, -40);
- lv_screen_load(spinner_screen);
- bool switch_screen_flag = true;
- while (true) {
- lv_timer_handler(); /* let the UI do its work */
- vTaskDelay( 10 ); // `delay` for arduino
- if (switch_screen_flag && millis() > 5000) {
- switch_screen_flag = false;
- // Load the label screen after 5s of run time, by fading it in for 1s.
- 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)
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement