|
1 | 1 | /* |
2 | | - * SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD |
| 2 | + * SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD |
3 | 3 | * |
4 | 4 | * SPDX-License-Identifier: CC0-1.0 |
5 | 5 | */ |
6 | 6 |
|
7 | | -// This demo UI is adapted from LVGL official example: https://docs.lvgl.io/master/widgets/extra/meter.html#simple-meter |
| 7 | +// This demo UI is adapted from LVGL official example: https://docs.lvgl.io/master/examples.html#loader-with-arc |
8 | 8 |
|
9 | 9 | #include "lvgl.h" |
10 | 10 |
|
11 | | -static lv_obj_t *meter; |
12 | 11 | static lv_obj_t * btn; |
13 | | -static lv_disp_rot_t rotation = LV_DISP_ROT_NONE; |
14 | | - |
15 | | -static void set_value(void *indic, int32_t v) |
16 | | -{ |
17 | | - lv_meter_set_indicator_end_value(meter, indic, v); |
18 | | -} |
| 12 | +static lv_display_rotation_t rotation = LV_DISP_ROTATION_0; |
19 | 13 |
|
20 | 14 | static void btn_cb(lv_event_t * e) |
21 | 15 | { |
22 | | - lv_disp_t *disp = lv_event_get_user_data(e); |
| 16 | + lv_display_t *disp = lv_event_get_user_data(e); |
23 | 17 | rotation++; |
24 | | - if (rotation > LV_DISP_ROT_270) { |
25 | | - rotation = LV_DISP_ROT_NONE; |
| 18 | + if (rotation > LV_DISP_ROTATION_270) { |
| 19 | + rotation = LV_DISP_ROTATION_0; |
26 | 20 | } |
27 | 21 | lv_disp_set_rotation(disp, rotation); |
28 | 22 | } |
29 | | - |
30 | | -void example_lvgl_demo_ui(lv_disp_t *disp) |
| 23 | +static void set_angle(void * obj, int32_t v) |
31 | 24 | { |
32 | | - lv_obj_t *scr = lv_disp_get_scr_act(disp); |
33 | | - meter = lv_meter_create(scr); |
34 | | - lv_obj_center(meter); |
35 | | - lv_obj_set_size(meter, 200, 200); |
36 | | - |
37 | | - /*Add a scale first*/ |
38 | | - lv_meter_scale_t *scale = lv_meter_add_scale(meter); |
39 | | - lv_meter_set_scale_ticks(meter, scale, 41, 2, 10, lv_palette_main(LV_PALETTE_GREY)); |
40 | | - lv_meter_set_scale_major_ticks(meter, scale, 8, 4, 15, lv_color_black(), 10); |
41 | | - |
42 | | - lv_meter_indicator_t *indic; |
43 | | - |
44 | | - /*Add a blue arc to the start*/ |
45 | | - indic = lv_meter_add_arc(meter, scale, 3, lv_palette_main(LV_PALETTE_BLUE), 0); |
46 | | - lv_meter_set_indicator_start_value(meter, indic, 0); |
47 | | - lv_meter_set_indicator_end_value(meter, indic, 20); |
48 | | - |
49 | | - /*Make the tick lines blue at the start of the scale*/ |
50 | | - indic = lv_meter_add_scale_lines(meter, scale, lv_palette_main(LV_PALETTE_BLUE), lv_palette_main(LV_PALETTE_BLUE), false, 0); |
51 | | - lv_meter_set_indicator_start_value(meter, indic, 0); |
52 | | - lv_meter_set_indicator_end_value(meter, indic, 20); |
53 | | - |
54 | | - /*Add a red arc to the end*/ |
55 | | - indic = lv_meter_add_arc(meter, scale, 3, lv_palette_main(LV_PALETTE_RED), 0); |
56 | | - lv_meter_set_indicator_start_value(meter, indic, 80); |
57 | | - lv_meter_set_indicator_end_value(meter, indic, 100); |
58 | | - |
59 | | - /*Make the tick lines red at the end of the scale*/ |
60 | | - indic = lv_meter_add_scale_lines(meter, scale, lv_palette_main(LV_PALETTE_RED), lv_palette_main(LV_PALETTE_RED), false, 0); |
61 | | - lv_meter_set_indicator_start_value(meter, indic, 80); |
62 | | - lv_meter_set_indicator_end_value(meter, indic, 100); |
| 25 | + lv_arc_set_value(obj, v); |
| 26 | +} |
63 | 27 |
|
64 | | - /*Add a needle line indicator*/ |
65 | | - indic = lv_meter_add_needle_line(meter, scale, 4, lv_palette_main(LV_PALETTE_GREY), -10); |
| 28 | +void example_lvgl_demo_ui(lv_display_t *disp) |
| 29 | +{ |
| 30 | + lv_obj_t *scr = lv_display_get_screen_active(disp); |
66 | 31 |
|
67 | | - btn = lv_btn_create(scr); |
| 32 | + btn = lv_button_create(scr); |
68 | 33 | lv_obj_t * lbl = lv_label_create(btn); |
69 | 34 | lv_label_set_text_static(lbl, LV_SYMBOL_REFRESH" ROTATE"); |
70 | 35 | lv_obj_align(btn, LV_ALIGN_BOTTOM_LEFT, 30, -30); |
71 | 36 | /*Button event*/ |
72 | 37 | lv_obj_add_event_cb(btn, btn_cb, LV_EVENT_CLICKED, disp); |
73 | 38 |
|
74 | | - /*Create an animation to set the value*/ |
| 39 | + /*Create an Arc*/ |
| 40 | + lv_obj_t * arc = lv_arc_create(scr); |
| 41 | + lv_arc_set_rotation(arc, 270); |
| 42 | + lv_arc_set_bg_angles(arc, 0, 360); |
| 43 | + lv_obj_remove_style(arc, NULL, LV_PART_KNOB); /*Be sure the knob is not displayed*/ |
| 44 | + lv_obj_remove_flag(arc, LV_OBJ_FLAG_CLICKABLE); /*To not allow adjusting by click*/ |
| 45 | + lv_obj_center(arc); |
| 46 | + |
75 | 47 | lv_anim_t a; |
76 | 48 | lv_anim_init(&a); |
77 | | - lv_anim_set_exec_cb(&a, set_value); |
78 | | - lv_anim_set_var(&a, indic); |
| 49 | + lv_anim_set_var(&a, arc); |
| 50 | + lv_anim_set_exec_cb(&a, set_angle); |
| 51 | + lv_anim_set_duration(&a, 1000); |
| 52 | + lv_anim_set_repeat_count(&a, LV_ANIM_REPEAT_INFINITE); /*Just for the demo*/ |
| 53 | + lv_anim_set_repeat_delay(&a, 500); |
79 | 54 | lv_anim_set_values(&a, 0, 100); |
80 | | - lv_anim_set_time(&a, 2000); |
81 | | - lv_anim_set_repeat_delay(&a, 100); |
82 | | - lv_anim_set_playback_time(&a, 500); |
83 | | - lv_anim_set_playback_delay(&a, 100); |
84 | | - lv_anim_set_repeat_count(&a, LV_ANIM_REPEAT_INFINITE); |
85 | 55 | lv_anim_start(&a); |
86 | 56 | } |
0 commit comments