Added background option test.
This commit is contained in:
parent
fbca0dd77e
commit
3f55e5da1d
|
@ -4,7 +4,28 @@
|
|||
#include "lvgl.h"
|
||||
|
||||
void user_lvgl_impl_init(void);
|
||||
void user_lvgl_impl_flush_cb(lv_disp_drv_t * disp_drv, const lv_area_t * area, lv_color_t * color_p);
|
||||
|
||||
void user_lvgl_impl_flush_cb(lv_disp_drv_t *disp_drv, const lv_area_t *area,
|
||||
lv_color_t *color_p);
|
||||
|
||||
void *user_lvgl_impl_fs_open_cb(lv_fs_drv_t *drv, const char *path,
|
||||
lv_fs_mode_t mode);
|
||||
|
||||
lv_fs_res_t user_lvgl_impl_fs_close_cb(lv_fs_drv_t *drv, void *file_p);
|
||||
|
||||
lv_fs_res_t user_lvgl_impl_fs_read_cb(lv_fs_drv_t *drv, void *file_p, void *buf,
|
||||
uint32_t btr, uint32_t *br);
|
||||
|
||||
lv_fs_res_t user_lvgl_impl_fs_write_cb(lv_fs_drv_t *drv, void *file_p,
|
||||
const void *buf, uint32_t btw,
|
||||
uint32_t *bw);
|
||||
|
||||
lv_fs_res_t user_lvgl_impl_fs_seek_cb(lv_fs_drv_t *drv, void *file_p,
|
||||
uint32_t pos, lv_fs_whence_t whence);
|
||||
|
||||
lv_fs_res_t user_lvgl_impl_fs_tell_cb(lv_fs_drv_t *drv, void *file_p,
|
||||
uint32_t *pos_p);
|
||||
|
||||
void user_lvgl_impl_deinit(void);
|
||||
|
||||
#endif
|
|
@ -1 +1 @@
|
|||
Subproject commit b0be98b771d6c2bd3452f16998a3897a047c4f30
|
||||
Subproject commit 93c56ceaa021dde3f22057dabaecdb9f4eddb5f1
|
|
@ -22,10 +22,20 @@ agent: {
|
|||
path = "/dev/gpiochip1";
|
||||
line = 230;
|
||||
};
|
||||
blk_pin: {
|
||||
backlight_pin: {
|
||||
path = "/dev/gpiochip1";
|
||||
line = 231;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
libraries: {
|
||||
lvgl: {
|
||||
fs_base = "";
|
||||
};
|
||||
};
|
||||
|
||||
theme: {
|
||||
background = "A:background.bin"
|
||||
};
|
||||
};
|
|
@ -1,8 +1,16 @@
|
|||
#include "impl/user_st7789_impl.h"
|
||||
#include <fcntl.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "drivers/user_config_driver.h"
|
||||
|
||||
#include "impl/user_lvgl_impl.h"
|
||||
#include "impl/user_st7789_impl.h"
|
||||
|
||||
#include "utils/user_log_util.h"
|
||||
|
||||
extern user_config_t g_config;
|
||||
|
||||
user_st7789_impl_t g_lcd_impl;
|
||||
st7789_lcd_t g_lcd = {
|
||||
.cb =
|
||||
|
@ -15,6 +23,8 @@ st7789_lcd_t g_lcd = {
|
|||
{
|
||||
.direction = ST7789_DIR_270,
|
||||
.pix_fmt = ST7789_RGB565,
|
||||
.bgr_mode = 0,
|
||||
.inversion = 0,
|
||||
},
|
||||
.user_data = &g_lcd_impl,
|
||||
};
|
||||
|
@ -24,11 +34,112 @@ void user_lvgl_impl_init(void) {
|
|||
st7789_lcd_init(&g_lcd);
|
||||
}
|
||||
|
||||
void user_lvgl_impl_flush_cb(lv_disp_drv_t * disp_drv, const lv_area_t * area, lv_color_t * color_p) {
|
||||
st7789_lcd_load(&g_lcd, (uint8_t *)color_p, area->x1, area->x2, area->y1, area->y2);
|
||||
void user_lvgl_impl_flush_cb(lv_disp_drv_t *disp_drv, const lv_area_t *area,
|
||||
lv_color_t *color_p) {
|
||||
st7789_lcd_load(&g_lcd, (uint8_t *)color_p, area->x1, area->x2, area->y1,
|
||||
area->y2);
|
||||
lv_disp_flush_ready(disp_drv);
|
||||
}
|
||||
|
||||
void *user_lvgl_impl_fs_open_cb(lv_fs_drv_t *drv, const char *path,
|
||||
lv_fs_mode_t mode) {
|
||||
char canonical_path[256];
|
||||
char *fs_base_dir =
|
||||
user_config_lookup_string(&g_config, "agent.libraries.lvgl.fs_base");
|
||||
if(fs_base_dir == NULL) {
|
||||
snprintf(canonical_path, 256, "%s", path);
|
||||
} else {
|
||||
snprintf(canonical_path, 256, "%s/%s", fs_base_dir, path);
|
||||
}
|
||||
|
||||
int oflag = (mode == LV_FS_MODE_RD) ? O_RDONLY : O_RDWR;
|
||||
|
||||
int fd = open(canonical_path, oflag);
|
||||
if(fd < 0) return NULL;
|
||||
|
||||
int *ret = malloc(sizeof(fd));
|
||||
if(ret != NULL) *ret = fd;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
lv_fs_res_t user_lvgl_impl_fs_close_cb(lv_fs_drv_t *drv, void *file_p) {
|
||||
int fd = *(int *)file_p;
|
||||
|
||||
if(fd > 0) {
|
||||
free(file_p);
|
||||
close(fd);
|
||||
return LV_FS_RES_OK;
|
||||
}
|
||||
return LV_FS_RES_FS_ERR;
|
||||
}
|
||||
|
||||
lv_fs_res_t user_lvgl_impl_fs_read_cb(lv_fs_drv_t *drv, void *file_p, void *buf,
|
||||
uint32_t btr, uint32_t *br) {
|
||||
int fd = *(int *)file_p;
|
||||
|
||||
if(fd > 0) {
|
||||
*br = read(fd, buf, btr);
|
||||
if(*br < 0) return LV_FS_RES_FS_ERR;
|
||||
return LV_FS_RES_OK;
|
||||
}
|
||||
|
||||
return LV_FS_RES_FS_ERR;
|
||||
}
|
||||
|
||||
lv_fs_res_t user_lvgl_impl_fs_write_cb(lv_fs_drv_t *drv, void *file_p,
|
||||
const void *buf, uint32_t btw,
|
||||
uint32_t *bw) {
|
||||
int fd = *(int *)file_p;
|
||||
|
||||
if(fd > 0) {
|
||||
*bw = write(fd, buf, btw);
|
||||
if(*bw < 0) return LV_FS_RES_FS_ERR;
|
||||
return LV_FS_RES_OK;
|
||||
}
|
||||
|
||||
return LV_FS_RES_FS_ERR;
|
||||
}
|
||||
|
||||
lv_fs_res_t user_lvgl_impl_fs_seek_cb(lv_fs_drv_t *drv, void *file_p,
|
||||
uint32_t pos, lv_fs_whence_t whence) {
|
||||
int fd = *(int *)file_p;
|
||||
|
||||
int l_whence = SEEK_SET;
|
||||
switch(whence) {
|
||||
case LV_FS_SEEK_CUR:
|
||||
l_whence = SEEK_CUR;
|
||||
break;
|
||||
case LV_FS_SEEK_END:
|
||||
l_whence = SEEK_END;
|
||||
break;
|
||||
case LV_FS_SEEK_SET:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if(fd > 0) {
|
||||
int new_offset = lseek(fd, pos, l_whence);
|
||||
if(new_offset < 0) return LV_FS_RES_FS_ERR;
|
||||
return LV_FS_RES_OK;
|
||||
}
|
||||
|
||||
return LV_FS_RES_FS_ERR;
|
||||
}
|
||||
|
||||
lv_fs_res_t user_lvgl_impl_fs_tell_cb(lv_fs_drv_t *drv, void *file_p,
|
||||
uint32_t *pos_p) {
|
||||
int fd = *(int *)file_p;
|
||||
|
||||
if(fd > 0) {
|
||||
*pos_p = lseek(fd, 0, LV_FS_SEEK_CUR);
|
||||
if(*pos_p < 0) return LV_FS_RES_FS_ERR;
|
||||
return LV_FS_RES_OK;
|
||||
}
|
||||
|
||||
return LV_FS_RES_FS_ERR;
|
||||
}
|
||||
|
||||
void user_lvgl_impl_deinit(void) {
|
||||
st7789_lcd_display(&g_lcd, 0);
|
||||
user_st7789_impl_deinit(&g_lcd_impl);
|
||||
|
|
|
@ -5,10 +5,13 @@
|
|||
|
||||
#include "lvgl.h"
|
||||
|
||||
#include "drivers/user_config_driver.h"
|
||||
|
||||
#include "utils/user_log_util.h"
|
||||
|
||||
extern uint8_t g_running;
|
||||
extern uint8_t g_lvgl_ready;
|
||||
extern user_config_t g_config;
|
||||
|
||||
pthread_t user_clock_task_thread;
|
||||
|
||||
|
@ -39,21 +42,14 @@ void *user_clock_task(void *arguments) {
|
|||
while(g_running && !g_lvgl_ready) {
|
||||
sleep(1);
|
||||
}
|
||||
lv_obj_t * label1 = lv_label_create(lv_scr_act());
|
||||
lv_label_set_long_mode(label1, LV_LABEL_LONG_WRAP); /*Break the long lines*/
|
||||
lv_label_set_recolor(label1, true); /*Enable re-coloring by commands in the text*/
|
||||
lv_label_set_text(label1, "#0000ff Re-color# #ff00ff words# #ff0000 of a# label, align the lines to the center "
|
||||
"and wrap long text automatically.");
|
||||
lv_obj_set_width(label1, 150); /*Set smaller width to make the lines wrap*/
|
||||
lv_obj_set_style_text_align(label1, LV_TEXT_ALIGN_CENTER, 0);
|
||||
lv_obj_align(label1, LV_ALIGN_CENTER, 0, -40);
|
||||
|
||||
char *background_path = user_config_lookup_string(&g_config, "agent.theme.background");
|
||||
|
||||
lv_obj_t * bg_image = lv_img_create(lv_scr_act());
|
||||
if(background_path != NULL) {
|
||||
lv_img_set_src(bg_image, background_path);
|
||||
}
|
||||
|
||||
lv_obj_t * label2 = lv_label_create(lv_scr_act());
|
||||
lv_label_set_long_mode(label2, LV_LABEL_LONG_SCROLL_CIRCULAR); /*Circular scroll*/
|
||||
lv_obj_set_width(label2, 150);
|
||||
lv_label_set_text(label2, "It is a circularly scrolling text. ");
|
||||
lv_obj_align(label2, LV_ALIGN_CENTER, 0, 40);
|
||||
while(g_running) {
|
||||
sleep(1);
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@ pthread_t user_lv_tick_thread;
|
|||
static lv_disp_draw_buf_t s_disp_buf;
|
||||
static lv_color_t s_pix_buf[2][PIXBUF_SIZE];
|
||||
static lv_disp_drv_t s_disp_drv;
|
||||
static lv_fs_drv_t s_fs_drv;
|
||||
|
||||
void *user_lv_task(void *arguments);
|
||||
void *user_lv_tick(void *arguments);
|
||||
|
@ -44,6 +45,17 @@ int user_lvgl_task_init(void) {
|
|||
s_disp_drv.flush_cb = user_lvgl_impl_flush_cb;
|
||||
lv_disp_t *disp = lv_disp_drv_register(&s_disp_drv);
|
||||
|
||||
lv_fs_drv_init(&s_fs_drv);
|
||||
s_fs_drv.letter = 'A';
|
||||
s_fs_drv.open_cb = user_lvgl_impl_fs_open_cb;
|
||||
s_fs_drv.close_cb = user_lvgl_impl_fs_close_cb;
|
||||
s_fs_drv.read_cb = user_lvgl_impl_fs_read_cb;
|
||||
s_fs_drv.write_cb = user_lvgl_impl_fs_write_cb;
|
||||
s_fs_drv.seek_cb = user_lvgl_impl_fs_seek_cb;
|
||||
s_fs_drv.tell_cb = user_lvgl_impl_fs_tell_cb;
|
||||
|
||||
lv_fs_drv_register(&s_fs_drv);
|
||||
|
||||
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);
|
||||
|
|
Loading…
Reference in New Issue