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 static INT animation_step = 0;
7
8 /******************************************************************************************/
9 /* Reset screen data. */
10 /******************************************************************************************/
screen_data_reset()11 static void screen_data_reset()
12 {
13 gx_numeric_prompt_value_set(&weather_screen.weather_screen_calorie_burned_progress_val, 0);
14 gx_numeric_prompt_value_set(&weather_screen.weather_screen_running_progress_val, 0);
15 gx_numeric_prompt_value_set(&weather_screen.weather_screen_ekg_progress_val, 0);
16 gx_radial_progress_bar_value_set(&weather_screen.weather_screen_calorie_burned_progress, 0);
17 gx_radial_progress_bar_value_set(&weather_screen.weather_screen_running_progress, 0);
18 gx_radial_progress_bar_value_set(&weather_screen.weather_screen_ekg_progress, 0);
19 }
20
21 /******************************************************************************************/
22 /* Start a timer for animation. */
23 /******************************************************************************************/
animation_start(GX_WINDOW * window)24 static void animation_start(GX_WINDOW* window)
25 {
26 animation_step = 0;
27
28 gx_system_timer_start(window, SCREEN_ANIMATION_TIMER_ID, 40 / GX_SYSTEM_TIMER_MS, 40 / GX_SYSTEM_TIMER_MS);
29 }
30
31 /******************************************************************************************/
32 /* Update animation. */
33 /******************************************************************************************/
animation_update()34 static void animation_update()
35 {
36 INT val;
37
38 animation_step++;
39
40
41 val = get_calorie_burned_progress_val();
42 gx_numeric_prompt_value_set(&weather_screen.weather_screen_calorie_burned_progress_val, CAL_ANIMATION_VAL(val));
43
44 val = val * (-360) / 100;
45 gx_radial_progress_bar_value_set(&weather_screen.weather_screen_calorie_burned_progress, CAL_ANIMATION_VAL(val));
46
47 val = get_running_progress_val();
48 gx_numeric_prompt_value_set(&weather_screen.weather_screen_running_progress_val, CAL_ANIMATION_VAL(val));
49
50 val = val * (-360) / 100;
51 gx_radial_progress_bar_value_set(&weather_screen.weather_screen_running_progress, CAL_ANIMATION_VAL(val));
52
53 val = get_ekg_progress_val();
54 gx_numeric_prompt_value_set(&weather_screen.weather_screen_ekg_progress_val, CAL_ANIMATION_VAL(val));
55
56 val = val * (-360) / 100;
57 gx_radial_progress_bar_value_set(&weather_screen.weather_screen_ekg_progress, CAL_ANIMATION_VAL(val));
58
59 if (animation_step == ANIMATION_TOTAL_STEPS)
60 {
61 gx_system_timer_stop(&weather_screen, SCREEN_ANIMATION_TIMER_ID);
62 }
63 }
64
65 /******************************************************************************************/
66 /* Override the default event processing of "weather_screen" to handle signals from my */
67 /* child widgets. */
68 /******************************************************************************************/
weather_screen_event_process(GX_WINDOW * window,GX_EVENT * event_ptr)69 UINT weather_screen_event_process(GX_WINDOW* window, GX_EVENT* event_ptr)
70 {
71 switch (event_ptr->gx_event_type)
72 {
73 case GX_EVENT_SHOW:
74 screen_data_reset();
75 clear_screen_clock_record();
76 screen_clock_update(&weather_screen.weather_screen_hour, &weather_screen.weather_screen_minute, &weather_screen.weather_screen_second);
77 weather_screen_music_progress_update();
78 gx_system_timer_start(window, SCREEN_CLOCK_TIMER_ID, GX_TICKS_SECOND, GX_TICKS_SECOND);
79 return gx_window_event_process(window, event_ptr);
80
81 case USER_EVENT_ANIMATION_START:
82 animation_start(window);
83 break;
84
85 case USER_EVENT_ANIMATION_STOP:
86 gx_system_timer_stop(window, SCREEN_ANIMATION_TIMER_ID);
87 return gx_window_event_process(window, event_ptr);
88
89 case GX_EVENT_TIMER:
90 switch (event_ptr->gx_event_payload.gx_event_timer_id)
91 {
92 case SCREEN_ANIMATION_TIMER_ID:
93 animation_update();
94 break;
95
96 case SCREEN_CLOCK_TIMER_ID:
97 screen_clock_update(&weather_screen.weather_screen_hour, &weather_screen.weather_screen_minute, &weather_screen.weather_screen_second);
98 weather_screen_music_progress_update();
99 break;
100 }
101 break;
102
103 case GX_SIGNAL(ID_PLAY_BUTTON, GX_EVENT_TOGGLE_ON):
104 music_play_on();
105 break;
106
107 case GX_SIGNAL(ID_PLAY_BUTTON, GX_EVENT_TOGGLE_OFF):
108 music_play_off();
109 break;
110
111 case GX_SIGNAL(ID_CALORIE_BUTTON, GX_EVENT_CLICKED):
112 container_screen_slide((GX_WIDGET*)window, (GX_WIDGET*)&calories_screen);
113 break;
114
115 case GX_SIGNAL(ID_RUNNING_BUTTON, GX_EVENT_CLICKED):
116 container_screen_slide((GX_WIDGET*)window, (GX_WIDGET*)&run_screen);
117 break;
118
119 case GX_SIGNAL(ID_EKG_BUTTON, GX_EVENT_CLICKED):
120 container_screen_slide((GX_WIDGET*)window, (GX_WIDGET*)&ekg_screen);
121 break;
122
123 case GX_SIGNAL(ID_BELL_BUTTON, GX_EVENT_CLICKED):
124 page_screen_slide((GX_WIDGET *)window, (GX_WIDGET *)&message_screen);
125 break;
126
127 default:
128 return gx_window_event_process(window, event_ptr);
129 }
130
131 return 0;
132 }