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 standing_minutes_target = 272;
8 static INT standing_minutes = 140;
9 static INT animation_step = 0;
10 
11 /******************************************************************************************/
12 /* Get standing progress value.                                                           */
13 /******************************************************************************************/
get_standing_progress_val()14 int get_standing_progress_val()
15 {
16     return (standing_minutes * 100 / standing_minutes_target);
17 }
18 
19 /******************************************************************************************/
20 /* Reset screen data.                                                                     */
21 /******************************************************************************************/
screen_data_reset()22 static void screen_data_reset()
23 {
24     gx_numeric_prompt_value_set(&stand_screen.stand_screen_stand_hour, 0);
25     gx_numeric_prompt_value_set(&stand_screen.stand_screen_stand_minute, 0);
26     gx_numeric_prompt_value_set(&stand_screen.stand_screen_stand_hour_target, 0);
27     gx_numeric_prompt_value_set(&stand_screen.stand_screen_stand_minute_target, 0);
28     gx_numeric_prompt_value_set(&stand_screen.stand_screen_progress_val, 0);
29     gx_radial_progress_bar_value_set(&stand_screen.stand_screen_progress, 0);
30 }
31 
32 /******************************************************************************************/
33 /* Start a timer for animation.                                                           */
34 /******************************************************************************************/
animation_start(GX_WINDOW * window)35 static void animation_start(GX_WINDOW *window)
36 {
37     animation_step = 0;
38 
39     gx_system_timer_start(window, SCREEN_ANIMATION_TIMER_ID, 40 / GX_SYSTEM_TIMER_MS, 40 / GX_SYSTEM_TIMER_MS);
40 }
41 
42 /******************************************************************************************/
43 /* Update animation.                                                                      */
44 /******************************************************************************************/
animation_update()45 static void animation_update()
46 {
47     animation_step++;
48 
49     gx_numeric_prompt_value_set(&stand_screen.stand_screen_stand_hour, CAL_ANIMATION_VAL(standing_minutes / 60));
50     gx_numeric_prompt_value_set(&stand_screen.stand_screen_stand_minute, CAL_ANIMATION_VAL(standing_minutes % 60));
51     gx_numeric_prompt_value_set(&stand_screen.stand_screen_stand_hour_target, CAL_ANIMATION_VAL(standing_minutes_target / 60));
52     gx_numeric_prompt_value_set(&stand_screen.stand_screen_stand_minute_target, CAL_ANIMATION_VAL(standing_minutes_target % 60));
53     gx_numeric_prompt_value_set(&stand_screen.stand_screen_progress_val, CAL_ANIMATION_VAL(standing_minutes * 100 / standing_minutes_target));
54     gx_radial_progress_bar_value_set(&stand_screen.stand_screen_progress, CAL_ANIMATION_VAL(standing_minutes * (-360) / standing_minutes_target));
55 
56     if (animation_step == ANIMATION_TOTAL_STEPS)
57     {
58         gx_system_timer_stop(&stand_screen, SCREEN_ANIMATION_TIMER_ID);
59     }
60 }
61 
62 /******************************************************************************************/
63 /* Override the default event processing of "stand_screen" to handle signals from my      */
64 /* child widgets.                                                                         */
65 /******************************************************************************************/
stand_screen_event_process(GX_WINDOW * window,GX_EVENT * event_ptr)66 UINT stand_screen_event_process(GX_WINDOW* window, GX_EVENT* event_ptr)
67 {
68     switch (event_ptr->gx_event_type)
69     {
70     case GX_EVENT_SHOW:
71         screen_data_reset();
72         break;
73 
74     case USER_EVENT_ANIMATION_START:
75         animation_start(window);
76         break;
77 
78     case USER_EVENT_ANIMATION_STOP:
79         gx_system_timer_stop(window, SCREEN_ANIMATION_TIMER_ID);
80         break;
81 
82     case GX_EVENT_TIMER:
83         if (event_ptr->gx_event_payload.gx_event_timer_id == SCREEN_ANIMATION_TIMER_ID)
84         {
85             animation_update();
86         }
87         break;
88 
89     default:
90         break;
91     }
92 
93     return screen_template_event_process(window, event_ptr);
94 }