Hi @IvyHu ,
Looking at the code, you are probably using version 6.0 of the LVGL library, it might be worth updating if you can, here is a link to the latest repository.
I believe the problem is, you are calling the blocking sleep()
function in the event handler. It is not advisable to call blocking functions from the event handlers as it will prevent the LVGL scheduler from running for the duration of the sleep halting all screen drawing and LVGL processing etc.
To process this type of application you will need to restructure the way you code it. In your event handlers you need to be able to notify another thread of execution that something needs to be changed.
The way I would deal with this type of scenario would be to create a LVGL task function which executes every 50mS or so This would check a global queue of events received from various event handlers and executes the appropriate actions.
This is how to create a task:
lv_task_create((void*)process_gui_event, 50, LV_TASK_PRIO_LOW, NULL );
In the event handler again you must not call any blocking functions so for timed actions like your requirement, you will need to trigger and increment a static counter to simulate a sleep condition with that counter incrementing in 50mS increments each time the LVGL scheduler calls the task function. So in your posted example when you counter reaches 100 you would make your call to lv_gauge_set_value(gauge1, 1, i);
with you variable āiā also being static and incremented by each entry to the task function once the event is triggered. Obviously you will need a static flag(s) to keep track of the progress of the function also.
If you have plans to implement your application on a micro-controller later and have access to some form of OS on that platform this type of thing can normally be implemented quite easily and efficiently using queues/semaphores/mutexes if available from the OS.
I hope this makes sense, and is helpful.
Kind Regards,
Pete