1 #include "demo_guix_smart_watch.h"
2 
3 #define ANIMATION_TOTAL_STEPS 20
4 #define CAL_ANIMATION_VAL(val) ((val) * animation_step / ANIMATION_TOTAL_STEPS)
5 
6 /* Define local variables.  */
7 static INT calorie_burned = 217;
8 static INT calorie_burned_target = 240;
9 static INT yoga_minutes = 69;
10 static INT animation_step = 0;
11 
12 /******************************************************************************************/
13 /* Reset screen data.                                                                     */
14 /******************************************************************************************/
screen_data_reset()15 static void screen_data_reset()
16 {
17     gx_numeric_prompt_value_set(&yoga_screen.yoga_screen_calories_burned, 0);
18     gx_numeric_prompt_value_set(&yoga_screen.yoga_screen_yoga_hour, 0);
19     gx_numeric_prompt_value_set(&yoga_screen.yoga_screen_yoga_minute, 0);
20     gx_numeric_prompt_value_set(&yoga_screen.yoga_screen_progress_val, 0);
21     gx_radial_progress_bar_value_set(&yoga_screen.yoga_screen_progress, 0);
22 }
23 
24 /******************************************************************************************/
25 /* Start a timer for animation.                                                           */
26 /******************************************************************************************/
animation_start(GX_WINDOW * window)27 static void animation_start(GX_WINDOW* window)
28 {
29     animation_step = 0;
30 
31     gx_system_timer_start(window, SCREEN_ANIMATION_TIMER_ID, 40 / GX_SYSTEM_TIMER_MS, 40 / GX_SYSTEM_TIMER_MS);
32 }
33 
34 /******************************************************************************************/
35 /* Update animation.                                                                      */
36 /******************************************************************************************/
animation_update()37 static void animation_update()
38 {
39     animation_step++;
40 
41     gx_numeric_prompt_value_set(&yoga_screen.yoga_screen_calories_burned, CAL_ANIMATION_VAL(calorie_burned));
42     gx_numeric_prompt_value_set(&yoga_screen.yoga_screen_yoga_hour, CAL_ANIMATION_VAL(yoga_minutes % 60));
43     gx_numeric_prompt_value_set(&yoga_screen.yoga_screen_yoga_minute, CAL_ANIMATION_VAL(yoga_minutes / 60));
44     gx_numeric_prompt_value_set(&yoga_screen.yoga_screen_progress_val, CAL_ANIMATION_VAL(calorie_burned * 100 / calorie_burned_target));
45     gx_radial_progress_bar_value_set(&yoga_screen.yoga_screen_progress, CAL_ANIMATION_VAL(calorie_burned * (-360) / calorie_burned_target));
46 
47     if (animation_step == ANIMATION_TOTAL_STEPS)
48     {
49         gx_system_timer_stop(&yoga_screen, SCREEN_ANIMATION_TIMER_ID);
50     }
51 }
52 
53 /******************************************************************************************/
54 /* Override the default event processing of "yoga_screen" to handle signals from my       */
55 /* child widgets.                                                                         */
56 /******************************************************************************************/
yoga_screen_event_process(GX_WINDOW * window,GX_EVENT * event_ptr)57 UINT yoga_screen_event_process(GX_WINDOW* window, GX_EVENT* event_ptr)
58 {
59     switch (event_ptr->gx_event_type)
60     {
61     case GX_EVENT_SHOW:
62         screen_data_reset();
63         break;
64 
65     case USER_EVENT_ANIMATION_START:
66         animation_start(window);
67         break;
68 
69     case USER_EVENT_ANIMATION_STOP:
70         gx_system_timer_stop(window, SCREEN_ANIMATION_TIMER_ID);
71         break;
72 
73     case GX_EVENT_TIMER:
74         if (event_ptr->gx_event_payload.gx_event_timer_id == SCREEN_ANIMATION_TIMER_ID)
75         {
76             animation_update();
77         }
78         break;
79 
80     default:
81         break;
82     }
83 
84     return screen_template_event_process(window, event_ptr);
85 }