mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
69 lines
2.3 KiB
C
69 lines
2.3 KiB
C
|
/*
|
||
|
* SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD
|
||
|
*
|
||
|
* SPDX-License-Identifier: CC0-1.0
|
||
|
*/
|
||
|
|
||
|
// This demo UI is adapted from LVGL official example: https://docs.lvgl.io/8.3/widgets/extra/meter.html#a-meter-with-multiple-arcs
|
||
|
|
||
|
#include "lvgl.h"
|
||
|
|
||
|
static lv_obj_t * meter;
|
||
|
|
||
|
static void set_value(void *indic, int32_t v)
|
||
|
{
|
||
|
lv_meter_set_indicator_end_value(meter, indic, v);
|
||
|
}
|
||
|
|
||
|
void example_lvgl_demo_ui(lv_disp_t *disp)
|
||
|
{
|
||
|
lv_obj_t *scr = lv_disp_get_scr_act(disp);
|
||
|
meter = lv_meter_create(scr);
|
||
|
lv_obj_center(meter);
|
||
|
lv_obj_set_size(meter, 600, 600);
|
||
|
|
||
|
/*Remove the circle from the middle*/
|
||
|
lv_obj_remove_style(meter, NULL, LV_PART_INDICATOR);
|
||
|
|
||
|
/*Add a scale first*/
|
||
|
lv_meter_scale_t * scale = lv_meter_add_scale(meter);
|
||
|
lv_meter_set_scale_ticks(meter, scale, 11, 2, 10, lv_palette_main(LV_PALETTE_GREY));
|
||
|
lv_meter_set_scale_major_ticks(meter, scale, 1, 2, 30, lv_color_hex3(0xeee), 15);
|
||
|
lv_meter_set_scale_range(meter, scale, 0, 100, 270, 90);
|
||
|
|
||
|
/*Add a four arc indicator*/
|
||
|
lv_meter_indicator_t * indic1 = lv_meter_add_arc(meter, scale, 30, lv_palette_main(LV_PALETTE_RED), 0);
|
||
|
lv_meter_indicator_t * indic2 = lv_meter_add_arc(meter, scale, 30, lv_palette_main(LV_PALETTE_GREEN), -30);
|
||
|
lv_meter_indicator_t * indic3 = lv_meter_add_arc(meter, scale, 30, lv_palette_main(LV_PALETTE_BLUE), -60);
|
||
|
lv_meter_indicator_t * indic4 = lv_meter_add_arc(meter, scale, 30, lv_palette_main(LV_PALETTE_YELLOW), -90);
|
||
|
|
||
|
/*Create an animation to set the value*/
|
||
|
lv_anim_t a;
|
||
|
lv_anim_init(&a);
|
||
|
lv_anim_set_exec_cb(&a, set_value);
|
||
|
lv_anim_set_values(&a, 0, 100);
|
||
|
lv_anim_set_repeat_delay(&a, 100);
|
||
|
lv_anim_set_playback_delay(&a, 100);
|
||
|
lv_anim_set_repeat_count(&a, LV_ANIM_REPEAT_INFINITE);
|
||
|
|
||
|
lv_anim_set_time(&a, 2000);
|
||
|
lv_anim_set_playback_time(&a, 500);
|
||
|
lv_anim_set_var(&a, indic1);
|
||
|
lv_anim_start(&a);
|
||
|
|
||
|
lv_anim_set_time(&a, 1000);
|
||
|
lv_anim_set_playback_time(&a, 1000);
|
||
|
lv_anim_set_var(&a, indic2);
|
||
|
lv_anim_start(&a);
|
||
|
|
||
|
lv_anim_set_time(&a, 1000);
|
||
|
lv_anim_set_playback_time(&a, 2000);
|
||
|
lv_anim_set_var(&a, indic3);
|
||
|
lv_anim_start(&a);
|
||
|
|
||
|
lv_anim_set_time(&a, 3000);
|
||
|
lv_anim_set_playback_time(&a, 2000);
|
||
|
lv_anim_set_var(&a, indic4);
|
||
|
lv_anim_start(&a);
|
||
|
}
|