1 /**
2 * @file lv_spinner.c
3 *
4 */
5
6 /*********************
7 * INCLUDES
8 *********************/
9 #include "lv_spinner.h"
10 #if LV_USE_SPINNER
11
12 /*********************
13 * DEFINES
14 *********************/
15
16 /**********************
17 * TYPEDEFS
18 **********************/
19
20 /**********************
21 * STATIC PROTOTYPES
22 **********************/
23 static void lv_spinner_constructor(const lv_obj_class_t * class_p, lv_obj_t * obj);
24 static void arc_anim_start_angle(void * obj, int32_t v);
25 static void arc_anim_end_angle(void * obj, int32_t v);
26
27 /**********************
28 * STATIC VARIABLES
29 **********************/
30 const lv_obj_class_t lv_spinner_class = {
31 .base_class = &lv_arc_class,
32 .constructor_cb = lv_spinner_constructor
33 };
34
35 static uint32_t time_param;
36 static uint32_t arc_length_param;
37
38 /**********************
39 * MACROS
40 **********************/
41
42 /**********************
43 * GLOBAL FUNCTIONS
44 **********************/
45
46 /**
47 * Create a spinner object
48 * @param parent pointer to an object, it will be the parent of the new spinner
49 * @return pointer to the created spinner
50 */
lv_spinner_create(lv_obj_t * parent,uint32_t time,uint32_t arc_length)51 lv_obj_t * lv_spinner_create(lv_obj_t * parent, uint32_t time, uint32_t arc_length)
52 {
53 time_param = time;
54 arc_length_param = arc_length;
55
56 lv_obj_t * obj = lv_obj_class_create_obj(&lv_spinner_class, parent);
57 lv_obj_class_init_obj(obj);
58 return obj;
59 }
60
61 /**********************
62 * STATIC FUNCTIONS
63 **********************/
64
lv_spinner_constructor(const lv_obj_class_t * class_p,lv_obj_t * obj)65 static void lv_spinner_constructor(const lv_obj_class_t * class_p, lv_obj_t * obj)
66 {
67 LV_TRACE_OBJ_CREATE("begin");
68
69 LV_UNUSED(class_p);
70
71 lv_obj_clear_flag(obj, LV_OBJ_FLAG_CLICKABLE);
72
73 lv_anim_t a;
74 lv_anim_init(&a);
75 lv_anim_set_var(&a, obj);
76 lv_anim_set_exec_cb(&a, arc_anim_end_angle);
77 lv_anim_set_repeat_count(&a, LV_ANIM_REPEAT_INFINITE);
78 lv_anim_set_time(&a, time_param);
79 lv_anim_set_values(&a, arc_length_param, 360 + arc_length_param);
80 lv_anim_start(&a);
81
82 lv_anim_set_path_cb(&a, lv_anim_path_ease_in_out);
83 lv_anim_set_values(&a, 0, 360);
84 lv_anim_set_exec_cb(&a, arc_anim_start_angle);
85 lv_anim_start(&a);
86
87 lv_arc_set_bg_angles(obj, 0, 360);
88 lv_arc_set_rotation(obj, 270);
89 }
90
arc_anim_start_angle(void * obj,int32_t v)91 static void arc_anim_start_angle(void * obj, int32_t v)
92 {
93 lv_arc_set_start_angle(obj, (uint16_t) v);
94 }
95
arc_anim_end_angle(void * obj,int32_t v)96 static void arc_anim_end_angle(void * obj, int32_t v)
97 {
98 lv_arc_set_end_angle(obj, (uint16_t) v);
99 }
100
101 #endif /*LV_USE_SPINNER*/
102