1 /* This is a small demo of the high-performance GUIX graphics framework. */
2
3 #include "demo_guix_car_infotainment.h"
4
5 /* Define macros. */
6 #define MIN_SEAT_ANGLE 50
7 #define MAX_SEAT_ANGLE 90
8 #define PROGRESS_ANIMATION_TOTAL_STEPS 20
9
10 /* Define variables. */
11 GX_RESOURCE_ID fan_mode_text_id_list[] = {
12 GX_STRING_ID_AUTO,
13 GX_STRING_ID_MED,
14 GX_STRING_ID_HI,
15 GX_STRING_ID_LOW
16 };
17
18 INT left_fan_mode_index = 0;
19 INT right_fan_mode_index = 0;
20 INT target_left_progress_val;
21 INT target_right_progress_val;
22 INT progress_animation_step;
23
24 /******************************************************************************************/
25 /* Convert progress bar value to seat angle. */
26 /******************************************************************************************/
progress_val_to_seat_angle(GX_PROGRESS_BAR * bar)27 INT progress_val_to_seat_angle(GX_PROGRESS_BAR* bar)
28 {
29 INT seat_angle;
30 GX_PROGRESS_BAR_INFO* info = &bar->gx_progress_bar_info;
31
32 seat_angle = info->gx_progress_bar_info_current_val - info->gx_progress_bar_info_min_val;
33 seat_angle *= (MAX_SEAT_ANGLE - MIN_SEAT_ANGLE);
34 seat_angle /= info->gx_progress_bar_info_max_val - info->gx_progress_bar_info_min_val;
35 seat_angle += MIN_SEAT_ANGLE;
36
37 return seat_angle;
38 }
39
40 /******************************************************************************************/
41 /* Increase fan mode. */
42 /******************************************************************************************/
fan_mode_increase(int fan_mode)43 INT fan_mode_increase(int fan_mode)
44 {
45 fan_mode++;
46 if (fan_mode >= sizeof(fan_mode_text_id_list) / sizeof(GX_RESOURCE_ID))
47 {
48 fan_mode = 0;
49 }
50
51 return fan_mode;
52 }
53
54 /******************************************************************************************/
55 /* Decrease fan mode. */
56 /******************************************************************************************/
fan_mode_decrease(int fan_mode)57 INT fan_mode_decrease(int fan_mode)
58 {
59 fan_mode--;
60 if (fan_mode < 0)
61 {
62 fan_mode = sizeof(fan_mode_text_id_list) / sizeof(GX_RESOURCE_ID) - 1;
63 }
64
65 return fan_mode;
66 }
67
68 /******************************************************************************************/
69 /* Start seat angle animation. */
70 /******************************************************************************************/
seat_angle_animation_start()71 VOID seat_angle_animation_start()
72 {
73 gx_system_timer_start(&climate_screen, TIMER_ID_CLIMATE_SCREEN_PROGRESS_ANIMATION, 20 / GX_SYSTEM_TIMER_MS, 20 / GX_SYSTEM_TIMER_MS);
74 target_left_progress_val = climate_screen.climate_screen_left_progress_bar.gx_progress_bar_info.gx_progress_bar_info_current_val;
75 target_right_progress_val = climate_screen.climate_screen_right_progress_bar.gx_progress_bar_info.gx_progress_bar_info_current_val;
76 progress_animation_step = 0;
77 gx_progress_bar_value_set(&climate_screen.climate_screen_left_progress_bar, 0);
78 gx_progress_bar_value_set(&climate_screen.climate_screen_right_progress_bar, 0);
79 }
80
81 /******************************************************************************************/
82 /* Update seat angle animation. */
83 /******************************************************************************************/
seat_angle_animation_update()84 VOID seat_angle_animation_update()
85 {
86 INT left_progress_val;
87 INT right_progress_val;
88
89 progress_animation_step++;
90
91 left_progress_val = target_left_progress_val * progress_animation_step / PROGRESS_ANIMATION_TOTAL_STEPS;
92 right_progress_val = target_right_progress_val * progress_animation_step / PROGRESS_ANIMATION_TOTAL_STEPS;
93 gx_progress_bar_value_set(&climate_screen.climate_screen_left_progress_bar, left_progress_val);
94 gx_progress_bar_value_set(&climate_screen.climate_screen_right_progress_bar, right_progress_val);
95
96 if (progress_animation_step == PROGRESS_ANIMATION_TOTAL_STEPS)
97 {
98 gx_system_timer_stop(&climate_screen, 0);
99 }
100 }
101
102 /******************************************************************************************/
103 /* Override the default event processing of "climate_screen" to handle signals from my */
104 /* child widgets. */
105 /******************************************************************************************/
climate_screen_event_process(GX_WINDOW * window,GX_EVENT * event_ptr)106 UINT climate_screen_event_process(GX_WINDOW *window, GX_EVENT* event_ptr)
107 {
108 switch (event_ptr->gx_event_type)
109 {
110 case GX_EVENT_SHOW:
111 seat_angle_animation_start();
112 screen_base_event_process(window, event_ptr);
113 break;
114
115 case GX_EVENT_TIMER:
116 if (event_ptr->gx_event_payload.gx_event_timer_id == TIMER_ID_CLIMATE_SCREEN_PROGRESS_ANIMATION)
117 {
118 seat_angle_animation_update();
119 }
120 else
121 {
122 screen_base_event_process(window, event_ptr);
123 }
124 break;
125
126 case GX_SIGNAL(ID_LEFT_PROGRESS_BAR, GX_EVENT_PROGRESS_VALUE):
127 gx_numeric_prompt_value_set(&climate_screen.climate_screen_left_progress_val, progress_val_to_seat_angle(&climate_screen.climate_screen_left_progress_bar));
128 break;
129
130 case GX_SIGNAL(ID_RIGHT_PROGRESS_BAR, GX_EVENT_PROGRESS_VALUE):
131 gx_numeric_prompt_value_set(&climate_screen.climate_screen_right_progress_val, progress_val_to_seat_angle(&climate_screen.climate_screen_right_progress_bar));
132 break;
133
134 case GX_SIGNAL(ID_LEFT_FAN_BUTTON, GX_EVENT_CLICKED):
135 left_fan_mode_index = fan_mode_increase(left_fan_mode_index);
136 gx_prompt_text_id_set(&climate_screen.climate_screen_left_fan_mode, fan_mode_text_id_list[left_fan_mode_index]);
137 break;
138
139 case GX_SIGNAL(ID_LEFT_SMALL_FAN_BUTTON, GX_EVENT_CLICKED):
140 left_fan_mode_index = fan_mode_decrease(left_fan_mode_index);
141 gx_prompt_text_id_set(&climate_screen.climate_screen_left_fan_mode, fan_mode_text_id_list[left_fan_mode_index]);
142 break;
143
144 case GX_SIGNAL(ID_RIGHT_FAN_BUTTON, GX_EVENT_CLICKED):
145 right_fan_mode_index = fan_mode_increase(right_fan_mode_index);
146 gx_prompt_text_id_set(&climate_screen.climate_screen_right_fan_mode, fan_mode_text_id_list[right_fan_mode_index]);
147 break;
148
149 case GX_SIGNAL(ID_RIGHT_SMALL_FAN_BUTTON, GX_EVENT_CLICKED):
150 right_fan_mode_index = fan_mode_decrease(right_fan_mode_index);
151 gx_prompt_text_id_set(&climate_screen.climate_screen_right_fan_mode, fan_mode_text_id_list[right_fan_mode_index]);
152 break;
153 default:
154 return screen_base_event_process(window, event_ptr);
155 }
156
157 return GX_SUCCESS;
158 }
159
160 /******************************************************************************************/
161 /* Define custom progress event process function to handle pen down event. */
162 /******************************************************************************************/
custom_progress_bar_event_process(GX_PROGRESS_BAR * bar,GX_EVENT * event_ptr)163 UINT custom_progress_bar_event_process(GX_PROGRESS_BAR *bar, GX_EVENT *event_ptr)
164 {
165 INT val;
166 GX_RECTANGLE *size = &bar->gx_widget_size;
167 GX_PROGRESS_BAR_INFO *info = &bar->gx_progress_bar_info;
168
169 if (event_ptr->gx_event_type == GX_EVENT_PEN_DOWN)
170 {
171 /* Calculate progress bar value according to pen down position. */
172 val = (size->gx_rectangle_bottom - event_ptr->gx_event_payload.gx_event_pointdata.gx_point_y + 2);
173 val *= (info->gx_progress_bar_info_max_val - info->gx_progress_bar_info_min_val);
174 val /= (size->gx_rectangle_bottom - size->gx_rectangle_top + 1);
175 val += info->gx_progress_bar_info_min_val;
176
177 gx_progress_bar_value_set(bar, val);
178 return GX_SUCCESS;
179 }
180 else
181 {
182 return gx_progress_bar_event_process(bar, event_ptr);
183 }
184 }