/** * @file main * */ /********************* * INCLUDES *********************/ #define _DEFAULT_SOURCE /* needed for usleep() */ #include #include #define SDL_MAIN_HANDLED /*To fix SDL's "undefined reference to WinMain" \ issue*/ #include #include "lvgl/lvgl.h" #include "lv_drivers/display/monitor.h" #include "lv_drivers/indev/mouse.h" #include "lv_examples/lv_examples.h" /********************* * DEFINES *********************/ /*On OSX SDL needs different handling*/ #if defined(__APPLE__) && defined(TARGET_OS_MAC) #if __APPLE__ && TARGET_OS_MAC #define SDL_APPLE #endif #endif /********************** * TYPEDEFS **********************/ /********************** * STATIC PROTOTYPES **********************/ static void hal_init(void); static int tick_thread(void *data); static void memory_monitor(lv_task_t *param); /********************** * STATIC VARIABLES **********************/ lv_indev_t *kb_indev; /********************** * MACROS **********************/ /********************** * GLOBAL FUNCTIONS **********************/ #define MY_U_SYMBOL "\xe2\x84\x83" #define MY_U_SYMBOL2 "\u221a" int main(int argc, char **argv) { (void)argc; /*Unused*/ (void)argv; /*Unused*/ /*Initialize LittlevGL*/ lv_init(); /*Initialize the HAL (display, input devices, tick) for LittlevGL*/ hal_init(); static lv_style_t style1; static lv_style_t style2; lv_style_init(&style1); lv_style_init(&style2); LV_FONT_DECLARE(my_font_CH); lv_obj_t * label1 = lv_label_create(lv_scr_act(), NULL); lv_obj_t * label2 = lv_label_create(lv_scr_act(), NULL); lv_obj_add_style(label1, LV_OBJ_PART_MAIN, &style1); lv_obj_add_style(label2, LV_OBJ_PART_MAIN, &style2); lv_style_set_text_font(&style1, LV_STATE_DEFAULT, &my_font_CH); lv_style_set_text_font(&style2, LV_STATE_DEFAULT, &my_font_CH); lv_obj_set_style_local_text_color(label1, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_RED); lv_obj_set_style_local_text_color(label2, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_ORANGE); lv_label_set_text(label1, "测试√℃●"); char * xx="\u6D4B 试测测测测 试da√测试b℃●√c\uF00C"; lv_label_set_text(label2, xx); /* Position the main label */ lv_obj_align(label1, NULL, LV_ALIGN_CENTER, 0, 0); lv_obj_align(label2, NULL, LV_ALIGN_CENTER, 0, 12); //lv_demo_widgets(); //lv_ex_arc_1(); //lv_ex_arc_2(); //lv_ex_bar_1(); //lv_ex_btn_1(); //lv_ex_btn_2(); //lv_ex_btnmatrix_1(); //lv_ex_calendar_1(); //lv_ex_canvas_1(); //lv_ex_checkbox_1(); //lv_ex_chart_1(); //lv_ex_chart_2(); //lv_ex_cont_1(); //lv_ex_cpicker_1(); //lv_ex_dropdown_1(); //lv_ex_dropdown_2(); //lv_ex_gauge_1(); //lv_ex_img_1(); //lv_ex_img_2(); //lv_ex_img_3(); //lv_ex_imgbtn_1(); //lv_ex_keyboard_1(); //lv_ex_label_1(); //lv_ex_label_2(); //lv_ex_label_3(); //lv_ex_led_1(); //lv_ex_line_1(); //lv_ex_list_1(); //lv_ex_linemeter_1(); //lv_ex_msgbox_1(); //lv_ex_msgbox_2(); //lv_ex_obj_1(); //lv_ex_page_1(); //lv_ex_spinner_1(); //lv_ex_roller_1(); //lv_ex_slider_1(); //lv_ex_slider_2(); //lv_ex_spinbox_1(); //lv_ex_switch_1(); //lv_ex_textarea_1(); //lv_ex_textarea_2(); //lv_ex_objmask_2(); //lv_ex_objmask_1(); //lv_ex_table_1(); //lv_ex_tabview_1(); //lv_ex_tileview_1(); //lv_ex_win_1(); while (1) { /* Periodically call the lv_task handler. * It could be done in a timer interrupt or an OS task too.*/ lv_task_handler(); usleep(5 * 1000); #ifdef SDL_APPLE SDL_Event event; while (SDL_PollEvent(&event)) { #if USE_MOUSE != 0 mouse_handler(&event); #endif #if USE_KEYBOARD keyboard_handler(&event); #endif #if USE_MOUSEWHEEL != 0 mousewheel_handler(&event); #endif } #endif } return 0; } /********************** * STATIC FUNCTIONS **********************/ /** * Initialize the Hardware Abstraction Layer (HAL) for the Littlev graphics * library */ static void hal_init(void) { /* Use the 'monitor' driver which creates window on PC's monitor to simulate a display*/ monitor_init(); /*Create a display buffer*/ static lv_disp_buf_t disp_buf1; static lv_color_t buf1_1[LV_HOR_RES_MAX * 300]; lv_disp_buf_init(&disp_buf1, buf1_1, NULL, LV_HOR_RES_MAX * 300); /*Create a display*/ lv_disp_drv_t disp_drv; lv_disp_drv_init(&disp_drv); /*Basic initialization*/ disp_drv.buffer = &disp_buf1; disp_drv.flush_cb = monitor_flush; lv_disp_drv_register(&disp_drv); /* Add the mouse as input device * Use the 'mouse' driver which reads the PC's mouse*/ mouse_init(); lv_indev_drv_t indev_drv; lv_indev_drv_init(&indev_drv); /*Basic initialization*/ indev_drv.type = LV_INDEV_TYPE_POINTER; /*This function will be called periodically (by the library) to get the mouse position and state*/ indev_drv.read_cb = mouse_read; lv_indev_t *mouse_indev = lv_indev_drv_register(&indev_drv); /*Set a cursor for the mouse*/ LV_IMG_DECLARE(mouse_cursor_icon); /*Declare the image file.*/ // lv_obj_t * cursor_obj = lv_img_create(lv_scr_act(), NULL); /*Create an image object for the cursor */ // lv_img_set_src(cursor_obj, &mouse_cursor_icon); /*Set the image source*/ // lv_indev_set_cursor(mouse_indev, cursor_obj); /*Connect the image object to the driver*/ /* Tick init. * You have to call 'lv_tick_inc()' in periodically to inform LittelvGL about * how much time were elapsed Create an SDL thread to do this*/ SDL_CreateThread(tick_thread, "tick", NULL); /* Optional: * Create a memory monitor task which prints the memory usage in * periodically.*/ lv_task_create(memory_monitor, 5000, LV_TASK_PRIO_MID, NULL); } /** * A task to measure the elapsed time for LittlevGL * @param data unused * @return never return */ static int tick_thread(void *data) { (void)data; while (1) { SDL_Delay(5); /*Sleep for 5 millisecond*/ lv_tick_inc(5); /*Tell LittelvGL that 5 milliseconds were elapsed*/ } return 0; } /** * Print the memory usage periodically * @param param */ static void memory_monitor(lv_task_t *param) { (void)param; /*Unused*/ lv_mem_monitor_t mon; lv_mem_monitor(&mon); printf("used: %6d (%3d %%), frag: %3d %%, biggest free: %6d\n", (int)mon.total_size - mon.free_size, mon.used_pct, mon.frag_pct, (int)mon.free_biggest_size); }