1 #include "demo_guix_smart_watch.h"
2 
3 #define ANIMATION_TOTAL_STEPS 20
4 #define MAX_DIASTOLE_BLOOD_PRESSURE 120
5 #define CAL_ANIMATION_VAL(val) ((val) * animation_step / ANIMATION_TOTAL_STEPS)
6 
7 /* Define local variables.  */
8 static INT systole_blood_pressure = 120;
9 static INT diastole_blood_pressure = 78;
10 static INT heart_rate = 68;
11 static INT animation_step = 0;
12 
13 /******************************************************************************************/
14 /* Retrieve ekg progress value.                                                           */
15 /******************************************************************************************/
get_ekg_progress_val()16 int get_ekg_progress_val()
17 {
18     return diastole_blood_pressure * 100 / MAX_DIASTOLE_BLOOD_PRESSURE;
19 }
20 
21 /******************************************************************************************/
22 /* Reset screen data.                                                                     */
23 /******************************************************************************************/
screen_data_reset()24 static void screen_data_reset()
25 {
26     gx_numeric_prompt_value_set(&ekg_screen.ekg_screen_systole_blood_pressure, 0);
27     gx_numeric_prompt_value_set(&ekg_screen.ekg_screen_diastole_blood_pressure, 0);
28     gx_numeric_prompt_value_set(&ekg_screen.ekg_screen_heart_rate, 0);
29     gx_radial_progress_bar_value_set(&ekg_screen.ekg_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(&ekg_screen.ekg_screen_systole_blood_pressure, CAL_ANIMATION_VAL(systole_blood_pressure));
50     gx_numeric_prompt_value_set(&ekg_screen.ekg_screen_diastole_blood_pressure, CAL_ANIMATION_VAL(diastole_blood_pressure));
51     gx_numeric_prompt_value_set(&ekg_screen.ekg_screen_heart_rate, CAL_ANIMATION_VAL(heart_rate));
52     gx_radial_progress_bar_value_set(&ekg_screen.ekg_screen_progress, CAL_ANIMATION_VAL(diastole_blood_pressure * (-360) / MAX_DIASTOLE_BLOOD_PRESSURE));
53 
54     if (animation_step == ANIMATION_TOTAL_STEPS)
55     {
56         gx_system_timer_stop(&ekg_screen, SCREEN_ANIMATION_TIMER_ID);
57     }
58 }
59 
60 /******************************************************************************************/
61 /* Override the default event processing of "ekg_screen" to handle signals from my        */
62 /* child widgets.                                                                         */
63 /******************************************************************************************/
ekg_screen_event_process(GX_WINDOW * window,GX_EVENT * event_ptr)64 UINT ekg_screen_event_process(GX_WINDOW* window, GX_EVENT* event_ptr)
65 {
66     switch (event_ptr->gx_event_type)
67     {
68     case GX_EVENT_SHOW:
69         screen_data_reset();
70         break;
71 
72     case USER_EVENT_ANIMATION_START:
73         animation_start(window);
74         break;
75 
76     case USER_EVENT_ANIMATION_STOP:
77         gx_system_timer_stop(window, SCREEN_ANIMATION_TIMER_ID);
78         break;
79 
80     case GX_EVENT_TIMER:
81         if (event_ptr->gx_event_payload.gx_event_timer_id == SCREEN_ANIMATION_TIMER_ID)
82         {
83             animation_update();
84         }
85         break;
86 
87     default:
88         break;
89     }
90 
91     return screen_template_event_process(window, event_ptr);
92 }