
jeu pacman
Dependencies: BSP_DISCO_F746NG
main.cpp@3:4f5dc253eb7b, 2021-04-24 (annotated)
- Committer:
- JohnnyK
- Date:
- Sat Apr 24 19:08:28 2021 +0000
- Revision:
- 3:4f5dc253eb7b
- Parent:
- 2:afc050526249
- Child:
- 5:071136c3eefa
Rework to LVGL 7.10.1 and MbedOS 6.10
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
JohnnyK | 2:afc050526249 | 1 | //Notebook page https://os.mbed.com/users/JohnnyK/notebook/how-start-with-the-littlevgl/ |
JohnnyK | 0:10c4b83c458d | 2 | #include "mbed.h" |
JohnnyK | 0:10c4b83c458d | 3 | #include "lvgl/lvgl.h" |
JohnnyK | 3:4f5dc253eb7b | 4 | #include "hal_stm_lvgl/tft/tft.h" |
JohnnyK | 3:4f5dc253eb7b | 5 | #include "hal_stm_lvgl/touchpad/touchpad.h" |
JohnnyK | 3:4f5dc253eb7b | 6 | #include "lv_examples.h" /*Comment/uncomment will switch between LVGL demo and Hello word example*/ |
JohnnyK | 0:10c4b83c458d | 7 | |
JohnnyK | 3:4f5dc253eb7b | 8 | #define LVGL_TICK 10 //Time tick value for lvgl in ms (1-10msa) |
JohnnyK | 3:4f5dc253eb7b | 9 | #define TICKER_TIME 10ms //modified to miliseconds |
JohnnyK | 0:10c4b83c458d | 10 | |
JohnnyK | 3:4f5dc253eb7b | 11 | Ticker ticker; //Ticker for lvgl |
JohnnyK | 3:4f5dc253eb7b | 12 | |
JohnnyK | 0:10c4b83c458d | 13 | //Callback function for lvgl timing. |
JohnnyK | 0:10c4b83c458d | 14 | void lv_ticker_func(){ |
JohnnyK | 0:10c4b83c458d | 15 | lv_tick_inc(LVGL_TICK); |
JohnnyK | 0:10c4b83c458d | 16 | //Call lv_tick_inc(x) every x milliseconds in a Timer or Task (x should be between 1 and 10). |
JohnnyK | 0:10c4b83c458d | 17 | //It is required for the internal timing of LittlevGL. |
JohnnyK | 0:10c4b83c458d | 18 | } |
JohnnyK | 0:10c4b83c458d | 19 | |
JohnnyK | 3:4f5dc253eb7b | 20 | #ifndef LV_EXAMPLES_H |
JohnnyK | 3:4f5dc253eb7b | 21 | static void event_handler(lv_obj_t * obj, lv_event_t event) |
JohnnyK | 3:4f5dc253eb7b | 22 | { |
JohnnyK | 3:4f5dc253eb7b | 23 | if(event == LV_EVENT_CLICKED) { |
JohnnyK | 3:4f5dc253eb7b | 24 | printf("Clicked\n"); |
JohnnyK | 3:4f5dc253eb7b | 25 | } |
JohnnyK | 3:4f5dc253eb7b | 26 | else if(event == LV_EVENT_VALUE_CHANGED) { |
JohnnyK | 3:4f5dc253eb7b | 27 | printf("Toggled\n"); |
JohnnyK | 0:10c4b83c458d | 28 | } |
JohnnyK | 1:627f26953c53 | 29 | } |
JohnnyK | 3:4f5dc253eb7b | 30 | #endif |
JohnnyK | 3:4f5dc253eb7b | 31 | // main() runs in its own thread in the OS |
JohnnyK | 0:10c4b83c458d | 32 | int main() |
JohnnyK | 0:10c4b83c458d | 33 | { |
JohnnyK | 3:4f5dc253eb7b | 34 | printf("LVGL-"); |
JohnnyK | 3:4f5dc253eb7b | 35 | lv_init(); //Initialize the LVGL |
JohnnyK | 3:4f5dc253eb7b | 36 | tft_init(); //Initialize diplay |
JohnnyK | 3:4f5dc253eb7b | 37 | touchpad_init(); //Initialize touchpad |
JohnnyK | 3:4f5dc253eb7b | 38 | ticker.attach(callback(&lv_ticker_func),TICKER_TIME); //Attach callback to ticker |
JohnnyK | 3:4f5dc253eb7b | 39 | |
JohnnyK | 3:4f5dc253eb7b | 40 | #ifdef LV_EXAMPLES_H |
JohnnyK | 3:4f5dc253eb7b | 41 | printf("Demo\n"); |
JohnnyK | 3:4f5dc253eb7b | 42 | lv_demo_widgets(); |
JohnnyK | 3:4f5dc253eb7b | 43 | #else |
JohnnyK | 3:4f5dc253eb7b | 44 | printf("Hello world\n"); |
JohnnyK | 3:4f5dc253eb7b | 45 | lv_obj_t * label1 = lv_label_create(lv_scr_act(), NULL); |
JohnnyK | 3:4f5dc253eb7b | 46 | lv_label_set_long_mode(label1, LV_LABEL_LONG_BREAK); /*Break the long lines*/ |
JohnnyK | 3:4f5dc253eb7b | 47 | lv_label_set_recolor(label1, true); /*Enable re-coloring by commands in the text*/ |
JohnnyK | 3:4f5dc253eb7b | 48 | lv_label_set_align(label1, LV_LABEL_ALIGN_CENTER); /*Center aligned lines*/ |
JohnnyK | 3:4f5dc253eb7b | 49 | lv_label_set_text(label1, "#0000ff Hello# #ff00ff world# #ff0000 - the LVGL and MbedOS#"); |
JohnnyK | 3:4f5dc253eb7b | 50 | lv_obj_set_width(label1, 150); |
JohnnyK | 3:4f5dc253eb7b | 51 | lv_obj_align(label1, NULL, LV_ALIGN_IN_TOP_MID, 0, 20); |
JohnnyK | 3:4f5dc253eb7b | 52 | |
JohnnyK | 3:4f5dc253eb7b | 53 | lv_obj_t * label2 = lv_label_create(lv_scr_act(), NULL); |
JohnnyK | 3:4f5dc253eb7b | 54 | lv_label_set_long_mode(label2, LV_LABEL_LONG_SROLL_CIRC); /*Circular scroll*/ |
JohnnyK | 3:4f5dc253eb7b | 55 | lv_obj_set_width(label2, 150); |
JohnnyK | 3:4f5dc253eb7b | 56 | lv_label_set_text(label2, "It is a circularly scrolling text. "); |
JohnnyK | 3:4f5dc253eb7b | 57 | lv_obj_align(label2, NULL, LV_ALIGN_IN_BOTTOM_MID, 0, 0); |
JohnnyK | 0:10c4b83c458d | 58 | |
JohnnyK | 0:10c4b83c458d | 59 | lv_obj_t * label; |
JohnnyK | 0:10c4b83c458d | 60 | lv_obj_t * btn1 = lv_btn_create(lv_scr_act(), NULL); |
JohnnyK | 0:10c4b83c458d | 61 | lv_obj_set_event_cb(btn1, event_handler); |
JohnnyK | 3:4f5dc253eb7b | 62 | lv_obj_align(btn1, NULL, LV_ALIGN_CENTER, 0, -25); |
JohnnyK | 0:10c4b83c458d | 63 | label = lv_label_create(btn1, NULL); |
JohnnyK | 0:10c4b83c458d | 64 | lv_label_set_text(label, "Button"); |
JohnnyK | 3:4f5dc253eb7b | 65 | lv_obj_t * btn2 = lv_btn_create(lv_scr_act(), NULL); |
JohnnyK | 0:10c4b83c458d | 66 | lv_obj_set_event_cb(btn2, event_handler); |
JohnnyK | 3:4f5dc253eb7b | 67 | lv_obj_align(btn2, NULL, LV_ALIGN_CENTER, 0, 25); |
JohnnyK | 3:4f5dc253eb7b | 68 | lv_btn_set_checkable(btn2, true); |
JohnnyK | 0:10c4b83c458d | 69 | lv_btn_toggle(btn2); |
JohnnyK | 0:10c4b83c458d | 70 | lv_btn_set_fit2(btn2, LV_FIT_NONE, LV_FIT_TIGHT); |
JohnnyK | 0:10c4b83c458d | 71 | label = lv_label_create(btn2, NULL); |
JohnnyK | 0:10c4b83c458d | 72 | lv_label_set_text(label, "Toggled"); |
JohnnyK | 3:4f5dc253eb7b | 73 | #endif |
JohnnyK | 0:10c4b83c458d | 74 | |
JohnnyK | 3:4f5dc253eb7b | 75 | while (true){ |
JohnnyK | 3:4f5dc253eb7b | 76 | lv_task_handler(); |
JohnnyK | 3:4f5dc253eb7b | 77 | //Call lv_task_handler() periodically every few milliseconds. |
JohnnyK | 3:4f5dc253eb7b | 78 | //It will redraw the screen if required, handle input devices etc. |
JohnnyK | 3:4f5dc253eb7b | 79 | thread_sleep_for(LVGL_TICK); |
JohnnyK | 0:10c4b83c458d | 80 | } |
JohnnyK | 3:4f5dc253eb7b | 81 | } |