1
2 #include "demo_guix_washing_machine.h"
3
4 /* Define progress bar animation timer ID. */
5 #define ID_TIMER_PROGRESS_BAR 1
6
7 /* Define progress bar animation properties. */
8 #define PROGRESS_BAR_ANIMATION_TOTAL_STEPS 9
9 #define PROGRESS_BAR_ANIMATION_END_VAL -270
10
11 /* Define variables. */
12 static INT progress_bar_animation_step = 10;
13 static INT selected_button_id = ID_BTN_ECO;
14
15 /* Define MODE button control block. */
16 typedef struct MODE_BTN_INFO_STRUCT {
17 TEMPLATE_MODE_BTN_CONTROL_BLOCK *button;
18 TEMPLATE_MODE_BTN_SMALL_CONTROL_BLOCK* button_small;
19 GX_RESOURCE_ID text_id;
20 GX_RESOURCE_ID map_id;
21 GX_RESOURCE_ID map_id_small;
22 INT minutes;
23 }MODE_BTN_INFO;
24
25 /* Define mode button properties. */
26 MODE_BTN_INFO mode_button_info_list[] = {
27 {&mode_select_window.mode_select_window_btn_quick, &mode_select_window.mode_select_window_btn_quick_small, GX_STRING_ID_QUICK, GX_PIXELMAP_ID_CYCLE_QUICK, GX_PIXELMAP_ID_CYCLE_QUICK_SMALL, 30},
28 {&mode_select_window.mode_select_window_btn_eco, &mode_select_window.mode_select_window_btn_eco_small, GX_STRING_ID_ECO, GX_PIXELMAP_ID_CYCLE_ECO, GX_PIXELMAP_ID_CYCLE_ECO_SMALL, 60},
29 {&mode_select_window.mode_select_window_btn_deep, &mode_select_window.mode_select_window_btn_deep_small, GX_STRING_ID_DEEP, GX_PIXELMAP_ID_CYCLE_DEEP, GX_PIXELMAP_ID_CYCLE_DEEP_SMALL, 90},
30 {GX_NULL, GX_NULL, 0, 0, 0, 0}
31 };
32
33 /******************************************************************************************/
34 /* Initialize mode buttons in mode select window. */
35 /******************************************************************************************/
mode_select_window_init()36 VOID mode_select_window_init()
37 {
38 MODE_BTN_INFO *entry = mode_button_info_list;
39
40 /* Loop through mode buttons. */
41 while (entry->button)
42 {
43
44 /* Set big mode button background map. */
45 gx_pixelmap_button_pixelmap_set((GX_PIXELMAP_BUTTON*)entry->button, entry->map_id, entry->map_id, entry->map_id);
46
47 /* Set big mode button title text. */
48 gx_prompt_text_id_set(&entry->button->template_mode_btn_mode_label, entry->text_id);
49
50 /* Set total time in big button. */
51 gx_numeric_prompt_value_set(&entry->button->template_mode_btn_total_time, entry->minutes);
52
53 /* Set title text in big button. */
54 gx_prompt_text_id_set(&entry->button_small->template_mode_btn_small_mode_label, entry->text_id);
55
56 /* Set total time in small button. */
57 gx_numeric_prompt_value_set(&entry->button_small->template_mode_btn_small_total_time, entry->minutes);
58
59 /* Set small button background map. */
60 gx_pixelmap_button_pixelmap_set((GX_PIXELMAP_BUTTON*)entry->button_small, entry->map_id_small, entry->map_id_small, entry->map_id_small);
61
62 if (selected_button_id != entry->button->gx_widget_id)
63 {
64 /* Hide big button. */
65 gx_widget_hide(entry->button);
66
67 /* Hide progress bar in big button. */
68 gx_widget_hide(&entry->button->template_mode_btn_mode_progress_bar);
69 }
70 else
71 {
72 /* Hide small button. */
73 gx_widget_hide(entry->button_small);
74
75 /* Set remain time in big button. */
76 gx_numeric_prompt_value_set(&entry->button->template_mode_btn_minute, entry->minutes);
77 gx_numeric_prompt_value_set(&entry->button->template_mode_btn_second, 0);
78 }
79
80 entry++;
81 }
82 }
83
84 /******************************************************************************************/
85 /* Get mode button information by button id. */
86 /******************************************************************************************/
get_mode_button_info(INT button_id)87 MODE_BTN_INFO *get_mode_button_info(INT button_id)
88 {
89 MODE_BTN_INFO* entry = mode_button_info_list;
90
91 while (entry->button)
92 {
93 if ((button_id == entry->button->gx_widget_id) ||
94 (button_id == entry->button_small->gx_widget_id))
95 {
96 return entry;
97 }
98
99 entry++;
100 }
101
102 return GX_NULL;
103 }
104
105 /******************************************************************************************/
106 /* Select button by button id. */
107 /******************************************************************************************/
button_select(INT button_id)108 VOID button_select(INT button_id)
109 {
110 MODE_BTN_INFO* info = get_mode_button_info(selected_button_id);
111
112 if (info)
113 {
114 /* Detach the big button of the selected mode. */
115 gx_widget_detach(info->button);
116
117 /* Attach the small button of the selected mode. */
118 gx_widget_attach(&mode_select_window, info->button_small);
119 }
120
121 /* Get button information of the new selected mode. */
122 info = get_mode_button_info(button_id);
123
124 if (info)
125 {
126 /* Detach the small button of the new selected mode. */
127 gx_widget_detach(info->button_small);
128
129 /* Attach the big button of the new selected mode. */
130 gx_widget_attach(&mode_select_window, info->button);
131
132 /* Set selected button id. */
133 selected_button_id = info->button->gx_widget_id;
134 }
135 }
136
137 /******************************************************************************************/
138 /* Set cycle mode. */
139 /******************************************************************************************/
set_cycle_mode()140 VOID set_cycle_mode()
141 {
142 MODE_BTN_INFO* entry = mode_button_info_list;
143
144 while (entry->button)
145 {
146 if (selected_button_id == entry->button->gx_widget_id)
147 {
148 gx_prompt_text_id_set(&main_screen.main_screen_wash_cycle_mode, entry->text_id);
149 gx_widget_detach(&mode_select_window);
150 gx_widget_attach(entry->button, &entry->button->template_mode_btn_mode_progress_bar);
151 gx_widget_attach(&main_screen, &wash_cycle_window);
152 remain_time_set(entry->minutes * 60);
153 }
154 else
155 {
156 gx_widget_detach(&entry->button->template_mode_btn_mode_progress_bar);
157 }
158
159 entry++;
160 }
161 }
162
163 /******************************************************************************************/
164 /* Update radial progress bar animation. */
165 /******************************************************************************************/
update_radial_progress_bar()166 VOID update_radial_progress_bar()
167 {
168 MODE_BTN_INFO* info = get_mode_button_info(selected_button_id);
169 INT value;
170
171 progress_bar_animation_step--;
172
173 value = PROGRESS_BAR_ANIMATION_END_VAL *
174 (PROGRESS_BAR_ANIMATION_TOTAL_STEPS - progress_bar_animation_step) /
175 PROGRESS_BAR_ANIMATION_TOTAL_STEPS;
176
177 gx_radial_progress_bar_value_set(&info->button->template_mode_btn_mode_progress_bar, value);
178
179 if(progress_bar_animation_step == 0)
180 {
181 gx_system_timer_stop(&mode_select_window, ID_TIMER_PROGRESS_BAR);
182 }
183 }
184
185 /******************************************************************************************/
186 /* Update remain time. */
187 /******************************************************************************************/
mode_select_window_remain_time_update(INT remain_seconds)188 VOID mode_select_window_remain_time_update(INT remain_seconds)
189 {
190 MODE_BTN_INFO *info;
191
192 if (remain_seconds)
193 {
194 info = get_mode_button_info(selected_button_id);
195 gx_numeric_prompt_value_set(&info->button->template_mode_btn_minute, remain_seconds / 60);
196 gx_numeric_prompt_value_set(&info->button->template_mode_btn_second, remain_seconds % 60);
197 }
198 }
199
200 /******************************************************************************************/
201 /* Override the default event processing of "wash_cycle_select_window" to handle signals */
202 /* from my child widgets. */
203 /******************************************************************************************/
mode_select_window_event_process(GX_WINDOW * window,GX_EVENT * event_ptr)204 UINT mode_select_window_event_process(GX_WINDOW* window, GX_EVENT* event_ptr)
205 {
206 switch (event_ptr->gx_event_type)
207 {
208 case GX_SIGNAL(ID_BTN_QUICK, GX_EVENT_CLICKED):
209 case GX_SIGNAL(ID_BTN_QUICK_SMALL, GX_EVENT_CLICKED):
210 case GX_SIGNAL(ID_BTN_ECO, GX_EVENT_CLICKED):
211 case GX_SIGNAL(ID_BTN_ECO_SMALL, GX_EVENT_CLICKED):
212 case GX_SIGNAL(ID_BTN_DEEP, GX_EVENT_CLICKED):
213 case GX_SIGNAL(ID_BTN_DEEP_SMALL, GX_EVENT_CLICKED):
214 if (selected_button_id == event_ptr->gx_event_sender)
215 {
216 set_cycle_mode();
217 }
218 else
219 {
220 button_select(event_ptr->gx_event_sender);
221 }
222 break;
223
224 case GX_EVENT_SHOW:
225 gx_window_event_process(window, event_ptr);
226 gx_widget_detach(&main_screen.main_screen_btn_play);
227 gx_system_timer_start(window, ID_TIMER_PROGRESS_BAR, 20 / GX_SYSTEM_TIMER_MS, 20 / GX_SYSTEM_TIMER_MS);
228 progress_bar_animation_step = 10;
229 break;
230
231 case GX_EVENT_HIDE:
232 gx_window_event_process(window, event_ptr);
233
234 gx_widget_attach(&main_screen, &main_screen.main_screen_btn_play);
235
236 gx_system_timer_stop(window, 0);
237 break;
238
239 case GX_EVENT_TIMER:
240 if (event_ptr->gx_event_payload.gx_event_timer_id == ID_TIMER_PROGRESS_BAR)
241 {
242 update_radial_progress_bar();
243 }
244 break;
245
246 default:
247 return gx_window_event_process(window, event_ptr);
248 }
249
250 return 0;
251 }