From 452fbf850a4f40e5940be83764ba0337c2f60106 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Sat, 23 Oct 2021 01:58:56 -0400 Subject: [PATCH] [lvgl][stm32l475] update demo --- .../board/ports/lvgl/lv_conf.h | 1 + .../board/ports/lvgl/lv_demo.c | 61 +++++++++++++------ 2 files changed, 44 insertions(+), 18 deletions(-) diff --git a/bsp/stm32/stm32l475-atk-pandora/board/ports/lvgl/lv_conf.h b/bsp/stm32/stm32l475-atk-pandora/board/ports/lvgl/lv_conf.h index c3ff474e58..c89b3a740f 100644 --- a/bsp/stm32/stm32l475-atk-pandora/board/ports/lvgl/lv_conf.h +++ b/bsp/stm32/stm32l475-atk-pandora/board/ports/lvgl/lv_conf.h @@ -12,5 +12,6 @@ #define LV_CONF_H #define LV_COLOR_16_SWAP 1 +#define LV_USE_PERF_MONITOR 1 #endif diff --git a/bsp/stm32/stm32l475-atk-pandora/board/ports/lvgl/lv_demo.c b/bsp/stm32/stm32l475-atk-pandora/board/ports/lvgl/lv_demo.c index 3f8865e982..01536328b8 100644 --- a/bsp/stm32/stm32l475-atk-pandora/board/ports/lvgl/lv_demo.c +++ b/bsp/stm32/stm32l475-atk-pandora/board/ports/lvgl/lv_demo.c @@ -12,7 +12,7 @@ #define DBG_TAG "LVGL" #define DBG_LVL DBG_INFO #include - +#include #include #ifndef LV_THREAD_STACK_SIZE @@ -23,34 +23,59 @@ #define LV_THREAD_PRIO (RT_THREAD_PRIORITY_MAX*2/3) #endif -static void btn_event_cb(lv_event_t * e) +static void event_handler(lv_event_t * e) { lv_event_code_t code = lv_event_get_code(e); - lv_obj_t * btn = lv_event_get_target(e); - if(code == LV_EVENT_CLICKED) { - static uint8_t cnt = 0; - cnt++; + lv_obj_t * obj = lv_event_get_target(e); - /*Get the first child of the button which is the label and change its text*/ - lv_obj_t * label = lv_obj_get_child(btn, 0); - lv_label_set_text_fmt(label, "WK_UP: %d", cnt); + if(code == LV_EVENT_VALUE_CHANGED) { + lv_calendar_date_t date; + if(lv_calendar_get_pressed_date(obj, &date)) { + LV_LOG_USER("Clicked date: %02d.%02d.%d", date.day, date.month, date.year); + } } } +void lv_example_calendar_1(void) +{ + lv_obj_t * calendar = lv_calendar_create(lv_scr_act()); + lv_obj_set_size(calendar, LCD_W, LCD_H); + lv_obj_align(calendar, LV_ALIGN_CENTER, 0, 60); + lv_obj_add_event_cb(calendar, event_handler, LV_EVENT_ALL, NULL); + + lv_calendar_set_today_date(calendar, 2021, 02, 23); + lv_calendar_set_showed_date(calendar, 2021, 02); + + /*Highlight a few days*/ + static lv_calendar_date_t highlighted_days[3]; /*Only its pointer will be saved so should be static*/ + highlighted_days[0].year = 2021; + highlighted_days[0].month = 02; + highlighted_days[0].day = 6; + + highlighted_days[1].year = 2021; + highlighted_days[1].month = 02; + highlighted_days[1].day = 11; + + highlighted_days[2].year = 2022; + highlighted_days[2].month = 02; + highlighted_days[2].day = 22; + + lv_calendar_set_highlighted_dates(calendar, highlighted_days, 3); + +#if LV_USE_CALENDAR_HEADER_DROPDOWN + lv_calendar_header_dropdown_create(lv_scr_act(), calendar); +#elif LV_USE_CALENDAR_HEADER_ARROW + lv_calendar_header_arrow_create(lv_scr_act(), calendar, 25); +#endif +} + static void lvgl_thread(void *parameter) { /*assign buttons to coordinates*/ - const lv_point_t points_array[] = {{0,0},{0,0},{0,0},{70,35}}; + const lv_point_t points_array[] = {{200,35},{0,0},{70,35},{0,0}}; lv_indev_set_button_points(button_indev, points_array); - lv_obj_t * btn = lv_btn_create(lv_scr_act()); /*Add a button the current screen*/ - lv_obj_set_pos(btn, 10, 10); /*Set its position*/ - lv_obj_set_size(btn, 120, 50); /*Set its size*/ - lv_obj_add_event_cb(btn, btn_event_cb, LV_EVENT_ALL, NULL); /*Assign a callback to the button*/ - - lv_obj_t * label = lv_label_create(btn); /*Add a label to the button*/ - lv_label_set_text(label, "WK_UP: 0"); /*Set the labels text*/ - lv_obj_center(label); + lv_example_calendar_1(); while(1) {