text: /*
   * Copyright (c) 2006-2021, RT-Thread Development Team
   *
   * SPDX-License-Identifier: Apache-2.0
   *
   * Change Logs:
   * Date           Author        Notes
   * 2021-10-17     Meco Man      First version
   */
  #include <rtthread.h>
  #include <lvgl.h>
  #define DBG_TAG    "LVGL"
  #define DBG_LVL    DBG_INFO
  #include <rtdbg.h>
  #include <drv_lcd.h>
  #include <lv_port_indev.h>
  
  #ifndef LV_THREAD_STACK_SIZE
  #define LV_THREAD_STACK_SIZE 4096
  #endif
  
  #ifndef LV_THREAD_PRIO
  #define LV_THREAD_PRIO (RT_THREAD_PRIORITY_MAX*2/3)
  #endif
  
  static void event_handler(lv_event_t * e)
  {
      lv_event_code_t code = lv_event_get_code(e);
      lv_obj_t * obj = lv_event_get_current_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, 0);
      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(calendar);
  #elif LV_USE_CALENDAR_HEADER_ARROW
      lv_calendar_header_arrow_create(calendar);
  #endif
      lv_calendar_set_showed_date(calendar, 2021, 10);
  }
  
  static void lvgl_thread(void *parameter)
  {
      /*assign buttons to coordinates*/
      const lv_point_t points_array[] =  {{200,35},{0,0},{70,35},{0,0}};
      lv_indev_set_button_points(button_indev, points_array);
  
      lv_example_calendar_1();
  
      while(1)
      {
          lv_task_handler();
          rt_thread_mdelay(10);
      }
  }
  
  static int lvgl_demo_init(void)
  {
      rt_thread_t tid;
  
      tid = rt_thread_create("LVGL", lvgl_thread, RT_NULL, LV_THREAD_STACK_SIZE, LV_THREAD_PRIO, 0);
      if(tid == RT_NULL)
      {
          LOG_E("Fail to create 'LVGL' thread");
      }
      rt_thread_startup(tid);
  
      return 0;
  }
  INIT_APP_EXPORT(lvgl_demo_init);
  