1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-01-18 12:52:44 +01:00

tests/pkg_lvgl: adapt to new lvgl version

This commit is contained in:
Alexandre Abadie 2021-06-04 13:58:12 +02:00
parent 0a33a08f21
commit f35c348722
No known key found for this signature in database
GPG Key ID: 1C919A403CAE1405
6 changed files with 86 additions and 30 deletions

View File

@ -6,7 +6,12 @@ DISABLE_MODULE += test_utils_interactive_sync
USEPKG += lvgl
USEMODULE += lvgl_contrib
USEMODULE += lvgl_extra_widget_chart
USEMODULE += lvgl_extra_widget_win
USEMODULE += lvgl_extra_layout_flex
USEMODULE += lvgl_extra_theme_default
USEMODULE += lvgl_extra_theme_default_dark
CFLAGS += -DTHREAD_STACKSIZE_MAIN=2048
CFLAGS += -DTHREAD_STACKSIZE_MAIN=2*1024
include $(RIOTBASE)/Makefile.include

View File

@ -1,2 +1,22 @@
CONFIG_PACKAGE_LVGL=y
CONFIG_MODULE_LVGL_CONTRIB=y
CONFIG_MODULE_LVGL_EXTRA_WIDGET_CHART=y
CONFIG_MODULE_LVGL_EXTRA_WIDGET_WIN=y
CONFIG_MODULE_LVGL_EXTRA_LAYOUT_FLEX=y
CONFIG_MODULE_LVGL_EXTRA_THEME_DEFAULT=y
CONFIG_MODULE_LVGL_EXTRA_THEME_DEFAULT_DARK=y
# Uncomment the following Kconfig symbols to configure LVGL using Kconfig. This
# requires the LVGL package to be already downloaded (e.g. built once already)
# LVGL specific configuration
# CONFIG_KCONFIG_USEPKG_LVGL=y
# CONFIG_LV_FONT_DEFAULT_MONTSERRAT_12=y
# CONFIG_LV_FONT_UNSCII_8=n
# CONFIG_LV_MEMCPY_MEMSET_STD=y
# CONFIG_LV_COLOR_16_SWAP=y
# # set memory size to 6 when
# # CONFIG_MODULE_LVGL_EXTRA_THEME_DEFAULT_GROW symbol above is enabled
# CONFIG_LV_MEM_SIZE_KILOBYTES=5
# # comment out the following line when
# # CONFIG_MODULE_LVGL_EXTRA_THEME_DEFAULT_GROW symbol above is enabled
# CONFIG_LV_THEME_DEFAULT_GROW=n

View File

@ -36,14 +36,14 @@ static lv_obj_t *chart;
static lv_chart_series_t * cpu_ser;
static lv_chart_series_t *mem_ser;
static lv_obj_t *info_label;
static lv_task_t *refr_task;
static lv_timer_t *refr_task;
static void sysmon_task(lv_task_t *param)
static void sysmon_task(lv_timer_t *param)
{
(void)param;
/* Get CPU and memory information */
uint8_t cpu_busy = 100 - lv_task_get_idle();
uint8_t cpu_busy = 100 - lv_timer_get_idle();
lv_mem_monitor_t mem_mon;
lv_mem_monitor(&mem_mon);
@ -51,16 +51,16 @@ static void sysmon_task(lv_task_t *param)
uint8_t mem_used_pct = mem_mon.used_pct;
/* Add the CPU and memory data to the chart */
lv_chart_set_next(chart, cpu_ser, cpu_busy);
lv_chart_set_next(chart, mem_ser, mem_used_pct);
lv_chart_set_next_value(chart, cpu_ser, cpu_busy);
lv_chart_set_next_value(chart, mem_ser, mem_used_pct);
/* Set the text info */
lv_label_set_text_fmt(info_label,
"%s%s CPU: %d %%%s\n\n"
LV_TXT_COLOR_CMD"%s MEMORY: %d %%"LV_TXT_COLOR_CMD"\n"
"Total: %d bytes\n"
"Used: %d bytes\n"
"Free: %d bytes\n"
"Total: %" PRIu32 " bytes\n"
"Used: %" PRIu32 " bytes\n"
"Free: %" PRIu32 " bytes\n"
"Frag: %d %%",
LV_TXT_COLOR_CMD,
CPU_LABEL_COLOR,
@ -68,9 +68,10 @@ static void sysmon_task(lv_task_t *param)
LV_TXT_COLOR_CMD,
MEM_LABEL_COLOR,
mem_used_pct,
(int)mem_mon.total_size,
(int)mem_mon.total_size - mem_mon.free_size,
mem_mon.free_size, mem_mon.frag_pct);
mem_mon.total_size,
mem_mon.total_size - mem_mon.free_size,
mem_mon.free_size,
mem_mon.frag_pct);
/* Force a wakeup of lvgl when each task is called: this ensures an activity
is triggered and wakes up lvgl during the next LVGL_INACTIVITY_PERIOD ms */
@ -82,35 +83,36 @@ void sysmon_create(void)
lv_coord_t hres = lv_disp_get_hor_res(NULL);
lv_coord_t vres = lv_disp_get_ver_res(NULL);
win = lv_win_create(lv_disp_get_scr_act(NULL), NULL);
lv_win_set_title(win, "System monitor");
win = lv_win_create(lv_scr_act(), 25);
lv_win_add_title(win, "System monitor");
lv_obj_t * cont = lv_win_get_content(win);
/* Make the window content responsive */
lv_win_set_layout(win, LV_LAYOUT_PRETTY_MID);
lv_obj_set_layout(cont, LV_LAYOUT_FLEX);
/* Create a chart with two data lines */
chart = lv_chart_create(win, NULL);
chart = lv_chart_create(cont);
lv_obj_set_size(chart, hres / 2.5, vres / 2);
lv_obj_set_pos(chart, LV_DPI / 10, LV_DPI / 10);
lv_obj_set_pos(chart, LV_DPI_DEF / 10, LV_DPI_DEF / 10);
lv_chart_set_point_count(chart, CHART_POINT_NUM);
lv_chart_set_range(chart, 0, 100);
lv_chart_set_range(chart, LV_CHART_AXIS_PRIMARY_Y, 0, 100);
lv_chart_set_type(chart, LV_CHART_TYPE_LINE);
cpu_ser = lv_chart_add_series(chart, LV_COLOR_RED);
mem_ser = lv_chart_add_series(chart, LV_COLOR_BLUE);
cpu_ser = lv_chart_add_series(chart, lv_palette_main(LV_PALETTE_RED), LV_CHART_AXIS_PRIMARY_Y);
mem_ser = lv_chart_add_series(chart, lv_palette_main(LV_PALETTE_BLUE), LV_CHART_AXIS_PRIMARY_Y);
/* Set the data series to zero */
uint16_t i;
for(i = 0; i < CHART_POINT_NUM; i++) {
lv_chart_set_next(chart, cpu_ser, 0);
lv_chart_set_next(chart, mem_ser, 0);
lv_chart_set_next_value(chart, cpu_ser, 0);
lv_chart_set_next_value(chart, mem_ser, 0);
}
/* Create a label for the details of Memory and CPU usage */
info_label = lv_label_create(win, NULL);
info_label = lv_label_create(cont);
lv_label_set_recolor(info_label, true);
/* Create the task used to refresh the chart and label */
refr_task = lv_task_create(sysmon_task, REFR_TIME, LV_TASK_PRIO_LOW, NULL);
refr_task = lv_timer_create(sysmon_task, REFR_TIME, NULL);
}
int main(void)

