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 c3ff474e5830e80f9e3109022a107a6756b15cfc..c89b3a740f46edca617657d624423c2f9a052a33 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 3f8865e982e0baaa485d82e0d7d0d7a27b987866..01536328b8be9a45f09f0ad70aa6f178c791e2e8 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++; - - /*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); + lv_obj_t * obj = lv_event_get_target(e); + + 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) {