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 calories_burned_target = 600;
8 static INT calories_burned = 480;
9 static INT animation_step = 0;
10
11 /******************************************************************************************/
12 /* Get calorie burned progress value. */
13 /******************************************************************************************/
get_calorie_burned_progress_val()14 int get_calorie_burned_progress_val()
15 {
16 return (calories_burned * 100 / calories_burned_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(&calories_screen.calories_screen_calories_burned, 0);
25 gx_numeric_prompt_value_set(&calories_screen.calories_screen_calories_burned_target, 0);
26 gx_numeric_prompt_value_set(&calories_screen.calories_screen_progress_val, 0);
27 gx_radial_progress_bar_value_set(&calories_screen.calories_screen_progress, 0);
28 }
29
30 /******************************************************************************************/
31 /* Start a timer for animation. */
32 /******************************************************************************************/
animation_start(GX_WINDOW * window)33 static void animation_start(GX_WINDOW *window)
34 {
35 animation_step = 0;
36
37 gx_system_timer_start(window, SCREEN_ANIMATION_TIMER_ID, 40 / GX_SYSTEM_TIMER_MS, 40 / GX_SYSTEM_TIMER_MS);
38 }
39
40 /******************************************************************************************/
41 /* Update animation. */
42 /******************************************************************************************/
animation_update()43 static void animation_update()
44 {
45 animation_step++;
46
47 gx_numeric_prompt_value_set(&calories_screen.calories_screen_calories_burned, CAL_ANIMATION_VAL(calories_burned));
48 gx_numeric_prompt_value_set(&calories_screen.calories_screen_calories_burned_target, CAL_ANIMATION_VAL(calories_burned_target));
49 gx_numeric_prompt_value_set(&calories_screen.calories_screen_progress_val, CAL_ANIMATION_VAL(calories_burned * 100 / calories_burned_target));
50 gx_radial_progress_bar_value_set(&calories_screen.calories_screen_progress, CAL_ANIMATION_VAL(calories_burned * (-360) / calories_burned_target));
51
52 if (animation_step == ANIMATION_TOTAL_STEPS)
53 {
54 gx_system_timer_stop(&calories_screen, SCREEN_ANIMATION_TIMER_ID);
55 }
56 }
57
58 /******************************************************************************************/
59 /* Override the default event processing of "calories_screen" to handle signals from my */
60 /* child widgets. */
61 /******************************************************************************************/
calories_screen_event_process(GX_WINDOW * window,GX_EVENT * event_ptr)62 UINT calories_screen_event_process(GX_WINDOW* window, GX_EVENT* event_ptr)
63 {
64 switch (event_ptr->gx_event_type)
65 {
66 case GX_EVENT_SHOW:
67 screen_data_reset();
68 break;
69
70 case USER_EVENT_ANIMATION_START:
71 animation_start(window);
72 break;
73
74 case USER_EVENT_ANIMATION_STOP:
75 gx_system_timer_stop(window, SCREEN_ANIMATION_TIMER_ID);
76 break;
77
78 case GX_EVENT_TIMER:
79 if (event_ptr->gx_event_payload.gx_event_timer_id == SCREEN_ANIMATION_TIMER_ID)
80 {
81 animation_update();
82 }
83 break;
84
85 default:
86 break;
87 }
88
89 return screen_template_event_process(window, event_ptr);
90 }