unl0kr: optimize the main loop
This commit is contained in:
@@ -21,6 +21,7 @@ If a change only affects particular applications, they are listed in parentheses
|
|||||||
- feat(buffyboard): Add a buffyboard.service systemd service (!34, @uninsane)
|
- feat(buffyboard): Add a buffyboard.service systemd service (!34, @uninsane)
|
||||||
- fix(unl0kr): Select an available DRM device instead of a hard-coded one (!35, thanks @Sorcus)
|
- fix(unl0kr): Select an available DRM device instead of a hard-coded one (!35, thanks @Sorcus)
|
||||||
- feat(unl0kr): Enable software rotation (!32, thanks @xs5871 & @craftyguy)
|
- feat(unl0kr): Enable software rotation (!32, thanks @xs5871 & @craftyguy)
|
||||||
|
- misc(unl0kr): Optimize the main loop (!38, thanks @vstoiakin)
|
||||||
|
|
||||||
## 3.2.0 (2024-06-03)
|
## 3.2.0 (2024-06-03)
|
||||||
|
|
||||||
|
@@ -18,7 +18,6 @@
|
|||||||
|
|
||||||
#include "lvgl/lvgl.h"
|
#include "lvgl/lvgl.h"
|
||||||
|
|
||||||
#include <pthread.h>
|
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@@ -49,11 +48,9 @@ lv_obj_t *keyboard = NULL;
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function to invoke in the tick generation thread.
|
* Provides the number of milliseconds for LVGL timers
|
||||||
*
|
|
||||||
* @param args unused
|
|
||||||
*/
|
*/
|
||||||
static void *tick_thread (void *args);
|
static uint32_t millis();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle LV_EVENT_CLICKED events from the theme toggle button.
|
* Handle LV_EVENT_CLICKED events from the theme toggle button.
|
||||||
@@ -201,13 +198,10 @@ static void sigaction_handler(int signum);
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
static void *tick_thread (void *args) {
|
static uint32_t millis() {
|
||||||
LV_UNUSED(args);
|
struct timespec ts;
|
||||||
while (1) {
|
clock_gettime(CLOCK_MONOTONIC, &ts);
|
||||||
usleep(5 * 1000); /* Sleep for 5 millisecond */
|
return ts.tv_sec * 1000 + ts.tv_nsec / 1000000;
|
||||||
lv_tick_inc(5); /* Tell LVGL that 5 milliseconds have elapsed */
|
|
||||||
}
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void toggle_theme_btn_clicked_cb(lv_event_t *event) {
|
static void toggle_theme_btn_clicked_cb(lv_event_t *event) {
|
||||||
@@ -380,6 +374,13 @@ int main(int argc, char *argv[]) {
|
|||||||
/* Announce ourselves */
|
/* Announce ourselves */
|
||||||
bbx_log(BBX_LOG_LEVEL_VERBOSE, "unl0kr %s", PROJECT_VERSION);
|
bbx_log(BBX_LOG_LEVEL_VERBOSE, "unl0kr %s", PROJECT_VERSION);
|
||||||
|
|
||||||
|
/* Check that we have access to the clock */
|
||||||
|
struct timespec ts;
|
||||||
|
if (clock_gettime(CLOCK_MONOTONIC, &ts) == -1) {
|
||||||
|
bbx_log(BBX_LOG_LEVEL_ERROR, "Unable to read the clock");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
/* Parse config files */
|
/* Parse config files */
|
||||||
ul_config_init_opts(&conf_opts);
|
ul_config_init_opts(&conf_opts);
|
||||||
ul_config_parse_file("/usr/share/unl0kr/unl0kr.conf", &conf_opts);
|
ul_config_parse_file("/usr/share/unl0kr/unl0kr.conf", &conf_opts);
|
||||||
@@ -399,10 +400,7 @@ int main(int argc, char *argv[]) {
|
|||||||
/* Initialise LVGL and set up logging callback */
|
/* Initialise LVGL and set up logging callback */
|
||||||
lv_init();
|
lv_init();
|
||||||
lv_log_register_print_cb(bbx_log_print_cb);
|
lv_log_register_print_cb(bbx_log_print_cb);
|
||||||
|
lv_tick_set_cb(millis);
|
||||||
/* Start the tick thread */
|
|
||||||
pthread_t ticker;
|
|
||||||
pthread_create(&ticker, NULL, tick_thread, NULL);
|
|
||||||
|
|
||||||
/* Initialise display */
|
/* Initialise display */
|
||||||
lv_display_t *disp = NULL;
|
lv_display_t *disp = NULL;
|
||||||
@@ -610,12 +608,19 @@ int main(int argc, char *argv[]) {
|
|||||||
/* Periodically run timer / task handler */
|
/* Periodically run timer / task handler */
|
||||||
uint32_t timeout = conf_opts.general.timeout * 1000; /* ms */
|
uint32_t timeout = conf_opts.general.timeout * 1000; /* ms */
|
||||||
while(1) {
|
while(1) {
|
||||||
if (!timeout || lv_disp_get_inactive_time(NULL) < timeout) {
|
uint32_t time_till_next = lv_timer_handler();
|
||||||
uint32_t time_till_next = lv_timer_handler();
|
|
||||||
usleep(time_till_next * 1000);
|
if (timeout != 0) {
|
||||||
} else if (timeout) {
|
uint32_t time_idle = lv_display_get_inactive_time(NULL);
|
||||||
shutdown();
|
if (time_idle >= timeout)
|
||||||
|
shutdown();
|
||||||
|
|
||||||
|
uint32_t time_till_shutdown = timeout - time_idle;
|
||||||
|
if (time_till_shutdown < time_till_next)
|
||||||
|
time_till_next = time_till_shutdown;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
usleep(time_till_next * 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
Reference in New Issue
Block a user