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

Merge pull request #18481 from benpicco/tests/pkg_lvgl_touch-random

tests/pkg_lvgl_touch: randomize button position on click
This commit is contained in:
Alexandre Abadie 2022-08-27 16:20:10 +02:00 committed by GitHub
commit feb98ce748
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 3 deletions

View File

@ -15,6 +15,8 @@ USEMODULE += lvgl_extra_theme_default
# uncomment the following to enable growing button (needs more RAM) # uncomment the following to enable growing button (needs more RAM)
# USEMODULE += lvgl_extra_theme_default_grow # USEMODULE += lvgl_extra_theme_default_grow
USEMODULE += random
# SDL requires more stack # SDL requires more stack
ifeq (native,$(BOARD)) ifeq (native,$(BOARD))
CFLAGS += -DTHREAD_STACKSIZE_MAIN=64*1024 CFLAGS += -DTHREAD_STACKSIZE_MAIN=64*1024

View File

@ -9,6 +9,9 @@ CONFIG_MODULE_LVGL_EXTRA_THEME_DEFAULT=y
# Add touch capabilities # Add touch capabilities
CONFIG_MODULE_LVGL_CONTRIB_TOUCH=y CONFIG_MODULE_LVGL_CONTRIB_TOUCH=y
# enable random positioning
CONFIG_MODULE_RANDOM=y
# Uncomment the following Kconfig symbols to configure LVGL using Kconfig. This # Uncomment the following Kconfig symbols to configure LVGL using Kconfig. This
# requires the LVGL package to be already downloaded (e.g. built once already) # requires the LVGL package to be already downloaded (e.g. built once already)
# LVGL specific configuration # LVGL specific configuration

View File

@ -24,13 +24,22 @@
#include "lvgl_riot.h" #include "lvgl_riot.h"
#include "disp_dev.h" #include "disp_dev.h"
#include "random.h"
static lv_obj_t *btn;
static const lv_coord_t x_size = 100;
static const lv_coord_t y_size = 50;
static void btn_event_cb(lv_event_t *event) static void btn_event_cb(lv_event_t *event)
{ {
lv_event_code_t code = lv_event_get_code(event); lv_event_code_t code = lv_event_get_code(event);
if (code == LV_EVENT_CLICKED) { if (code == LV_EVENT_CLICKED) {
puts("Button clicked!"); puts("Button clicked!");
lv_coord_t x_pos = random_uint32_range(0, lv_obj_get_width(lv_scr_act()) - x_size);
lv_coord_t y_pos = random_uint32_range(0, lv_obj_get_height(lv_scr_act()) - y_size);
lv_obj_set_pos(btn, x_pos, y_pos);
} }
} }
@ -40,11 +49,9 @@ int main(void)
disp_dev_backlight_on(); disp_dev_backlight_on();
/* Add a button to the current screen */ /* Add a button to the current screen */
lv_obj_t *btn = lv_btn_create(lv_scr_act()); btn = lv_btn_create(lv_scr_act());
/* Set the button position and size */ /* Set the button position and size */
lv_coord_t x_size = 100;
lv_coord_t y_size = 50;
lv_coord_t x_pos = (lv_obj_get_width(lv_scr_act()) - x_size) / 2; lv_coord_t x_pos = (lv_obj_get_width(lv_scr_act()) - x_size) / 2;
lv_coord_t y_pos = (lv_obj_get_height(lv_scr_act()) - y_size) / 2; lv_coord_t y_pos = (lv_obj_get_height(lv_scr_act()) - y_size) / 2;
lv_obj_set_pos(btn, x_pos, y_pos); lv_obj_set_pos(btn, x_pos, y_pos);