SystemAgent/src/tasks/user_lvgl_task.c

70 lines
1.4 KiB
C
Raw Normal View History

2021-03-14 07:00:33 +00:00
#include <stdint.h>
#include <unistd.h>
#include <pthread.h>
#include "lvgl.h"
2021-03-14 15:47:28 +00:00
#include "utils/user_log_util.h"
2021-03-14 07:00:33 +00:00
#include "tasks/user_tasks.h"
2021-03-21 16:01:12 +00:00
#include "impl/user_lvgl_impl.h"
2021-03-14 07:00:33 +00:00
extern uint8_t g_running;
pthread_t user_lv_task_thread;
pthread_t user_lv_tick_thread;
void *user_lv_task(void *arguments);
void *user_lv_tick(void *arguments);
int user_lvgl_task_init(void) {
int ret;
2021-03-21 16:01:12 +00:00
user_lvgl_impl_init();
2021-03-14 15:47:28 +00:00
USER_LOG(USER_LOG_INFO, "lv_init() called.");
2021-03-14 07:00:33 +00:00
lv_init();
ret = pthread_create(&user_lv_task_thread, NULL, user_lv_task, NULL);
if(ret) return ret;
ret = pthread_create(&user_lv_tick_thread, NULL, user_lv_tick, NULL);
if(ret) return ret;
2021-03-14 15:47:28 +00:00
USER_LOG(USER_LOG_INFO, "LVGL threads created.");
pthread_setname_np(user_lv_task_thread, "LV_TASK");
pthread_setname_np(user_lv_tick_thread, "LV_TICK");
2021-03-14 07:00:33 +00:00
}
int user_lvgl_task_deinit(void) {
2021-03-14 15:47:28 +00:00
USER_LOG(USER_LOG_INFO, "LVGL task_deinit() called.");
pthread_join(user_lv_task_thread, NULL);
pthread_join(user_lv_tick_thread, NULL);
USER_LOG(USER_LOG_INFO, "LVGL threads joined.");
2021-03-21 16:01:12 +00:00
user_lvgl_impl_deinit();
2021-03-14 07:00:33 +00:00
return 0;
}
void *user_lv_task(void *arguments) {
2021-03-14 15:47:28 +00:00
2021-03-14 07:00:33 +00:00
while(g_running) {
usleep(30 * 1000);
lv_task_handler();
}
return NULL;
}
void *user_lv_tick(void *arguments) {
while(g_running) {
usleep(30 * 1000);
lv_tick_inc(30);
}
return NULL;
}