Tue, 23 Oct 2018 20:39:40 +0200
Updated README
0 | 1 | /** |
2 | * @file buttons.c | |
3 | * @brief The touch buttons. | |
4 | */ | |
5 | ||
6 | #include "config.h" | |
7 | ||
8 | ||
1
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
9 | sButton Buttons[MAXBUTTONS]; ///< 40 buttons on a screen. |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
10 | int level = 1; ///< Keyboard level. |
0 | 11 | |
1
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
12 | extern uint8_t VNC_pointer_button; ///< Mouse buttons mask |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
13 | extern uint16_t VNC_pointer_x; ///< Mouse coordinate X |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
14 | extern uint16_t VNC_pointer_y; ///< Mouse coordinate Y |
0 | 15 | |
16 | ||
1
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
17 | #define EDIT_TYPE_TEXT 0 ///< Editor type is text |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
18 | #define EDIT_TYPE_INT 1 ///< Editor type is integer |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
19 | #define EDIT_TYPE_FLOAT 2 ///< Editor type is float |
0 | 20 | |
21 | ||
22 | /***************************************************************************/ | |
23 | ||
24 | ||
25 | void WaitTouchReleased(void) | |
26 | { | |
27 | int tx, ty; | |
28 | ||
29 | // Do raw reads. | |
30 | while (TFT_read_touch(&tx, &ty, 1) == 1) { | |
31 | vTaskDelay(50 / portTICK_PERIOD_MS); | |
32 | } | |
33 | } | |
34 | ||
35 | ||
36 | ||
37 | void Buttons_Clear(void) | |
38 | { | |
39 | int i; | |
40 | ||
41 | for (i = 0; i < MAXBUTTONS; i++) { | |
42 | if ((Buttons[i].x != -1) && strlen(Buttons[i].text)) { | |
43 | TFT_fillRect(Buttons[i].x, Buttons[i].y, Buttons[i].w, Buttons[i].h, TFT_BLACK); | |
44 | } | |
45 | Buttons[i].x = -1; | |
46 | } | |
47 | } | |
48 | ||
49 | ||
50 | ||
51 | void Buttons_Add(int x, int y, int w, int h, char *txt, int order) | |
52 | { | |
53 | Buttons[order].x = x; | |
54 | Buttons[order].y = y; | |
55 | Buttons[order].w = w; | |
56 | Buttons[order].h = h; | |
57 | strncpy(Buttons[order].text, txt, 11); | |
58 | Buttons[order].dark = Buttons[order].small = false; | |
59 | } | |
60 | ||
61 | ||
62 | ||
63 | void Buttons_Show(void) | |
64 | { | |
65 | int i; | |
66 | const color_t KEY_NORM = { 191, 191, 191}; | |
67 | const color_t KEY_DARK = { 95, 95, 95}; | |
68 | const color_t KEY_LOCK = { 127, 127, 255}; | |
69 | ||
70 | _fg = TFT_BLACK; | |
71 | ||
72 | for (i = 0; i < MAXBUTTONS; i++) { | |
73 | if (Buttons[i].x != -1) { | |
74 | ||
75 | if (Buttons[i].lock) { | |
76 | _fg = TFT_BLACK; | |
77 | TFT_fillRoundRect(Buttons[i].x, Buttons[i].y, Buttons[i].w, Buttons[i].h, 5, KEY_LOCK); | |
78 | } else if (Buttons[i].dark) { | |
79 | _fg = TFT_WHITE; | |
80 | TFT_fillRoundRect(Buttons[i].x, Buttons[i].y, Buttons[i].w, Buttons[i].h, 5, KEY_DARK); | |
81 | } else { | |
82 | _fg = TFT_BLACK; | |
83 | TFT_fillRoundRect(Buttons[i].x, Buttons[i].y, Buttons[i].w, Buttons[i].h, 5, KEY_NORM); | |
84 | } | |
85 | TFT_drawRoundRect(Buttons[i].x, Buttons[i].y, Buttons[i].w, Buttons[i].h, 5, TFT_LIGHTGREY); | |
86 | if (Buttons[i].small) | |
87 | TFT_setFont(DEFAULT_FONT, NULL); // DEF_SMALL_FONT | |
88 | else | |
89 | TFT_setFont(DEJAVU18_FONT, NULL); | |
90 | font_transparent = 1; | |
91 | TFT_print(Buttons[i].text, | |
92 | Buttons[i].x + ((Buttons[i].w - TFT_getStringWidth(Buttons[i].text)) / 2), | |
93 | Buttons[i].y + 1 + ((Buttons[i].h - TFT_getfontheight()) / 2)); | |
94 | } | |
95 | } | |
96 | ||
97 | font_transparent = 0; | |
98 | } | |
99 | ||
100 | ||
101 | ||
102 | int Buttons_Search(int x, int y) | |
103 | { | |
104 | int i; | |
105 | ||
106 | for (i = 0; i < MAXBUTTONS; i++) { | |
107 | if (Buttons[i].x != -1) { | |
108 | if ((x >= Buttons[i].x) && (x <= (Buttons[i].x + Buttons[i].w)) && | |
109 | (y >= Buttons[i].y) && (y <= (Buttons[i].y + Buttons[i].h))) { | |
110 | return i; | |
111 | } | |
112 | } | |
113 | } | |
114 | ||
115 | return -1; | |
116 | } | |
117 | ||
118 | ||
119 | ||
120 | int Buttons_Scan(void) | |
121 | { | |
122 | int tx, ty, rc; | |
123 | static int ox = -1, oy = -1, vx = -1, vy = -1; | |
124 | static bool t_pressed = false, v_pressed = false; | |
125 | ||
126 | if (TFT_read_touch(&tx, &ty, 0)) { | |
127 | t_pressed = true; | |
128 | ox = tx; | |
129 | oy = ty; | |
130 | return -1; | |
131 | } else if (t_pressed) { | |
132 | rc = Buttons_Search(ox, oy); | |
133 | t_pressed = false; | |
134 | ox = oy = -1; | |
135 | return rc; | |
136 | } | |
137 | ||
138 | if (VNC_pointer_button & 0x07) { | |
139 | v_pressed = true; | |
140 | vx = VNC_pointer_x; | |
141 | vy = VNC_pointer_y; | |
142 | return -1; | |
143 | } else if (v_pressed) { | |
144 | rc = Buttons_Search(vx, vy); | |
145 | v_pressed = false; | |
146 | vx = vy = -1; | |
147 | return rc; | |
148 | } | |
149 | ||
150 | return -1; | |
151 | } | |
152 | ||
153 | ||
154 | ||
155 | static const uint8_t alphalow_tab[] = { 'q','w','e','r','t','y','u','i','o','p', | |
156 | 'a','s','d','f','g','h','j','k','l', | |
157 | 'z','x','c','v','b','n','m' }; | |
158 | ||
1
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
159 | /** |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
160 | * @brief Level 1 keys, lowercase alpha. |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
161 | */ |
0 | 162 | void B_AlphaLow(void) |
163 | { | |
164 | Buttons_Clear(); | |
165 | ||
166 | Buttons_Add( 2, 80,28,36,"q", 0); | |
167 | Buttons_Add( 34, 80,28,36,"w", 1); | |
168 | Buttons_Add( 66, 80,28,36,"e", 2); | |
169 | Buttons_Add( 98, 80,28,36,"r", 3); | |
170 | Buttons_Add(130, 80,28,36,"t", 4); | |
171 | Buttons_Add(162, 80,28,36,"y", 5); | |
172 | Buttons_Add(194, 80,28,36,"u", 6); | |
173 | Buttons_Add(226, 80,28,36,"i", 7); | |
174 | Buttons_Add(258, 80,28,36,"o", 8); | |
175 | Buttons_Add(290, 80,28,36,"p", 9); | |
176 | ||
177 | Buttons_Add( 18,120,28,36,"a",10); | |
178 | Buttons_Add( 50,120,28,36,"s",11); | |
179 | Buttons_Add( 82,120,28,36,"d",12); | |
180 | Buttons_Add(114,120,28,36,"f",13); | |
181 | Buttons_Add(146,120,28,36,"g",14); | |
182 | Buttons_Add(178,120,28,36,"h",15); | |
183 | Buttons_Add(210,120,28,36,"j",16); | |
184 | Buttons_Add(242,120,28,36,"k",17); | |
185 | Buttons_Add(274,120,28,36,"l",18); | |
186 | ||
187 | Buttons_Add( 50,160,28,36,"z",19); | |
188 | Buttons_Add( 82,160,28,36,"x",20); | |
189 | Buttons_Add(114,160,28,36,"c",21); | |
190 | Buttons_Add(146,160,28,36,"v",22); | |
191 | Buttons_Add(178,160,28,36,"b",23); | |
192 | Buttons_Add(210,160,28,36,"n",24); | |
193 | Buttons_Add(242,160,28,36,"m",25); | |
194 | ||
195 | Buttons_Add( 2,160,42,36,"caps",26); | |
196 | Buttons[26].dark = true; | |
197 | Buttons[26].small = true; | |
198 | Buttons[26].lock = false; | |
199 | Buttons_Add(276,160,42,36,"del",27); | |
200 | Buttons[27].dark = true; | |
201 | Buttons[27].small = true; | |
202 | ||
203 | Buttons_Add( 2,200,60,36,"123",28); | |
204 | Buttons[28].dark = true; | |
205 | Buttons_Add( 72,200,28,36,"/",29); | |
206 | Buttons_Add(108,200,104,36," ",30); | |
207 | Buttons_Add(220,200,28,36,".",31); | |
208 | Buttons_Add(258,200,60,36,"Ok",32); | |
209 | Buttons[32].dark = true; | |
210 | ||
211 | Buttons_Show(); | |
212 | } | |
213 | ||
214 | ||
215 | ||
216 | static const uint8_t alphacaps_tab[] = { 'Q','W','E','R','T','Y','U','I','O','P', | |
217 | 'A','S','D','F','G','H','J','K','L', | |
218 | 'Z','X','C','V','B','N','M' }; | |
219 | ||
1
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
220 | /** |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
221 | * @brief Level 2 and 3 keys, uppercase alpha. |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
222 | */ |
0 | 223 | void B_AlphaCaps(int level) |
224 | { | |
225 | Buttons_Clear(); | |
226 | ||
227 | Buttons_Add( 2, 80,28,36,"Q", 0); | |
228 | Buttons_Add( 34, 80,28,36,"W", 1); | |
229 | Buttons_Add( 66, 80,28,36,"E", 2); | |
230 | Buttons_Add( 98, 80,28,36,"R", 3); | |
231 | Buttons_Add(130, 80,28,36,"T", 4); | |
232 | Buttons_Add(162, 80,28,36,"Y", 5); | |
233 | Buttons_Add(194, 80,28,36,"U", 6); | |
234 | Buttons_Add(226, 80,28,36,"I", 7); | |
235 | Buttons_Add(258, 80,28,36,"O", 8); | |
236 | Buttons_Add(290, 80,28,36,"P", 9); | |
237 | ||
238 | Buttons_Add( 18,120,28,36,"A",10); | |
239 | Buttons_Add( 50,120,28,36,"S",11); | |
240 | Buttons_Add( 82,120,28,36,"D",12); | |
241 | Buttons_Add(114,120,28,36,"F",13); | |
242 | Buttons_Add(146,120,28,36,"G",14); | |
243 | Buttons_Add(178,120,28,36,"H",15); | |
244 | Buttons_Add(210,120,28,36,"J",16); | |
245 | Buttons_Add(242,120,28,36,"K",17); | |
246 | Buttons_Add(274,120,28,36,"L",18); | |
247 | ||
248 | Buttons_Add( 50,160,28,36,"Z",19); | |
249 | Buttons_Add( 82,160,28,36,"X",20); | |
250 | Buttons_Add(114,160,28,36,"C",21); | |
251 | Buttons_Add(146,160,28,36,"V",22); | |
252 | Buttons_Add(178,160,28,36,"B",23); | |
253 | Buttons_Add(210,160,28,36,"N",24); | |
254 | Buttons_Add(242,160,28,36,"M",25); | |
255 | ||
256 | Buttons_Add( 2,160,42,36,"caps",26); | |
257 | Buttons[26].dark = true; | |
258 | Buttons[26].small = true; | |
259 | if (level == 3) | |
260 | Buttons[26].lock = true; | |
261 | else | |
262 | Buttons[26].lock = false; | |
263 | Buttons_Add(276,160,42,36,"del",27); | |
264 | Buttons[27].dark = true; | |
265 | Buttons[27].small = true; | |
266 | ||
267 | Buttons_Add( 2,200,60,36,"123",28); | |
268 | Buttons[28].dark = true; | |
269 | Buttons_Add( 72,200,28,36,"/",29); | |
270 | Buttons_Add(108,204,100,36," ",30); | |
271 | Buttons_Add(220,200,28,36,".",31); | |
272 | Buttons_Add(258,200,60,36,"Ok",32); | |
273 | Buttons[32].dark = true; | |
274 | ||
275 | Buttons_Show(); | |
276 | } | |
277 | ||
278 | ||
279 | ||
280 | static const uint8_t nums1_tab[] = { '1','2','3','4','5','6','7','8','9','0', | |
281 | '!','@','#','$','/','^','&','*','(',')', | |
282 | '-','\'','\"',':',';',',','?' }; | |
283 | ||
1
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
284 | /** |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
285 | * @brief Level 4, numeric keys and symbol |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
286 | */ |
0 | 287 | void B_Nums1(void) |
288 | { | |
289 | Buttons_Clear(); | |
290 | ||
291 | Buttons_Add( 2, 80,28,36,"1", 0); | |
292 | Buttons_Add( 34, 80,28,36,"2", 1); | |
293 | Buttons_Add( 66, 80,28,36,"3", 2); | |
294 | Buttons_Add( 98, 80,28,36,"4", 3); | |
295 | Buttons_Add(130, 80,28,36,"5", 4); | |
296 | Buttons_Add(162, 80,28,36,"6", 5); | |
297 | Buttons_Add(194, 80,28,36,"7", 6); | |
298 | Buttons_Add(226, 80,28,36,"8", 7); | |
299 | Buttons_Add(258, 80,28,36,"9", 8); | |
300 | Buttons_Add(290, 80,28,36,"0", 9); | |
301 | ||
302 | Buttons_Add( 2,120,28,36,"!",10); | |
303 | Buttons_Add( 34,120,28,36,"@",11); | |
304 | Buttons_Add( 66,120,28,36,"#",12); | |
305 | Buttons_Add( 98,120,28,36,"$",13); | |
306 | Buttons_Add(130,120,28,36,"/",14); | |
307 | Buttons_Add(162,120,28,36,"^",15); | |
308 | Buttons_Add(194,120,28,36,"&",16); | |
309 | Buttons_Add(226,120,28,36,"*",17); | |
310 | Buttons_Add(258,120,28,36,"(",18); | |
311 | Buttons_Add(290,120,28,36,")",19); | |
312 | ||
313 | Buttons_Add( 50,160,28,36,"-",20); | |
314 | Buttons_Add( 82,160,28,36,"'",21); | |
315 | Buttons_Add(114,160,28,36,"\"",22); | |
316 | Buttons_Add(146,160,28,36,":",23); | |
317 | Buttons_Add(178,160,28,36,";",24); | |
318 | Buttons_Add(210,160,28,36,",",25); | |
319 | Buttons_Add(242,160,28,36,"?",26); | |
320 | ||
321 | Buttons_Add( 2,160,42,36,"1/2",27); | |
322 | Buttons[27].dark = true; | |
323 | Buttons_Add(276,160,42,36,"del",28); | |
324 | Buttons[28].dark = true; | |
325 | Buttons[28].small = true; | |
326 | ||
327 | Buttons_Add( 2,200,60,36,"ABC",29); | |
328 | Buttons[29].dark = true; | |
329 | Buttons_Add( 72,200,28,36,"/",30); | |
330 | Buttons_Add(108,204,100,36," ",31); | |
331 | Buttons_Add(220,200,28,36,".",32); | |
332 | Buttons_Add(258,200,60,36,"Ok",33); | |
333 | Buttons[33].dark = true; | |
334 | ||
335 | Buttons_Show(); | |
336 | } | |
337 | ||
338 | ||
339 | static const uint8_t nums2_tab[] = { '+','*','/','=','<','>','{','}','[',']', | |
340 | ' ',' ',' ',' ','%','~','`',' ',' ',' ', | |
341 | '_','\\','|',' ',' ',' ',' ' }; | |
342 | ||
1
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
343 | /** |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
344 | * @brief Level 5, symbol keys |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
345 | */ |
0 | 346 | void B_Nums2(void) |
347 | { | |
348 | Buttons_Clear(); | |
349 | ||
350 | Buttons_Add( 2, 80,28,36,"+", 0); | |
351 | Buttons_Add( 34, 80,28,36,"*", 1); | |
352 | Buttons_Add( 66, 80,28,36,"/", 2); | |
353 | Buttons_Add( 98, 80,28,36,"=", 3); | |
354 | Buttons_Add(130, 80,28,36,"<", 4); | |
355 | Buttons_Add(162, 80,28,36,">", 5); | |
356 | Buttons_Add(194, 80,28,36,"{", 6); | |
357 | Buttons_Add(226, 80,28,36,"}", 7); | |
358 | Buttons_Add(258, 80,28,36,"[", 8); | |
359 | Buttons_Add(290, 80,28,36,"]", 9); | |
360 | ||
361 | Buttons_Add( 2,120,28,36," ",10); | |
362 | Buttons_Add( 34,120,28,36," ",11); | |
363 | Buttons_Add( 66,120,28,36," ",12); | |
364 | Buttons_Add( 98,120,28,36," ",13); | |
365 | Buttons_Add(130,120,28,36,"%",14); | |
366 | Buttons_Add(162,120,28,36,"~",15); | |
367 | Buttons_Add(194,120,28,36,"`",16); | |
368 | Buttons_Add(226,120,28,36," ",17); | |
369 | Buttons_Add(258,120,28,36," ",18); | |
370 | Buttons_Add(290,120,28,36," ",19); | |
371 | ||
372 | Buttons_Add( 50,160,28,36,"_",20); | |
373 | Buttons_Add( 82,160,28,36,"\\",21); | |
374 | Buttons_Add(114,160,28,36,"|",22); | |
375 | Buttons_Add(146,160,28,36," ",23); | |
376 | Buttons_Add(178,160,28,36," ",24); | |
377 | Buttons_Add(210,160,28,36," ",25); | |
378 | Buttons_Add(242,160,28,36," ",26); | |
379 | ||
380 | Buttons_Add( 2,160,42,36,"2/2",27); | |
381 | Buttons[27].dark = true; | |
382 | Buttons_Add(276,160,42,36,"del",28); | |
383 | Buttons[28].dark = true; | |
384 | Buttons[28].small = true; | |
385 | ||
386 | Buttons_Add( 2,200,60,36,"ABC",29); | |
387 | Buttons[29].dark = true; | |
388 | Buttons_Add( 72,200,28,36,"/",30); | |
389 | Buttons_Add(108,204,100,36," ",31); | |
390 | Buttons_Add(220,200,28,36,".",32); | |
391 | Buttons_Add(258,200,60,36,"Ok",33); | |
392 | Buttons[33].dark = true; | |
393 | ||
394 | Buttons_Show(); | |
395 | } | |
396 | ||
397 | ||
398 | static const uint8_t digits_tab[] = { '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '+', '-', '.' }; | |
399 | ||
1
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
400 | /** |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
401 | * @brief A small nummeric keyboard |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
402 | */ |
0 | 403 | void B_Digits(void) |
404 | { | |
405 | Buttons_Clear(); | |
406 | ||
407 | Buttons_Add( 61,200,147,36,"0", 9); | |
408 | ||
409 | Buttons_Add( 61,160,47,36,"1", 0); | |
410 | Buttons_Add(111,160,47,36,"2", 1); | |
411 | Buttons_Add(161,160,47,36,"3", 2); | |
412 | Buttons_Add(211,160,47,36,"+",10); | |
413 | Buttons[10].dark = true; | |
414 | ||
415 | Buttons_Add( 61,120,47,36,"4", 3); | |
416 | Buttons_Add(111,120,47,36,"5", 4); | |
417 | Buttons_Add(161,120,47,36,"6", 5); | |
418 | Buttons_Add(211,120,47,36,"-",11); | |
419 | Buttons[11].dark = true; | |
420 | ||
421 | Buttons_Add( 61, 80,47,36,"7", 6); | |
422 | Buttons_Add(111, 80,47,36,"8", 7); | |
423 | Buttons_Add(161, 80,47,36,"9", 8); | |
424 | Buttons_Add(211, 80,47,36,".",12); | |
425 | Buttons[12].dark = true; | |
426 | ||
427 | Buttons_Add(211,200,47,36,"del",13); | |
428 | Buttons[13].dark = true; | |
429 | Buttons[13].small = true; | |
430 | ||
431 | Buttons_Add(271,200,47,36,"Ok",14); | |
432 | Buttons[14].dark = true; | |
433 | ||
434 | Buttons_Show(); | |
435 | } | |
436 | ||
437 | ||
438 | ||
439 | int KeyBoardAll(void) | |
440 | { | |
441 | int key; | |
442 | ||
443 | key = Buttons_Scan(); | |
444 | if (key == -1) | |
445 | return -1; | |
446 | ||
447 | switch (level) { | |
448 | case 1: if (key >= 0 && key <= 25) { | |
449 | key = alphalow_tab[key]; | |
450 | } else if (key == 26) { | |
451 | level = 2; | |
452 | B_AlphaCaps(level); | |
453 | } else if (key == 27) { | |
454 | key = 127; | |
455 | } else if (key == 28) { | |
456 | level = 4; | |
457 | B_Nums1(); | |
458 | } else if (key == 29) { | |
459 | key = '/'; | |
460 | } else if (key == 30) { | |
461 | key = ' '; | |
462 | } else if (key == 31) { | |
463 | key = '.'; | |
464 | } else if (key == 32) { | |
465 | key = 0; | |
466 | } | |
467 | break; | |
468 | case 2: | |
469 | case 3: if (key >= 0 && key <= 25) { | |
470 | key = alphacaps_tab[key]; | |
471 | if (level == 2) { | |
472 | level = 1; | |
473 | B_AlphaLow(); | |
474 | } | |
475 | } else if (key == 26 && level == 3) { | |
476 | level = 1; | |
477 | B_AlphaLow(); | |
478 | } else if (key == 26 && level == 2) { | |
479 | level = 3; | |
480 | B_AlphaCaps(level); | |
481 | } else if (key == 27) { | |
482 | key = 127; | |
483 | } else if (key == 28) { | |
484 | level = 4; | |
485 | B_Nums1(); | |
486 | } else if (key == 29) { | |
487 | key = '/'; | |
488 | } else if (key == 30) { | |
489 | key = ' '; | |
490 | } else if (key == 31) { | |
491 | key = '.'; | |
492 | } else if (key == 32) { | |
493 | key = 0; | |
494 | } | |
495 | break; | |
496 | case 4: if (key >= 0 && key <= 26) { | |
497 | key = nums1_tab[key]; | |
498 | } else if (key == 27) { | |
499 | level = 5; | |
500 | B_Nums2(); | |
501 | } else if (key == 28) { | |
502 | key = 127; | |
503 | } else if (key == 29) { | |
504 | level = 1; | |
505 | B_AlphaLow(); | |
506 | } else if (key == 30) { | |
507 | key = '/'; | |
508 | } else if (key == 31) { | |
509 | key = ' '; | |
510 | } else if (key == 32) { | |
511 | key = '.'; | |
512 | } else if (key == 33) { | |
513 | key = 0; | |
514 | } | |
515 | break; | |
516 | case 5: if (key >= 0 && key <= 26) { | |
517 | key = nums2_tab[key]; | |
518 | } else if (key == 27) { | |
519 | level = 4; | |
520 | B_Nums1(); | |
521 | } else if (key == 28) { | |
522 | key = 127; | |
523 | } else if (key == 29) { | |
524 | level = 1; | |
525 | B_AlphaLow(); | |
526 | } else if (key == 30) { | |
527 | key = '/'; | |
528 | } else if (key == 31) { | |
529 | key = ' '; | |
530 | } else if (key == 32) { | |
531 | key = '.'; | |
532 | } else if (key == 33) { | |
533 | key = 0; | |
534 | } | |
535 | break; | |
536 | } | |
537 | ||
538 | return key; | |
539 | } | |
540 | ||
541 | ||
542 | int KeyBoardDigits(void) | |
543 | { | |
544 | int key; | |
545 | ||
546 | key = Buttons_Scan(); | |
547 | if (key == -1) | |
548 | return -1; | |
549 | ||
550 | if (key >= 0 && key <= 12) { | |
551 | key = digits_tab[key]; | |
552 | } else if (key == 13) { | |
553 | key = 127; | |
554 | } else if (key == 14) { | |
555 | key = 0; | |
556 | } | |
557 | ||
558 | return key; | |
559 | } | |
560 | ||
561 | ||
562 | ||
563 | /**************************************************************************/ | |
564 | /* | |
565 | * Data show and edit functions. | |
566 | */ | |
567 | ||
568 | void ShowText(uint16_t x, uint16_t y, char *label, char *txt) | |
569 | { | |
570 | _fg = TFT_LIGHTGREY; | |
571 | TFT_print(label, x, y); | |
572 | _fg = TFT_YELLOW; | |
573 | TFT_print(" ", LASTX, LASTY); | |
574 | TFT_print(txt, LASTX, LASTY); | |
575 | } | |
576 | ||
577 | ||
578 | ||
579 | void ShowInteger(uint16_t x, uint16_t y, char *label, char *suffix, int val) | |
580 | { | |
581 | char tmp[32]; | |
582 | ||
583 | _fg = TFT_LIGHTGREY; | |
584 | TFT_print(label, x, y); | |
585 | _fg = TFT_YELLOW; | |
586 | sprintf(tmp, " %d", val); | |
587 | TFT_print(tmp, LASTX, LASTY); | |
588 | if (suffix) { | |
589 | _fg = TFT_LIGHTGREY; | |
590 | TFT_print(suffix, LASTX, LASTY); | |
591 | } | |
592 | } | |
593 | ||
594 | ||
595 | ||
596 | void ShowBool(uint16_t x, uint16_t y, char *label, bool val) | |
597 | { | |
598 | _fg = TFT_LIGHTGREY; | |
599 | TFT_print(label, x, y); | |
600 | _fg = TFT_YELLOW; | |
601 | if (val) | |
602 | TFT_print(" J", LASTX, LASTY); | |
603 | else | |
604 | TFT_print(" N", LASTX, LASTY); | |
605 | } | |
606 | ||
607 | ||
608 | ||
609 | void ShowSSR2(uint16_t x, uint16_t y, int val) | |
610 | { | |
611 | _fg = TFT_LIGHTGREY; | |
612 | TFT_print("SSR2 ", x, y); | |
613 | _fg = TFT_YELLOW; | |
614 | TFT_clearStringRect(TFT_X, TFT_Y, "HLT en MLT"); | |
615 | ||
616 | switch (val) { | |
617 | case SSR2_OFF: TFT_print("Uit", LASTX, LASTY); | |
618 | break; | |
619 | case SSR2_HLT_SHARE: TFT_print("HLT of MLT", LASTX, LASTY); | |
620 | break; | |
621 | ||
622 | case SSR2_HLT_IND: TFT_print("HLT en MLT", LASTX, LASTY); | |
623 | break; | |
624 | ||
625 | case SSR2_ON_IDLE: TFT_print("Idle", LASTX, LASTY); | |
626 | break; | |
627 | ||
628 | default: TFT_print("N/A", LASTX, LASTY); | |
629 | } | |
630 | } | |
631 | ||
632 | ||
633 | ||
634 | void ShowFloat(uint16_t x, uint16_t y, char *label, char *suffix, float val, int decimals) | |
635 | { | |
636 | char tmp[32]; | |
637 | ||
638 | _fg = TFT_LIGHTGREY; | |
639 | TFT_print(label, x, y); | |
640 | _fg = TFT_YELLOW; | |
641 | sprintf(tmp, " %.*f", decimals, val); | |
642 | TFT_print(tmp, LASTX, LASTY); | |
643 | if (suffix) { | |
644 | _fg = TFT_LIGHTGREY; | |
645 | TFT_print(suffix, LASTX, LASTY); | |
646 | } | |
647 | } | |
648 | ||
649 | ||
650 | ||
651 | void ShowDouble(uint16_t x, uint16_t y, char *label, char *suffix, double val, int decimals) | |
652 | { | |
653 | char tmp[32]; | |
654 | ||
655 | _fg = TFT_LIGHTGREY; | |
656 | TFT_print(label, x, y); | |
657 | _fg = TFT_YELLOW; | |
658 | sprintf(tmp, " %.*f", decimals, val); | |
659 | TFT_print(tmp, LASTX, LASTY); | |
660 | if (suffix) { | |
661 | _fg = TFT_LIGHTGREY; | |
662 | TFT_print(suffix, LASTX, LASTY); | |
663 | } | |
664 | } | |
665 | ||
666 | ||
667 | ||
668 | void Editer(char *label, char *txt, char *errmsg, int len, int type) | |
669 | { | |
670 | int key; | |
671 | ||
672 | _bg = TFT_BLACK; | |
673 | TFT_fillScreen(_bg); | |
674 | TFT_resetclipwin(); | |
675 | TopMessage("Wijzigen"); | |
676 | _fg = TFT_LIGHTGREY; | |
677 | TFT_setFont(DEFAULT_FONT, NULL); | |
678 | TFT_print(label, 2, 28); | |
679 | if (strlen(errmsg)) { | |
680 | _fg = TFT_RED; | |
681 | TFT_print(errmsg, 2, 60); | |
682 | } | |
683 | TFT_fillRect(2, 40, 10 * len, 14, TFT_BLUE); | |
684 | _fg = TFT_YELLOW; | |
685 | _bg = TFT_BLUE; | |
686 | TFT_print(txt, 2, 41); | |
687 | TFT_fillRect(TFT_X, 50, 10, 4, TFT_GREEN); | |
688 | ||
689 | switch(type) { | |
690 | case EDIT_TYPE_INT: | |
691 | B_Digits(); | |
692 | break; | |
693 | ||
694 | default: level = 1; | |
695 | B_AlphaLow(); | |
696 | break; | |
697 | } | |
698 | ||
699 | while (1) { | |
700 | switch (type) { | |
701 | case EDIT_TYPE_INT: | |
702 | key = KeyBoardDigits(); | |
703 | break; | |
704 | ||
705 | default: key = KeyBoardAll(); | |
706 | break; | |
707 | } | |
708 | ||
709 | if (key != -1) { | |
710 | ||
711 | if (key >= 32 && key <= 126 && strlen(txt) < len) { | |
712 | // Append key | |
713 | txt[strlen(txt) + 1] = '\0'; | |
714 | txt[strlen(txt)] = key; | |
715 | } else if (key == 127 && strlen(txt)) { | |
716 | // Delete key | |
717 | txt[strlen(txt) - 1] = '\0'; | |
718 | } | |
719 | ||
720 | _fg = TFT_YELLOW; | |
721 | _bg = TFT_BLACK; | |
722 | TFT_setFont(DEFAULT_FONT, NULL); | |
723 | TFT_fillRect(2, 40, 10 * len, 14, TFT_BLUE); | |
724 | TFT_print(txt, 2, 41); | |
725 | TFT_fillRect(TFT_X, 50, 10, 4, TFT_GREEN); | |
726 | } | |
727 | ||
728 | if (key == 0) | |
729 | break; | |
730 | ||
731 | vTaskDelay(20 / portTICK_PERIOD_MS); | |
732 | } | |
733 | } | |
734 | ||
735 | ||
736 | ||
737 | void EditText(char *label, char *txt, int len) | |
738 | { | |
739 | char errmsg[40]; | |
740 | ||
741 | errmsg[0] = '\0'; | |
742 | while (1) { | |
743 | Editer(label, txt, errmsg, len, EDIT_TYPE_TEXT); | |
744 | if (strlen(txt)) | |
745 | break; | |
746 | sprintf(errmsg, "Tekst veld mag niet leeg zijn"); | |
747 | } | |
748 | } | |
749 | ||
750 | ||
751 | ||
752 | void EditTextMin(char *label, char *txt, int len, int min) | |
753 | { | |
754 | char errmsg[40]; | |
755 | ||
756 | errmsg[0] = '\0'; | |
757 | while (1) { | |
758 | Editer(label, txt, errmsg, len, EDIT_TYPE_TEXT); | |
759 | if (strlen(txt) >= min) | |
760 | break; | |
761 | sprintf(errmsg, "Tekst veld moet tussen %d en %d lang zijn", min, len); | |
762 | } | |
763 | } | |
764 | ||
765 | ||
766 | ||
767 | void EditInt(char *label, int *val, int min, int max) | |
768 | { | |
769 | char *valstr, errmsg[40]; | |
770 | int newval; | |
771 | ||
772 | errmsg[0] = '\0'; | |
773 | valstr = malloc(20); | |
774 | sprintf(valstr, "%d", *val); | |
775 | ||
776 | while (1) { | |
777 | Editer(label, valstr, errmsg, 8, EDIT_TYPE_INT); | |
778 | newval = atoi(valstr); | |
779 | if (newval < min || newval > max) { | |
780 | sprintf(errmsg, "De waarde moet tussen %d en %d zijn.", min, max); | |
781 | } else { | |
782 | break; | |
783 | } | |
784 | } | |
785 | ||
786 | *val = newval; | |
787 | free(valstr); | |
788 | } | |
789 | ||
790 | ||
791 | ||
792 | void EditUint8(char *label, uint8_t *val, uint8_t min, uint8_t max) | |
793 | { | |
794 | char *valstr, errmsg[40]; | |
795 | uint8_t newval; | |
796 | ||
797 | errmsg[0] = '\0'; | |
798 | valstr = malloc(20); | |
799 | sprintf(valstr, "%d", *val); | |
800 | ||
801 | while (1) { | |
802 | Editer(label, valstr, errmsg, 5, EDIT_TYPE_INT); | |
803 | newval = atoi(valstr); | |
804 | if (newval < min || newval > max) { | |
805 | sprintf(errmsg, "De waarde moet tussen %d en %d zijn.", min, max); | |
806 | } else { | |
807 | break; | |
808 | } | |
809 | } | |
810 | ||
811 | *val = newval; | |
812 | free(valstr); | |
813 | } | |
814 | ||
815 | ||
816 | ||
817 | void EditUint16(char *label, uint16_t *val, uint16_t min, uint16_t max) | |
818 | { | |
819 | char *valstr, errmsg[40]; | |
820 | uint16_t newval; | |
821 | ||
822 | errmsg[0] = '\0'; | |
823 | valstr = malloc(20); | |
824 | sprintf(valstr, "%d", *val); | |
825 | ||
826 | while (1) { | |
827 | Editer(label, valstr, errmsg, 5, EDIT_TYPE_INT); | |
828 | newval = atoi(valstr); | |
829 | if (newval < min || newval > max) { | |
830 | sprintf(errmsg, "De waarde moet tussen %d en %d zijn.", min, max); | |
831 | } else { | |
832 | break; | |
833 | } | |
834 | } | |
835 | ||
836 | *val = newval; | |
837 | free(valstr); | |
838 | } | |
839 | ||
840 | ||
841 | ||
842 | void EditFloat(char *label, float *val, float min, float max, int decimals) | |
843 | { | |
844 | char *valstr, errmsg[40]; | |
845 | float newval; | |
846 | ||
847 | errmsg[0] = '\0'; | |
848 | valstr = malloc(30); | |
849 | sprintf(valstr, " %.*f", decimals, *val); | |
850 | ||
851 | while (1) { | |
852 | Editer(label, valstr, errmsg, 25, EDIT_TYPE_INT); | |
853 | newval = atof(valstr); | |
854 | if (newval < min || newval > max) { | |
855 | sprintf(errmsg, "De waarde moet tussen %.2f en %.2f zijn.", min, max); | |
856 | } else { | |
857 | break; | |
858 | } | |
859 | } | |
860 | ||
861 | *val = newval; | |
862 | free(valstr); | |
863 | } | |
864 | ||
865 | ||
866 | ||
867 | void EditDouble(char *label, double *val, double min, double max, int decimals) | |
868 | { | |
869 | char *valstr, errmsg[40]; | |
870 | double newval; | |
871 | ||
872 | errmsg[0] = '\0'; | |
873 | valstr = malloc(30); | |
874 | sprintf(valstr, " %.*f", decimals, *val); | |
875 | ||
876 | while (1) { | |
877 | Editer(label, valstr, errmsg, 25, EDIT_TYPE_INT); | |
878 | newval = atof(valstr); | |
879 | if (newval < min || newval > max) { | |
880 | sprintf(errmsg, "De waarde moet tussen %.2f en %.2f zijn.", min, max); | |
881 | } else { | |
882 | break; | |
883 | } | |
884 | } | |
885 | ||
886 | *val = newval; | |
887 | free(valstr); | |
888 | } | |
889 | ||
890 | ||
891 | ||
892 | void EditBool(char *label, bool *val) | |
893 | { | |
894 | bool loop = true, value = *val; | |
895 | int curpos; | |
896 | ||
897 | _bg = TFT_BLACK; | |
898 | TFT_fillScreen(_bg); | |
899 | TFT_resetclipwin(); | |
900 | TopMessage("Wijzigen"); | |
901 | _fg = TFT_LIGHTGREY; | |
902 | TFT_setFont(DEFAULT_FONT, NULL); | |
903 | TFT_print(label, 2, 28); | |
904 | curpos = TFT_X; | |
905 | _fg = TFT_YELLOW; | |
906 | (value) ? TFT_print(" J ", curpos, 28) : TFT_print(" N ", curpos, 28); | |
907 | ||
908 | Buttons_Clear(); | |
909 | Buttons_Add( 40, 100, 80, 40, "J/N", 0); | |
910 | Buttons_Add(200, 100, 80, 40, "Ok", 1); | |
911 | Buttons_Show(); | |
912 | ||
913 | while (loop) { | |
914 | switch (Buttons_Scan()) { | |
915 | case 0: TFT_setFont(DEFAULT_FONT, NULL); | |
916 | _fg = TFT_YELLOW; | |
917 | if (value) { | |
918 | value = false; | |
919 | TFT_print(" N ", curpos, 28); | |
920 | } else { | |
921 | value = true; | |
922 | TFT_print(" J ", curpos, 28); | |
923 | } | |
924 | break; | |
925 | ||
926 | case 1: loop = false; | |
927 | break; | |
928 | ||
929 | default: break; | |
930 | } | |
931 | vTaskDelay(20 / portTICK_PERIOD_MS); | |
932 | } | |
933 | *val = value; | |
934 | } | |
935 | ||
936 | ||
937 | ||
938 | void EditSSR2(int *val) | |
939 | { | |
940 | bool loop = true; | |
941 | int value = *val; | |
942 | int key; | |
943 | ||
944 | _bg = TFT_BLACK; | |
945 | TFT_fillScreen(_bg); | |
946 | TFT_resetclipwin(); | |
947 | TopMessage("Wijzigen"); | |
948 | TFT_setFont(DEFAULT_FONT, NULL); | |
949 | ShowSSR2(2, 28, value); | |
950 | ||
951 | Buttons_Clear(); | |
952 | Buttons_Add( 20, 60,120, 40, "Uit", 0); | |
953 | Buttons_Add(180, 60,120, 40, "HLT of MLT", 1); | |
954 | Buttons_Add( 20, 130,120, 40, "HLT en MLT", 2); | |
955 | Buttons_Add(180, 130,120, 40, "Idle", 3); | |
956 | Buttons_Add(120, 200, 80, 40, "Ok", 4); | |
957 | Buttons_Show(); | |
958 | ||
959 | while (loop) { | |
960 | key = Buttons_Scan(); | |
961 | ||
962 | if (key >= 0 && key <= 3) { | |
963 | value = key; | |
964 | TFT_setFont(DEFAULT_FONT, NULL); | |
965 | ShowSSR2(2, 28, value); | |
966 | } else if (key == 4) { | |
967 | loop = false; | |
968 | } | |
969 | vTaskDelay(20 / portTICK_PERIOD_MS); | |
970 | } | |
971 | *val = value; | |
972 | } | |
973 | ||
974 | ||
975 | ||
976 | int Confirm(char *top, char *ack, char *nak) | |
977 | { | |
978 | int rc = false; | |
979 | bool loop = true; | |
980 | ||
981 | TFT_fillScreen(TFT_BLACK); | |
982 | TopMessage(top); | |
983 | Buttons_Clear(); | |
984 | Buttons_Add( 40, 100, 80, 40, ack, 0); | |
985 | Buttons_Add(200, 100, 80, 40, nak, 1); | |
986 | Buttons_Show(); | |
987 | SoundPlay(SOUND_Prompt); | |
988 | ||
989 | while (loop) { | |
990 | switch (Buttons_Scan()) { | |
991 | case 0: loop = false; | |
992 | rc = true; | |
993 | break; | |
994 | ||
995 | case 1: loop = false; | |
996 | rc = false; | |
997 | break; | |
998 | ||
999 | default: | |
1000 | break; | |
1001 | } | |
1002 | vTaskDelay(50 / portTICK_PERIOD_MS); | |
1003 | } | |
1004 | ||
1005 | Buttons_Clear(); | |
1006 | return rc; | |
1007 | } | |
1008 | ||
1009 |