1 #include "demo_guix_smart_watch.h"
2 
3 /* Define music information structure.  */
4 typedef struct MUSIC_INFO_STRUCT {
5     GX_STRING singer;
6     GX_STRING song;
7     INT duration;
8 }MUSIC_INFO;
9 
10 static GX_CHAR singer_1[] = "Angelo";
11 static GX_CHAR song_1[] = "Remember Me This Way";
12 static GX_CHAR singer_2[] = "Mat Steiner";
13 static GX_CHAR song_2[] = "Samba Do Brazil";
14 static GX_CHAR singer_3[] = "RageGuitar";
15 static GX_CHAR song_3[] = "Hope For Quick Escape";
16 
17 /* Define music information.  */
18 static MUSIC_INFO music_list[] = {
19     {{singer_1, sizeof(singer_1) - 1}, {song_1, sizeof(song_1) - 1}, 170},
20     {{singer_2, sizeof(singer_2) - 1}, {song_2, sizeof(song_2) - 1}, 180},
21     {{singer_3, sizeof(singer_3) - 1}, {song_3, sizeof(song_3) - 1}, 200}
22 };
23 
24 /* Define local variables.  */
25 static GX_BOOL play_on = GX_FALSE;
26 static INT play_index = 0;
27 static INT play_time = 0;
28 
29 /******************************************************************************************/
30 /* Update music play progress in weather screen.                                          */
31 /******************************************************************************************/
weather_screen_music_progress_update()32 VOID weather_screen_music_progress_update()
33 {
34     if (!play_on)
35     {
36         return;
37     }
38 
39     gx_radial_progress_bar_value_set(&weather_screen.weather_screen_music_play_progress, play_time * (-360) / music_list[play_index].duration);
40 }
41 
42 /******************************************************************************************/
43 /* Update music play progress in music screen.                                            */
44 /******************************************************************************************/
music_screen_music_progress_update()45 static VOID music_screen_music_progress_update()
46 {
47     if (!play_on)
48     {
49         return;
50     }
51 
52     gx_numeric_prompt_value_set(&music_screen.music_screen_hour, play_time / 60);
53     gx_numeric_prompt_value_set(&music_screen.music_screen_minute, play_time % 60);
54     gx_radial_progress_bar_value_set(&music_screen.music_screen_play_progress,
55         play_time * (-360) / music_list[play_index].duration);
56 }
57 
58 /******************************************************************************************/
59 /* Update music information.                                                              */
60 /******************************************************************************************/
music_info_update()61 static VOID music_info_update()
62 {
63     /* Update music information in weather screen.  */
64     gx_prompt_text_set_ext(&weather_screen.weather_screen_singer, &music_list[play_index].singer);
65     gx_prompt_text_set_ext(&weather_screen.weather_screen_song, &music_list[play_index].song);
66     gx_radial_progress_bar_value_set(&weather_screen.weather_screen_music_play_progress, play_time * (-360) / music_list[play_index].duration);
67 
68     /* Update music information in music screen.  */
69     gx_prompt_text_set_ext(&music_screen.music_screen_singer, &music_list[play_index].singer);
70     gx_prompt_text_set_ext(&music_screen.music_screen_song, &music_list[play_index].song);
71     gx_numeric_prompt_value_set(&music_screen.music_screen_hour, play_time / 60);
72     gx_numeric_prompt_value_set(&music_screen.music_screen_minute, play_time % 60);
73     gx_radial_progress_bar_value_set(&music_screen.music_screen_play_progress, play_time * (-360) / music_list[play_index].duration);
74 }
75 
76 /******************************************************************************************/
77 /* Play next song.                                                                        */
78 /******************************************************************************************/
music_play_next()79 static VOID music_play_next()
80 {
81     if (play_index + 1 < (INT)(sizeof(music_list) / sizeof(MUSIC_INFO)))
82     {
83         play_index++;
84     }
85     else
86     {
87         play_index = 0;
88     }
89 
90     play_time =0;
91 
92     music_info_update();
93 }
94 
95 
96 /******************************************************************************************/
97 /* Play previous song.                                                                    */
98 /******************************************************************************************/
music_play_previous()99 static VOID music_play_previous()
100 {
101     if (play_index > 0)
102     {
103         play_index--;
104     }
105     else
106     {
107         play_index = (INT)(sizeof(music_list) / sizeof(MUSIC_INFO)) - 1;
108     }
109 
110     play_time = 0;
111 
112     music_info_update();
113 }
114 
115 /******************************************************************************************/
116 /* Start music playing.                                                                   */
117 /******************************************************************************************/
music_play_on()118 VOID music_play_on()
119 {
120     play_on = GX_TRUE;
121 
122     gx_widget_style_add(&weather_screen.weather_screen_play_button, GX_STYLE_BUTTON_PUSHED);
123     gx_widget_style_add(&music_screen.music_screen_play_button, GX_STYLE_BUTTON_PUSHED);
124 }
125 
126 /******************************************************************************************/
127 /* Stop music playing.                                                                    */
128 /******************************************************************************************/
music_play_off()129 VOID music_play_off()
130 {
131     play_on = GX_FALSE;
132 
133     gx_widget_style_remove(&weather_screen.weather_screen_play_button, GX_STYLE_BUTTON_PUSHED);
134     gx_widget_style_remove(&music_screen.music_screen_play_button, GX_STYLE_BUTTON_PUSHED);
135 }
136 
137 /******************************************************************************************/
138 /* Update music play progress.                                                            */
139 /******************************************************************************************/
music_play_progress_update()140 VOID music_play_progress_update()
141 {
142     if (!play_on)
143     {
144         return;
145     }
146 
147     if (play_time < music_list[play_index].duration)
148     {
149         play_time++;
150     }
151     else
152     {
153         music_play_next();
154     }
155 }
156 
157 /******************************************************************************************/
158 /* Override the default event processing of "music_screen" to handle signals from my      */
159 /* child widgets.                                                                         */
160 /******************************************************************************************/
music_screen_event_process(GX_WINDOW * window,GX_EVENT * event_ptr)161 UINT music_screen_event_process(GX_WINDOW* window, GX_EVENT* event_ptr)
162 {
163     switch (event_ptr->gx_event_type)
164     {
165     case GX_EVENT_SHOW:
166         music_info_update();
167         break;
168 
169     case GX_EVENT_TIMER:
170         if (event_ptr->gx_event_payload.gx_event_timer_id == SCREEN_CLOCK_TIMER_ID)
171         {
172             music_screen_music_progress_update();
173         }
174         break;
175 
176     case GX_SIGNAL(ID_PLAY_BUTTON, GX_EVENT_TOGGLE_ON):
177         music_play_on();
178         break;
179 
180     case GX_SIGNAL(ID_PLAY_BUTTON, GX_EVENT_TOGGLE_OFF):
181         music_play_off();
182         break;
183 
184     case GX_SIGNAL(ID_FORWARD_BUTTON, GX_EVENT_CLICKED):
185         music_play_next();
186         break;
187 
188     case GX_SIGNAL(ID_REVERSE_BUTTON, GX_EVENT_CLICKED):
189         music_play_previous();
190         break;
191 
192     default:
193         break;
194     }
195 
196     return screen_template_event_process(window, event_ptr);
197 }
198 
199 /******************************************************************************************/
200 /* Define custom pixelmap button draw function to draw the button as selected when the    */
201 /* the button is pushed.                                                                  */
202 /******************************************************************************************/
custom_pixelmap_button_draw(GX_PIXELMAP_BUTTON * button)203 VOID custom_pixelmap_button_draw(GX_PIXELMAP_BUTTON* button)
204 {
205     if (button->gx_widget_style & GX_STYLE_BUTTON_PUSHED)
206     {
207         button->gx_widget_style |= GX_STYLE_DRAW_SELECTED;
208     }
209     else
210     {
211         button->gx_widget_style &= ~GX_STYLE_DRAW_SELECTED;
212     }
213 
214     gx_pixelmap_button_draw(button);
215 }