1
2 #include "demo_guix_home_automation.h"
3
4 extern APP_INFO app_info;
5
6 static INT input_code_count = 0;
7
8 /* This is a list of passcode icons, one icon correspond to on passcode. */
9 static GX_ICON *passcode_icon_list[] = {
10 &passcode_screen.passcode_screen_passcode_1,
11 &passcode_screen.passcode_screen_passcode_2,
12 &passcode_screen.passcode_screen_passcode_3,
13 &passcode_screen.passcode_screen_passcode_4,
14 GX_NULL
15 };
16
17 /******************************************************************************************/
18 /* Event handler for number button click. */
19 /******************************************************************************************/
on_passcode_input()20 static VOID on_passcode_input()
21 {
22 INT icon_id;
23 INT text_color_id;
24
25 if (input_code_count > 3)
26 {
27 return;
28 }
29
30 switch (input_code_count)
31 {
32 case 0:
33 case 1:
34 case 2:
35 icon_id = GX_PIXELMAP_ID_PASSCODE_ASTERIC_ACTIVE;
36 break;
37
38 case 3:
39 icon_id = GX_PIXELMAP_ID_PASSCODE_ASTERIC_WRONG;
40 text_color_id = GX_COLOR_ID_RED;
41
42 gx_prompt_text_id_set(&passcode_screen.passcode_screen_title, GX_STRING_ID_WRONG_PASSCODE);
43 gx_prompt_text_color_set(&passcode_screen.passcode_screen_title, text_color_id, text_color_id, text_color_id);
44 break;
45 }
46
47 gx_icon_pixelmap_set(passcode_icon_list[input_code_count], icon_id, icon_id);
48 input_code_count++;
49 }
50
51 /******************************************************************************************/
52 /* Event handler for clear button click. */
53 /******************************************************************************************/
on_clear()54 static VOID on_clear()
55 {
56 GX_ICON *icon;
57 INT index = 0;
58 GX_RESOURCE_ID icon_id = GX_PIXELMAP_ID_PASSCODE_ASTERIC;
59 INT text_color_id = GX_COLOR_ID_WHITE;
60 GX_ANIMATION *animation;
61 GX_ANIMATION_INFO info;
62
63 if (!input_code_count)
64 {
65 /* No code been input yet, just return. */
66 return;
67 }
68
69 /* Reset input code count to 0. */
70 input_code_count = 0;
71
72 memset(&info, 0, sizeof(GX_ANIMATION_INFO));
73
74 info.gx_animation_parent = (GX_WIDGET *)&passcode_screen;
75 info.gx_animation_start_position.gx_point_y = -60;
76 info.gx_animation_end_position.gx_point_y = 78;
77 info.gx_animation_steps = 600 / GX_SYSTEM_TIMER_MS;
78 info.gx_animation_frame_interval = 1;
79 info.gx_animation_start_alpha = 255;
80 info.gx_animation_end_alpha = 255;
81 info.gx_animation_style = GX_ANIMATION_CIRC_EASE_OUT;
82
83 while (1)
84 {
85 icon = passcode_icon_list[index];
86
87 if (icon)
88 {
89 if ((icon->gx_icon_normal_pixelmap != icon_id) &&
90 (gx_system_animation_get(&animation) == GX_SUCCESS))
91 {
92 info.gx_animation_start_position.gx_point_x = icon->gx_widget_size.gx_rectangle_left;
93 info.gx_animation_end_position.gx_point_x = icon->gx_widget_size.gx_rectangle_left;
94 info.gx_animation_target = (GX_WIDGET *)icon;
95 info.gx_animation_start_delay += 5;
96
97 /* Show cleared passcode icon with animation. */
98 gx_animation_start(animation, &info);
99 }
100
101 /* Reset icon pixelmaps. */
102 gx_icon_pixelmap_set(icon, icon_id, icon_id);
103
104 index++;
105 }
106 else
107 {
108 break;
109 }
110 }
111
112 gx_prompt_text_id_set(&passcode_screen.passcode_screen_title, GX_STRING_ID_ENTER_PASSCODE);
113 gx_prompt_text_color_set(&passcode_screen.passcode_screen_title, text_color_id, text_color_id, text_color_id);
114 }
115
116 /******************************************************************************************/
117 /* Override the default event processing of "passcode_screen" to handle signals from my */
118 /* child widgets. */
119 /******************************************************************************************/
passcode_screen_event_process(GX_WINDOW * window,GX_EVENT * event_ptr)120 UINT passcode_screen_event_process(GX_WINDOW *window, GX_EVENT *event_ptr)
121 {
122 switch (event_ptr->gx_event_type)
123 {
124 case GX_EVENT_SHOW:
125 gx_window_event_process(window, event_ptr);
126 on_clear();
127 break;
128
129 case GX_SIGNAL(ID_NUM_0, GX_EVENT_CLICKED):
130 case GX_SIGNAL(ID_NUM_1, GX_EVENT_CLICKED):
131 case GX_SIGNAL(ID_NUM_2, GX_EVENT_CLICKED):
132 case GX_SIGNAL(ID_NUM_3, GX_EVENT_CLICKED):
133 case GX_SIGNAL(ID_NUM_4, GX_EVENT_CLICKED):
134 case GX_SIGNAL(ID_NUM_5, GX_EVENT_CLICKED):
135 case GX_SIGNAL(ID_NUM_6, GX_EVENT_CLICKED):
136 case GX_SIGNAL(ID_NUM_7, GX_EVENT_CLICKED):
137 case GX_SIGNAL(ID_NUM_8, GX_EVENT_CLICKED):
138 case GX_SIGNAL(ID_NUM_9, GX_EVENT_CLICKED):
139 on_passcode_input();
140 break;
141
142 case GX_SIGNAL(ID_CLEAR, GX_EVENT_CLICKED):
143 on_clear();
144 break;
145
146 case GX_SIGNAL(ID_CLOSE, GX_EVENT_CLICKED):
147 toggle_screen(app_info.previous_screen);
148 break;
149
150 default:
151 return gx_window_event_process(window, event_ptr);
152 }
153
154 return 0;
155 }
156