
jeu pacman
Dependencies: BSP_DISCO_F746NG
main.cpp
- Committer:
- JohnnyK
- Date:
- 2021-04-24
- Revision:
- 3:4f5dc253eb7b
- Parent:
- 2:afc050526249
- Child:
- 5:071136c3eefa
File content as of revision 3:4f5dc253eb7b:
//Notebook page https://os.mbed.com/users/JohnnyK/notebook/how-start-with-the-littlevgl/ #include "mbed.h" #include "lvgl/lvgl.h" #include "hal_stm_lvgl/tft/tft.h" #include "hal_stm_lvgl/touchpad/touchpad.h" #include "lv_examples.h" /*Comment/uncomment will switch between LVGL demo and Hello word example*/ #define LVGL_TICK 10 //Time tick value for lvgl in ms (1-10msa) #define TICKER_TIME 10ms //modified to miliseconds Ticker ticker; //Ticker for lvgl //Callback function for lvgl timing. void lv_ticker_func(){ lv_tick_inc(LVGL_TICK); //Call lv_tick_inc(x) every x milliseconds in a Timer or Task (x should be between 1 and 10). //It is required for the internal timing of LittlevGL. } #ifndef LV_EXAMPLES_H static void event_handler(lv_obj_t * obj, lv_event_t event) { if(event == LV_EVENT_CLICKED) { printf("Clicked\n"); } else if(event == LV_EVENT_VALUE_CHANGED) { printf("Toggled\n"); } } #endif // main() runs in its own thread in the OS int main() { printf("LVGL-"); lv_init(); //Initialize the LVGL tft_init(); //Initialize diplay touchpad_init(); //Initialize touchpad ticker.attach(callback(&lv_ticker_func),TICKER_TIME); //Attach callback to ticker #ifdef LV_EXAMPLES_H printf("Demo\n"); lv_demo_widgets(); #else printf("Hello world\n"); lv_obj_t * label1 = lv_label_create(lv_scr_act(), NULL); lv_label_set_long_mode(label1, LV_LABEL_LONG_BREAK); /*Break the long lines*/ lv_label_set_recolor(label1, true); /*Enable re-coloring by commands in the text*/ lv_label_set_align(label1, LV_LABEL_ALIGN_CENTER); /*Center aligned lines*/ lv_label_set_text(label1, "#0000ff Hello# #ff00ff world# #ff0000 - the LVGL and MbedOS#"); lv_obj_set_width(label1, 150); lv_obj_align(label1, NULL, LV_ALIGN_IN_TOP_MID, 0, 20); lv_obj_t * label2 = lv_label_create(lv_scr_act(), NULL); lv_label_set_long_mode(label2, LV_LABEL_LONG_SROLL_CIRC); /*Circular scroll*/ lv_obj_set_width(label2, 150); lv_label_set_text(label2, "It is a circularly scrolling text. "); lv_obj_align(label2, NULL, LV_ALIGN_IN_BOTTOM_MID, 0, 0); lv_obj_t * label; lv_obj_t * btn1 = lv_btn_create(lv_scr_act(), NULL); lv_obj_set_event_cb(btn1, event_handler); lv_obj_align(btn1, NULL, LV_ALIGN_CENTER, 0, -25); label = lv_label_create(btn1, NULL); lv_label_set_text(label, "Button"); lv_obj_t * btn2 = lv_btn_create(lv_scr_act(), NULL); lv_obj_set_event_cb(btn2, event_handler); lv_obj_align(btn2, NULL, LV_ALIGN_CENTER, 0, 25); lv_btn_set_checkable(btn2, true); lv_btn_toggle(btn2); lv_btn_set_fit2(btn2, LV_FIT_NONE, LV_FIT_TIGHT); label = lv_label_create(btn2, NULL); lv_label_set_text(label, "Toggled"); #endif while (true){ lv_task_handler(); //Call lv_task_handler() periodically every few milliseconds. //It will redraw the screen if required, handle input devices etc. thread_sleep_for(LVGL_TICK); } }