acid-drop

- Hacking the planet from a LilyGo T-Deck using custom firmware
git clone git://git.acid.vegas/acid-drop.git
Log | Files | Refs | Archive | README | LICENSE

lv_spinner.c (2423B)

      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  */
     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 /**********************
     63  *   STATIC FUNCTIONS
     64  **********************/
     65 
     66 static void lv_spinner_constructor(const lv_obj_class_t * class_p, lv_obj_t * obj)
     67 {
     68     LV_TRACE_OBJ_CREATE("begin");
     69 
     70     LV_UNUSED(class_p);
     71 
     72     lv_obj_clear_flag(obj, LV_OBJ_FLAG_CLICKABLE);
     73 
     74     lv_anim_t a;
     75     lv_anim_init(&a);
     76     lv_anim_set_var(&a, obj);
     77     lv_anim_set_exec_cb(&a, arc_anim_end_angle);
     78     lv_anim_set_repeat_count(&a, LV_ANIM_REPEAT_INFINITE);
     79     lv_anim_set_time(&a, time_param);
     80     lv_anim_set_values(&a, arc_length_param, 360 + arc_length_param);
     81     lv_anim_start(&a);
     82 
     83     lv_anim_set_path_cb(&a, lv_anim_path_ease_in_out);
     84     lv_anim_set_values(&a, 0, 360);
     85     lv_anim_set_exec_cb(&a, arc_anim_start_angle);
     86     lv_anim_start(&a);
     87 
     88     lv_arc_set_bg_angles(obj, 0, 360);
     89     lv_arc_set_rotation(obj, 270);
     90 }
     91 
     92 
     93 static void arc_anim_start_angle(void * obj, int32_t v)
     94 {
     95     lv_arc_set_start_angle(obj, (uint16_t) v);
     96 }
     97 
     98 
     99 static void arc_anim_end_angle(void * obj, int32_t v)
    100 {
    101     lv_arc_set_end_angle(obj, (uint16_t) v);
    102 }
    103 
    104 #endif /*LV_USE_SPINNER*/