Skip to content

Commit

Permalink
tests/pkg_lvgl: adapt to new lvgl version
Browse files Browse the repository at this point in the history
  • Loading branch information
aabadie committed Feb 19, 2022
1 parent 6ea1cd7 commit d512b0b
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 30 deletions.
7 changes: 6 additions & 1 deletion tests/pkg_lvgl/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 5 additions & 0 deletions tests/pkg_lvgl/app.config.test
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
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
48 changes: 25 additions & 23 deletions tests/pkg_lvgl/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,41 +36,42 @@ 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);

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,
cpu_busy,
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 */
Expand All @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions tests/pkg_lvgl_touch/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,11 @@ USEMODULE += lvgl_contrib

# Add touch capabilities
USEMODULE += lvgl_contrib_touch
USEMODULE += lvgl_widget_btn
USEMODULE += lvgl_widget_label
USEMODULE += lvgl_extra_theme_default
USEMODULE += lvgl_extra_theme_default_grow

CFLAGS += -DTHREAD_STACKSIZE_MAIN=2*1024

include $(RIOTBASE)/Makefile.include
4 changes: 4 additions & 0 deletions tests/pkg_lvgl_touch/app.config.test
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
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
CONFIG_MODULE_LVGL_EXTRA_THEME_DEFAULT_GROW=y

# Add touch capabilities
CONFIG_MODULE_LVGL_CONTRIB_TOUCH=y
14 changes: 8 additions & 6 deletions tests/pkg_lvgl_touch/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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!");
}
}
Expand All @@ -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;
Expand All @@ -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();

Expand Down

0 comments on commit d512b0b

Please sign in to comment.