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