From a036d1e9a1d763eacd4c4e0c79386ac82e556049 Mon Sep 17 00:00:00 2001 From: Colin <colin@uninsane.org> Date: Sat, 5 Oct 2024 12:15:20 +0000 Subject: [PATCH] use OS sleep instead of polling to reduce CPU usage without this lvgl never releases the CPU, and just pegs one of the cores to 100%. see <https://github.com/lvgl/lvgl/blob/master/docs/porting/timer_handler.rst> --- buffyboard/main.c | 3 ++- unl0kr/main.c | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/buffyboard/main.c b/buffyboard/main.c index 26054f3..1fb634f 100644 --- a/buffyboard/main.c +++ b/buffyboard/main.c @@ -284,7 +284,8 @@ int main(int argc, char *argv[]) { /* Periodically run timer / task handler */ while(1) { - lv_timer_periodic_handler(); + uint32_t time_till_next = lv_timer_handler(); + usleep(time_till_next * 1000); } return 0; diff --git a/unl0kr/main.c b/unl0kr/main.c index e711e44..02da2f3 100644 --- a/unl0kr/main.c +++ b/unl0kr/main.c @@ -591,7 +591,8 @@ int main(int argc, char *argv[]) { uint32_t timeout = conf_opts.general.timeout * 1000; /* ms */ while(1) { if (!timeout || lv_disp_get_inactive_time(NULL) < timeout) { - lv_timer_periodic_handler(); + uint32_t time_till_next = lv_timer_handler(); + usleep(time_till_next * 1000); } else if (timeout) { shutdown(); } -- GitLab