1 #include "../../lv_examples.h"
2 #if LV_USE_METER && LV_BUILD_EXAMPLES
3
4 static lv_obj_t * meter;
5
set_value(void * indic,int32_t v)6 static void set_value(void * indic, int32_t v)
7 {
8 lv_meter_set_indicator_end_value(meter, indic, v);
9 }
10
11 /**
12 * A clock from a meter
13 */
lv_example_meter_3(void)14 void lv_example_meter_3(void)
15 {
16 meter = lv_meter_create(lv_scr_act());
17 lv_obj_set_size(meter, 220, 220);
18 lv_obj_center(meter);
19
20 /*Create a scale for the minutes*/
21 /*61 ticks in a 360 degrees range (the last and the first line overlaps)*/
22 lv_meter_scale_t * scale_min = lv_meter_add_scale(meter);
23 lv_meter_set_scale_ticks(meter, scale_min, 61, 1, 10, lv_palette_main(LV_PALETTE_GREY));
24 lv_meter_set_scale_range(meter, scale_min, 0, 60, 360, 270);
25
26 /*Create another scale for the hours. It's only visual and contains only major ticks*/
27 lv_meter_scale_t * scale_hour = lv_meter_add_scale(meter);
28 lv_meter_set_scale_ticks(meter, scale_hour, 12, 0, 0, lv_palette_main(LV_PALETTE_GREY)); /*12 ticks*/
29 lv_meter_set_scale_major_ticks(meter, scale_hour, 1, 2, 20, lv_color_black(), 10); /*Every tick is major*/
30 lv_meter_set_scale_range(meter, scale_hour, 1, 12, 330, 300); /*[1..12] values in an almost full circle*/
31
32 LV_IMG_DECLARE(img_hand)
33
34 /*Add a the hands from images*/
35 lv_meter_indicator_t * indic_min = lv_meter_add_needle_img(meter, scale_min, &img_hand, 5, 5);
36 lv_meter_indicator_t * indic_hour = lv_meter_add_needle_img(meter, scale_min, &img_hand, 5, 5);
37
38 /*Create an animation to set the value*/
39 lv_anim_t a;
40 lv_anim_init(&a);
41 lv_anim_set_exec_cb(&a, set_value);
42 lv_anim_set_values(&a, 0, 60);
43 lv_anim_set_repeat_count(&a, LV_ANIM_REPEAT_INFINITE);
44 lv_anim_set_time(&a, 2000); /*2 sec for 1 turn of the minute hand (1 hour)*/
45 lv_anim_set_var(&a, indic_min);
46 lv_anim_start(&a);
47
48 lv_anim_set_var(&a, indic_hour);
49 lv_anim_set_time(&a, 24000); /*24 sec for 1 turn of the hour hand*/
50 lv_anim_set_values(&a, 0, 60);
51 lv_anim_start(&a);
52 }
53
54 #endif
55