View File

@ -9,5 +9,12 @@ USEMODULE += lvgl_contrib
# Add touch capabilities
USEMODULE += lvgl_contrib_touch
USEMODULE += lvgl_widget_btn
USEMODULE += lvgl_widget_label
USEMODULE += lvgl_extra_theme_default
# uncomment the following to enable growing button (needs more RAM)
# USEMODULE += lvgl_extra_theme_default_grow
CFLAGS += -DTHREAD_STACKSIZE_MAIN=2*1024
include $(RIOTBASE)/Makefile.include

View File

@ -1,5 +1,25 @@
CONFIG_PACKAGE_LVGL=y
CONFIG_MODULE_LVGL_CONTRIB=y
CONFIG_MODULE_LVGL_WIDGET_BTN=y
CONFIG_MODULE_LVGL_WIDGET_LABEL=y
CONFIG_MODULE_LVGL_EXTRA_THEME_DEFAULT=y
# uncomment the following to enable growing button (needs more RAM)
#CONFIG_MODULE_LVGL_EXTRA_THEME_DEFAULT_GROW=y
# Add touch capabilities
CONFIG_MODULE_LVGL_CONTRIB_TOUCH=y
# Uncomment the following Kconfig symbols to configure LVGL using Kconfig. This
# requires the LVGL package to be already downloaded (e.g. built once already)
# LVGL specific configuration
# CONFIG_KCONFIG_USEPKG_LVGL=y
# CONFIG_LV_FONT_DEFAULT_MONTSERRAT_12=y
# CONFIG_LV_FONT_UNSCII_8=n
# CONFIG_LV_MEMCPY_MEMSET_STD=y
# CONFIG_LV_COLOR_16_SWAP=y
# # set memory size to 6 when
# # CONFIG_MODULE_LVGL_EXTRA_THEME_DEFAULT_GROW symbol above is enabled
# CONFIG_LV_MEM_SIZE_KILOBYTES=5
# # comment out the following line when
# # CONFIG_MODULE_LVGL_EXTRA_THEME_DEFAULT_GROW symbol above is enabled
# CONFIG_LV_THEME_DEFAULT_GROW=n

View File

@ -25,10 +25,11 @@
#include "disp_dev.h"
static void btn_event_cb(lv_obj_t * btn, lv_event_t event)
static void btn_event_cb(lv_event_t *event)
{
(void)btn;
if (event == LV_EVENT_CLICKED) {
lv_event_code_t code = lv_event_get_code(event);
if (code == LV_EVENT_CLICKED) {
puts("Button clicked!");
}
}
@ -39,7 +40,7 @@ int main(void)
disp_dev_backlight_on();
/* Add a button to the current screen */
lv_obj_t * btn = lv_btn_create(lv_scr_act(), NULL);
lv_obj_t *btn = lv_btn_create(lv_scr_act());
/* Set the button position and size */
lv_coord_t x_size = 100;
@ -50,11 +51,12 @@ int main(void)
lv_obj_set_size(btn, 100, 50);
/*Assign a callback to the button*/
lv_obj_set_event_cb(btn, btn_event_cb);
lv_obj_add_event_cb(btn, btn_event_cb, LV_EVENT_ALL, NULL);
/* Add a label to the button */
lv_obj_t * label = lv_label_create(btn, NULL);
lv_obj_t *label = lv_label_create(btn);
lv_label_set_text(label, "Click me");
lv_obj_center(label);
lvgl_run();