1 /* This is a small demo of the high-performance GUIX graphics framework. */
2
3 #include "demo_guix_washing_machine.h"
4
5 #define MIN_WATER_LEVEL 20
6 #define MAX_WATER_LEVEL 80
7
8 /* Define widget angle map structure. */
9 typedef struct widget_angle_map_struct {
10 INT angle;
11 GX_WIDGET *widget;
12 }widget_angle_map;
13
14 /* Define map list between radial slider angle and water level button widget. */
15 widget_angle_map map_list[] = {
16 {-40, (GX_WIDGET *) &water_level_window.water_level_window_btn_min},
17 {-20, (GX_WIDGET*) &water_level_window.water_level_window_btn_low},
18 {0, (GX_WIDGET*) &water_level_window.water_level_window_btn_medium},
19 {20, (GX_WIDGET*) &water_level_window.water_level_window_btn_high},
20 {40, (GX_WIDGET*) &water_level_window.water_level_window_btn_max},
21 {0, GX_NULL}
22 };
23
24 /* Define water level radial slider anchor angle values. */
25 GX_VALUE water_level_anchor_angle_values[] = { -40, -20, 0, 20, 40 };
26
27 /******************************************************************************************/
28 /* Initialize radial slider in water level window. */
29 /******************************************************************************************/
water_level_window_init()30 VOID water_level_window_init()
31 {
32 gx_radial_slider_anchor_angles_set(&water_level_window.water_level_window_water_level_slider,
33 water_level_anchor_angle_values,
34 sizeof(water_level_anchor_angle_values) / sizeof(GX_VALUE));
35 }
36
37 /******************************************************************************************/
38 /* Retrieved angle value by selected button widget. */
39 /******************************************************************************************/
get_angle(GX_WIDGET * widget)40 INT get_angle(GX_WIDGET *widget)
41 {
42 widget_angle_map* entry = map_list;
43
44 while (entry->widget)
45 {
46 if (entry->widget == widget)
47 {
48 return entry->angle;
49 }
50 entry++;
51 }
52
53 return 0;
54 }
55
56 /******************************************************************************************/
57 /* Retrieved button widget by angle value. */
58 /******************************************************************************************/
get_button_widget(INT angle)59 GX_WIDGET *get_button_widget(INT angle)
60 {
61 widget_angle_map* entry = map_list;
62
63 while (entry->widget)
64 {
65 if (entry->angle == angle)
66 {
67 return entry->widget;
68 }
69 entry++;
70 }
71
72 return GX_NULL;
73 }
74
75 /******************************************************************************************/
76 /* Start animation to move radial slider value from min angle to current angle. */
77 /******************************************************************************************/
start_water_level_slider_animation()78 VOID start_water_level_slider_animation()
79 {
80 GX_RADIAL_SLIDER *slider = &water_level_window.water_level_window_water_level_slider;
81 GX_RADIAL_SLIDER_INFO *info = &slider->gx_radial_slider_info;
82 INT water_level;
83
84 water_level = info->gx_radial_slider_info_current_angle;
85 gx_radial_slider_angle_set(slider, info->gx_radial_slider_info_min_angle);
86 gx_radial_slider_animation_start(slider, water_level);
87 }
88
89 /******************************************************************************************/
90 /* Update numeric water level values. */
91 /******************************************************************************************/
update_water_level_numeric_values(INT value)92 VOID update_water_level_numeric_values(INT value)
93 {
94 GX_RADIAL_SLIDER_INFO *info = &water_level_window.water_level_window_water_level_slider.gx_radial_slider_info;
95 INT water_level;
96
97 /* Convert angle value to temperature value. */
98 water_level = (info->gx_radial_slider_info_current_angle - info->gx_radial_slider_info_min_angle) *
99 (MAX_WATER_LEVEL - MIN_WATER_LEVEL) /
100 (info->gx_radial_slider_info_max_angle - info->gx_radial_slider_info_min_angle);
101
102 water_level = MIN_WATER_LEVEL + water_level;
103
104 /* Update numeric water level values. */
105 gx_numeric_prompt_value_set(&water_level_window.water_level_window_water_level_value, water_level);
106 gx_numeric_prompt_value_set(&main_screen.main_screen_water_level_value, water_level);
107 }
108
109 /******************************************************************************************/
110 /* Update water level slider values. */
111 /******************************************************************************************/
update_water_level_slider_value(INT selected_button_id)112 VOID update_water_level_slider_value(INT selected_button_id)
113 {
114 GX_WIDGET *widget;
115
116 gx_widget_find((GX_WIDGET *) &water_level_window, selected_button_id, GX_SEARCH_DEPTH_INFINITE, &widget);
117
118 if (widget)
119 {
120 gx_radial_slider_animation_start(&water_level_window.water_level_window_water_level_slider, get_angle(widget));
121 }
122 }
123
124 /******************************************************************************************/
125 /* Override the default event processing of "water_level_window" to handle signals from */
126 /* my child widgets. */
127 /******************************************************************************************/
water_level_window_event_process(GX_WINDOW * window,GX_EVENT * event_ptr)128 UINT water_level_window_event_process(GX_WINDOW* window, GX_EVENT* event_ptr)
129 {
130
131 switch (event_ptr->gx_event_type)
132 {
133 case GX_EVENT_SHOW:
134 gx_window_event_process(window, event_ptr);
135
136 start_water_level_slider_animation();
137 break;
138
139 case GX_SIGNAL(ID_WATER_LEVEL_SLIDER, GX_EVENT_SLIDER_VALUE):
140 update_water_level_numeric_values(event_ptr->gx_event_payload.gx_event_longdata);
141 break;
142
143
144 case GX_SIGNAL(ID_BTN_MAX, GX_EVENT_RADIO_SELECT):
145 case GX_SIGNAL(ID_BTN_HIGH, GX_EVENT_RADIO_SELECT):
146 case GX_SIGNAL(ID_BTN_MEDIUM, GX_EVENT_RADIO_SELECT):
147 case GX_SIGNAL(ID_BTN_LOW, GX_EVENT_RADIO_SELECT):
148 case GX_SIGNAL(ID_BTN_MIN, GX_EVENT_RADIO_SELECT):
149 update_water_level_slider_value(event_ptr->gx_event_sender);
150 break;
151
152 case GX_SIGNAL(ID_WATER_LEVEL_SLIDER, GX_EVENT_ANIMATION_COMPLETE):
153 gx_button_select((GX_BUTTON*)get_button_widget(water_level_window.water_level_window_water_level_slider.
154 gx_radial_slider_info.gx_radial_slider_info_current_angle));
155 break;
156
157 default:
158 return gx_window_event_process(window, event_ptr);
159 }
160
161 return 0;
162 }
163