examples/lcd: Add touch support into i80 lcd example.

This commit is contained in:
Vilem Zavodny
2022-06-08 12:33:03 +02:00
parent d7ab8fd4ba
commit 036705fe8f
6 changed files with 211 additions and 18 deletions

View File

@@ -20,15 +20,18 @@ typedef struct {
int count_val;
} my_timer_context_t;
static my_timer_context_t my_tim_ctx;
static lv_obj_t * btn;
static lv_obj_t *arc[3];
static lv_obj_t *img_logo;
static lv_obj_t *img_text;
static lv_obj_t *img_text = NULL;
static lv_color_t arc_color[] = {
LV_COLOR_MAKE(232, 87, 116),
LV_COLOR_MAKE(126, 87, 162),
LV_COLOR_MAKE(90, 202, 228),
};
static void anim_timer_cb(lv_timer_t *timer)
{
my_timer_context_t *timer_ctx = (my_timer_context_t *) timer->user_data;
@@ -69,18 +72,17 @@ static void anim_timer_cb(lv_timer_t *timer)
// Delete timer when all animation finished
if ((count += 5) == 220) {
lv_timer_del(timer);
// Enable button
lv_obj_clear_state(btn, LV_STATE_DISABLED);
} else {
timer_ctx->count_val = count;
}
}
void example_lvgl_demo_ui(lv_disp_t *disp)
static void start_animation(lv_obj_t *scr)
{
lv_obj_t *scr = lv_disp_get_scr_act(disp);
// Create image
img_logo = lv_img_create(scr);
lv_img_set_src(img_logo, &esp_logo);
// Align image
lv_obj_center(img_logo);
// Create arcs
@@ -101,10 +103,41 @@ void example_lvgl_demo_ui(lv_disp_t *disp)
lv_obj_center(arc[i]);
}
if (img_text) {
lv_obj_del(img_text);
img_text = NULL;
}
// Create timer for animation
static my_timer_context_t my_tim_ctx = {
.count_val = -90,
};
my_tim_ctx.count_val = -90;
my_tim_ctx.scr = scr;
lv_timer_create(anim_timer_cb, 20, &my_tim_ctx);
// Disable button
lv_obj_add_state(btn, LV_STATE_DISABLED);
}
static void btn_cb(lv_event_t * e)
{
lv_obj_t * scr = lv_event_get_user_data(e);
start_animation(scr);
}
void example_lvgl_demo_ui(lv_disp_t *disp)
{
lv_obj_t *scr = lv_disp_get_scr_act(disp);
// Create image
img_logo = lv_img_create(scr);
lv_img_set_src(img_logo, &esp_logo);
btn = lv_btn_create(scr);
lv_obj_t * lbl = lv_label_create(btn);
lv_label_set_text_static(lbl, LV_SYMBOL_REFRESH" SHOW AGAIN");
lv_obj_set_style_text_font(lbl, &lv_font_montserrat_20, 0);
lv_obj_align(btn, LV_ALIGN_BOTTOM_LEFT, 30, -30);
// Button event
lv_obj_add_event_cb(btn, btn_cb, LV_EVENT_CLICKED, scr);
start_animation(scr);
}