lv_demo.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. * Copyright (c) 2006-2021, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2021-10-17 Meco Man First version
  9. */
  10. #include <rtthread.h>
  11. #include <lvgl.h>
  12. #define DBG_TAG "LVGL"
  13. #define DBG_LVL DBG_INFO
  14. #include <rtdbg.h>
  15. #include <lcd_port.h>
  16. #include <lv_port_indev.h>
  17. #ifndef LV_THREAD_STACK_SIZE
  18. #define LV_THREAD_STACK_SIZE 4096
  19. #endif
  20. #ifndef LV_THREAD_PRIO
  21. #define LV_THREAD_PRIO (RT_THREAD_PRIORITY_MAX*2/3)
  22. #endif
  23. static void event_handler(lv_event_t * e)
  24. {
  25. lv_event_code_t code = lv_event_get_code(e);
  26. lv_obj_t * obj = lv_event_get_target(e);
  27. if(code == LV_EVENT_VALUE_CHANGED) {
  28. lv_calendar_date_t date;
  29. if(lv_calendar_get_pressed_date(obj, &date)) {
  30. LV_LOG_USER("Clicked date: %02d.%02d.%d", date.day, date.month, date.year);
  31. }
  32. }
  33. }
  34. void lv_example_calendar_1(void)
  35. {
  36. lv_obj_t * calendar = lv_calendar_create(lv_scr_act());
  37. lv_obj_set_size(calendar, LCD_WIDTH, LCD_HEIGHT);
  38. lv_obj_align(calendar, LV_ALIGN_CENTER, 0, 60);
  39. lv_obj_add_event_cb(calendar, event_handler, LV_EVENT_ALL, NULL);
  40. lv_calendar_set_today_date(calendar, 2021, 02, 23);
  41. lv_calendar_set_showed_date(calendar, 2021, 02);
  42. /*Highlight a few days*/
  43. static lv_calendar_date_t highlighted_days[3]; /*Only its pointer will be saved so should be static*/
  44. highlighted_days[0].year = 2021;
  45. highlighted_days[0].month = 02;
  46. highlighted_days[0].day = 6;
  47. highlighted_days[1].year = 2021;
  48. highlighted_days[1].month = 02;
  49. highlighted_days[1].day = 11;
  50. highlighted_days[2].year = 2022;
  51. highlighted_days[2].month = 02;
  52. highlighted_days[2].day = 22;
  53. lv_calendar_set_highlighted_dates(calendar, highlighted_days, 3);
  54. #if LV_USE_CALENDAR_HEADER_DROPDOWN
  55. lv_calendar_header_dropdown_create(lv_scr_act());
  56. #elif LV_USE_CALENDAR_HEADER_ARROW
  57. lv_calendar_header_arrow_create(lv_scr_act(), calendar, 25);
  58. #endif
  59. }
  60. static void lvgl_thread(void *parameter)
  61. {
  62. /*assign buttons to coordinates*/
  63. const lv_point_t points_array[] = {{200,35},{0,0},{70,35},{0,0}};
  64. lv_indev_set_button_points(button_indev, points_array);
  65. lv_example_calendar_1();
  66. while(1)
  67. {
  68. lv_task_handler();
  69. rt_thread_mdelay(10);
  70. }
  71. }
  72. static int lvgl_demo_init(void)
  73. {
  74. rt_thread_t tid;
  75. tid = rt_thread_create("LVGL", lvgl_thread, RT_NULL, LV_THREAD_STACK_SIZE, LV_THREAD_PRIO, 0);
  76. if(tid == RT_NULL)
  77. {
  78. LOG_E("Fail to create 'LVGL' thread");
  79. }
  80. rt_thread_startup(tid);
  81. return 0;
  82. }
  83. INIT_APP_EXPORT(lvgl_demo_init);