Select one of the symbols to view example projects that use it.
 
Outline
#include <math.h>
#include "sdkconfig.h"
#include "lvgl.h"
#define PI
my_timer_context_t
my_tim_ctx
arc
img_logo
img_text
arc_color
anim_timer_cb(lv_timer_t *)
start_animation(lv_obj_t *)
example_lvgl_demo_ui(lv_disp_t *)
Files
loading (2/4)...
SourceVuESP-IDF Framework and Examplesi80_controller samplemain/lvgl_demo_ui.c
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/* * SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: CC0-1.0 *//* ... */ #include <math.h> #include "sdkconfig.h" #include "lvgl.h" #ifndef PI #define PI (3.14159f) #endif #if CONFIG_EXAMPLE_LCD_IMAGE_FROM_EMBEDDED_BINARY // LVGL image declare LV_IMG_DECLARE(esp_logo) LV_IMG_DECLARE(esp_text)/* ... */ #endif // CONFIG_EXAMPLE_LCD_IMAGE_FROM_EMBEDDED_BINARY typedef struct { lv_obj_t *scr; int count_val; }{ ... } my_timer_context_t; static my_timer_context_t my_tim_ctx; static lv_obj_t *arc[3]; static lv_obj_t *img_logo = NULL; 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 *)lv_timer_get_user_data(timer); int count = timer_ctx->count_val; lv_obj_t *scr = timer_ctx->scr; // Play arc animation if (count < 90) { lv_coord_t arc_start = count > 0 ? (1 - cosf(count / 180.0f * PI)) * 270 : 0; lv_coord_t arc_len = (sinf(count / 180.0f * PI) + 1) * 135; for (size_t i = 0; i < sizeof(arc) / sizeof(arc[0]); i++) { lv_arc_set_bg_angles(arc[i], arc_start, arc_len); lv_arc_set_rotation(arc[i], (count + 120 * (i + 1)) % 360); }{...} }{...} // Delete arcs when animation finished if (count == 90) { for (size_t i = 0; i < sizeof(arc) / sizeof(arc[0]); i++) { lv_obj_delete(arc[i]); }{...} // Create new image and make it transparent img_text = lv_image_create(scr); #if CONFIG_EXAMPLE_LCD_IMAGE_FROM_FILE_SYSTEM lv_image_set_src(img_text, "S:/spiffs/esp_text.png"); #elif CONFIG_EXAMPLE_LCD_IMAGE_FROM_EMBEDDED_BINARY lv_image_set_src(img_text, &esp_text); #endif lv_obj_set_style_image_opa(img_text, 0, 0); }{...} // Move images when arc animation finished if ((count >= 100) && (count <= 180)) { lv_coord_t offset = (sinf((count - 140) * 2.25f / 90.0f) + 1) * 20.0f; lv_obj_align(img_logo, LV_ALIGN_CENTER, 0, -offset); lv_obj_align(img_text, LV_ALIGN_CENTER, 0, 2 * offset); lv_obj_set_style_image_opa(img_text, offset / 40.0f * 255, 0); }{...} // Delete timer when all animation finished if ((count += 5) == 220) { lv_timer_delete(timer); }{...} else { timer_ctx->count_val = count; }{...} }{ ... } static void start_animation(lv_obj_t *scr) { // Align image lv_obj_center(img_logo); // Create arcs for (size_t i = 0; i < sizeof(arc) / sizeof(arc[0]); i++) { arc[i] = lv_arc_create(scr); // Set arc caption lv_obj_set_size(arc[i], 220 - 30 * i, 220 - 30 * i); lv_arc_set_bg_angles(arc[i], 120 * i, 10 + 120 * i); lv_arc_set_value(arc[i], 0); // Set arc style lv_obj_remove_style(arc[i], NULL, LV_PART_KNOB); lv_obj_set_style_arc_width(arc[i], 10, 0); lv_obj_set_style_arc_color(arc[i], arc_color[i], 0); // Make arc center lv_obj_center(arc[i]); }{...} if (img_text) { lv_obj_delete(img_text); img_text = NULL; }{...} // Create timer for animation my_tim_ctx.count_val = -90; my_tim_ctx.scr = scr; lv_timer_create(anim_timer_cb, 20, &my_tim_ctx); }{ ... } void example_lvgl_demo_ui(lv_disp_t *disp) { lv_obj_t *scr = lv_display_get_screen_active(disp); // Create image img_logo = lv_image_create(scr); #if CONFIG_EXAMPLE_LCD_IMAGE_FROM_FILE_SYSTEM lv_image_set_src(img_logo, "S:/spiffs/esp_logo.png"); #elif CONFIG_EXAMPLE_LCD_IMAGE_FROM_EMBEDDED_BINARY lv_image_set_src(img_logo, &esp_logo); #endif start_animation(scr); }{ ... }
Details