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