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