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 running_distance_target = 637;
8 static INT running_distance = 465;
9 static INT running_steps = 11278;
10 static INT running_time = 3148; /* Seconds. */
11 static INT animation_step = 0;
12
13 /******************************************************************************************/
14 /* Get running progress value. */
15 /******************************************************************************************/
get_running_progress_val()16 int get_running_progress_val()
17 {
18 return (running_distance * 100 / running_distance_target);
19 }
20
21 /******************************************************************************************/
22 /* Get running steps. */
23 /******************************************************************************************/
get_running_steps()24 int get_running_steps()
25 {
26 return running_steps;
27 }
28
29 /******************************************************************************************/
30 /* Get running distance. */
31 /******************************************************************************************/
get_running_distance()32 int get_running_distance()
33 {
34 return running_distance;
35 }
36
37 /******************************************************************************************/
38 /* Reset screen data. */
39 /******************************************************************************************/
screen_data_reset()40 static void screen_data_reset()
41 {
42 gx_numeric_prompt_value_set(&run_screen.run_screen_running_distance, 0);
43 gx_numeric_prompt_value_set(&run_screen.run_screen_running_minutes, 0);
44 gx_numeric_prompt_value_set(&run_screen.run_screen_running_seconds, 0);
45 gx_numeric_prompt_value_set(&run_screen.run_screen_progress_val, 0);
46 gx_numeric_prompt_value_set(&run_screen.run_screen_running_distance_fraction_part, 0);
47 gx_radial_progress_bar_value_set(&run_screen.run_screen_progress, 0);
48 }
49
50 /******************************************************************************************/
51 /* Start a timer for animation. */
52 /******************************************************************************************/
animation_start(GX_WINDOW * window)53 static void animation_start(GX_WINDOW *window)
54 {
55 animation_step = 0;
56
57 gx_system_timer_start(window, SCREEN_ANIMATION_TIMER_ID, 40 / GX_SYSTEM_TIMER_MS, 40 / GX_SYSTEM_TIMER_MS);
58 }
59
60 /******************************************************************************************/
61 /* Update animation. */
62 /******************************************************************************************/
animation_update()63 static void animation_update()
64 {
65 animation_step++;
66
67 gx_numeric_prompt_value_set(&run_screen.run_screen_running_distance, CAL_ANIMATION_VAL(running_distance / 100));
68 gx_numeric_prompt_value_set(&run_screen.run_screen_running_distance_fraction_part, CAL_ANIMATION_VAL(running_distance % 100));
69 gx_numeric_prompt_value_set(&run_screen.run_screen_running_minutes, CAL_ANIMATION_VAL(running_time / 60));
70 gx_numeric_prompt_value_set(&run_screen.run_screen_running_seconds, CAL_ANIMATION_VAL(running_time % 60));
71 gx_numeric_prompt_value_set(&run_screen.run_screen_progress_val, CAL_ANIMATION_VAL(running_distance * 100 / running_distance_target));
72 gx_radial_progress_bar_value_set(&run_screen.run_screen_progress, CAL_ANIMATION_VAL(running_distance * (-360) / running_distance_target));
73
74 if (animation_step == ANIMATION_TOTAL_STEPS)
75 {
76 gx_system_timer_stop(&run_screen, SCREEN_ANIMATION_TIMER_ID);
77 }
78 }
79
80 /******************************************************************************************/
81 /* Override the default event processing of "calories_screen" to handle signals from my */
82 /* child widgets. */
83 /******************************************************************************************/
run_screen_event_process(GX_WINDOW * window,GX_EVENT * event_ptr)84 UINT run_screen_event_process(GX_WINDOW* window, GX_EVENT* event_ptr)
85 {
86 switch (event_ptr->gx_event_type)
87 {
88 case GX_EVENT_SHOW:
89 screen_data_reset();
90 break;
91
92 case USER_EVENT_ANIMATION_START:
93 animation_start(window);
94 break;
95
96 case USER_EVENT_ANIMATION_STOP:
97 gx_system_timer_stop(window, SCREEN_ANIMATION_TIMER_ID);
98 break;
99
100 case GX_EVENT_TIMER:
101 if (event_ptr->gx_event_payload.gx_event_timer_id == SCREEN_ANIMATION_TIMER_ID)
102 {
103 animation_update();
104 }
105 break;
106
107 default:
108 break;
109 }
110
111 return screen_template_event_process(window, event_ptr);
112 }