comparison Discovery/Src/tMenuEdit.c @ 38:5f11787b4f42

include in ostc4 repository
author heinrichsweikamp
date Sat, 28 Apr 2018 11:52:34 +0200
parents
children cc8e24374b83
comparison
equal deleted inserted replaced
37:ccc45c0e1ea2 38:5f11787b4f42
1 ///////////////////////////////////////////////////////////////////////////////
2 /// -*- coding: UTF-8 -*-
3 ///
4 /// \file Discovery/Src/tMenuEdit.c
5 /// \brief Main Template file for Menu Setting Modifications
6 /// \author heinrichs weikamp gmbh
7 /// \date 04-July-2014
8 ///
9 /// \details
10 ///
11 /// $Id$
12 ///////////////////////////////////////////////////////////////////////////////
13 /// \par Copyright (c) 2014-2018 Heinrichs Weikamp gmbh
14 ///
15 /// This program is free software: you can redistribute it and/or modify
16 /// it under the terms of the GNU General Public License as published by
17 /// the Free Software Foundation, either version 3 of the License, or
18 /// (at your option) any later version.
19 ///
20 /// This program is distributed in the hope that it will be useful,
21 /// but WITHOUT ANY WARRANTY; without even the implied warranty of
22 /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 /// GNU General Public License for more details.
24 ///
25 /// You should have received a copy of the GNU General Public License
26 /// along with this program. If not, see <http://www.gnu.org/licenses/>.
27 //////////////////////////////////////////////////////////////////////////////
28
29 /* Includes ------------------------------------------------------------------*/
30 #include "tMenuEdit.h"
31
32 #include "externLogbookFlash.h"
33 #include "gfx_fonts.h"
34 #include "tHome.h"
35 #include "tInfoCompass.h"
36 #include "tMenuEditHardware.h"
37 #include "tMenuEditPlanner.h"
38 #include "tMenuEditSystem.h"
39 #include "tMenuEditXtra.h"
40
41 /* Private types -------------------------------------------------------------*/
42 #define TEXTSIZE 16
43
44 typedef struct
45 {
46 uint32_t pEventFunction;
47 uint32_t callerID;
48 } SEventHandler;
49
50 typedef struct
51 {
52 uint32_t pEventFunction;
53 uint8_t functionParameter;
54 uint8_t line;
55 } SBackMenuHandler;
56
57 typedef struct
58 {
59 char orgText[32];
60 char newText[32];
61 uint16_t input[4];
62 uint16_t coord[3];
63 int8_t begin[4], size[4];
64 tFont *fontUsed;
65 uint32_t callerID;
66 uint8_t maintype;
67 uint8_t subtype;
68 } SEditIdent;
69
70 typedef enum
71 {
72 FIELD_NUMBERS = 0,
73 FIELD_BUTTON,
74 FIELD_SELECT,
75 FIELD_SYMBOL,
76 FIELD_TOGGLE,
77 FIELD_ON_OFF,
78 FIELD_UDIGIT,
79 FIELD_2DIGIT,
80 FIELD_3DIGIT,
81 FIELD_FLOAT,
82 FIELD_END
83 } SField;
84
85 /* Private variables ---------------------------------------------------------*/
86 GFX_DrawCfgScreen tMEscreen;
87 GFX_DrawCfgScreen tMEcursor;
88 GFX_DrawCfgScreen tMEcursorNew;
89
90 uint32_t menuID;
91 uint8_t menuColor;
92
93 int8_t id = 0;
94 int8_t idLast = -1;
95 SEditIdent ident[10];
96 int8_t tME_stop = 0;
97
98 int8_t evid = 0;
99 int8_t evidLast = -1;
100 SEventHandler event[10];
101
102 SBackMenuHandler backmenu;
103
104 int8_t block = 0;
105 int8_t subBlockPosition = 0;
106
107 _Bool EnterPressedBeforeButtonAction = 0;
108 _Bool EnterPressed = 0;
109
110 _Bool WriteSettings = 0;
111
112 /* Private function prototypes -----------------------------------------------*/
113 void draw_tMEdesign(void);
114 void set_cursor(uint8_t forThisIdentID);
115 void set_cursorNew(uint8_t forThisIdentID);
116 void startMenuEditFieldSelect(void);
117 void create_newText_for_actual_Id(void);
118 void write_content_of_actual_Id(void);
119 void clean_content_of_actual_Id(void);
120 void write_content_without_Id(void);
121
122 void nextMenuEditFieldDigit(void);
123 void upMenuEditFieldDigit(void);
124 void downMenuEditFieldDigit(void);
125
126 void draw_tMEcursorNewDesign(void);
127
128 void exitMenuEdit(uint8_t writeSettingsIfEnterPressed);
129 uint8_t split_Content_to_Digit_helper(uint8_t inContentAscii, uint8_t *outDigit100, uint8_t *outDigit10, uint8_t *outDigit1);
130
131 /* Exported functions --------------------------------------------------------*/
132
133 void tMenuEdit_init(void)
134 {
135 tMEcursor.FBStartAdress = getFrame(7);
136 tMEcursor.ImageHeight = 480;
137 tMEcursor.ImageWidth = 800;
138 tMEcursor.LayerIndex = 0;
139
140 GFX_fill_buffer(tMEcursor.FBStartAdress, 0xFF, CLUT_MenuEditCursor);
141
142 tMEcursorNew.FBStartAdress = getFrame(8);
143 tMEcursorNew.ImageHeight = 390;
144 tMEcursorNew.ImageWidth = 800;
145 tMEcursorNew.LayerIndex = 0;
146
147 draw_tMEcursorNewDesign();
148 }
149
150 void stop_cursor_fields(void)
151 {
152 tME_stop = 1;
153 }
154
155 void resetMenuEdit(uint8_t color)
156 {
157 id = 0;
158 idLast = -1;
159 evid = 0;
160 evidLast = -1;
161 tME_stop = 0;
162 EnterPressed = 0;
163 EnterPressedBeforeButtonAction = 0;
164
165 setBackMenu(0,0,0);
166
167 releaseFrame(9,tMEscreen.FBStartAdress);
168
169 tMEscreen.FBStartAdress = getFrame(9);
170 tMEscreen.ImageHeight = 480;
171 tMEscreen.ImageWidth = 800;
172 tMEscreen.LayerIndex = 1;
173
174 /*
175 write_content_simple(&tMEscreen, 0, 38, 0, &Awe48,"x",CLUT_ButtonSymbols);
176 write_content_simple(&tMEscreen, 800-46, 800, 0, &Awe48,"u",CLUT_ButtonSymbols);
177 write_content_simple(&tMEscreen, 0, 45, 480-45, &Awe48,"d",CLUT_ButtonSymbols);
178 write_content_simple(&tMEscreen, 800-48, 800, 480-45, &Awe48,"e",CLUT_ButtonSymbols);
179 */
180 menuID = get_globalState();
181
182 menuColor = color;
183
184 // draw_tMEdesign();
185 // GFX_SetFramesTopBottom(tMEscreen.FBStartAdress, tMEcursor.FBStartAdress,480);
186 uint8_t line = 1;
187 // GFX_SetFramesTopBottom(tMEscreen.FBStartAdress, (tMEcursorNew.FBStartAdress) + 65*2*(line - 1),390);
188 GFX_SetFrameTop(tMEscreen.FBStartAdress);
189 GFX_SetFrameBottom((tMEcursorNew.FBStartAdress) + 65*2*(line - 1), 0, 25, 800, 390);
190 }
191
192
193 void tMenuEdit_refresh_live_content(void)
194 {
195
196 if(get_globalState() == (StMHARD3_O2_Sensor1 & MaskFieldDigit))
197 {
198 uint32_t rememberPage = tMEscreen.FBStartAdress;
199 tMEscreen.FBStartAdress = getFrame(9);
200 // draw_tMEdesign();
201 refresh_O2Sensors();
202 GFX_SetFrameTop(tMEscreen.FBStartAdress);
203 releaseFrame(9,rememberPage);
204 }
205 else if(get_globalState() == (StMHARD2_Compass_SetCourse & MaskFieldDigit))
206 {
207 uint32_t rememberPage = tMEscreen.FBStartAdress;
208 tMEscreen.FBStartAdress = getFrame(9);
209 refresh_CompassEdit();
210 GFX_SetFrameTop(tMEscreen.FBStartAdress);
211 releaseFrame(9,rememberPage);
212 }
213 else if(get_globalState() == (StMXTRA_CompassHeading & MaskFieldDigit))
214 {
215 uint32_t rememberPage = tMEscreen.FBStartAdress;
216 tMEscreen.FBStartAdress = getFrame(9);
217 // draw_tMEdesign();
218 refresh_CompassHeading();
219 GFX_SetFrameTop(tMEscreen.FBStartAdress);
220 releaseFrame(9,rememberPage);
221 }
222 else if(get_globalState() == (StMSYS5_Info & MaskFieldDigit))
223 {
224 uint32_t rememberPage = tMEscreen.FBStartAdress;
225 tMEscreen.FBStartAdress = getFrame(9);
226 refresh_InformationPage();
227 GFX_SetFrameTop(tMEscreen.FBStartAdress);
228 releaseFrame(9,rememberPage);
229 }
230 else if(get_globalState() == (StMPLAN5_ExitResult & MaskFieldDigit))
231 {
232 uint32_t rememberPage = tMEscreen.FBStartAdress;
233 tMEscreen.FBStartAdress = getFrame(9);
234 refresh_PlanResult();
235 GFX_SetFrameTop(tMEscreen.FBStartAdress);
236 releaseFrame(9,rememberPage);
237 }
238 else if(get_globalState() == (StMHARD5_Button1 & MaskFieldDigit)) // will not be executed in EditFieldMode as global state is different
239 {
240 uint32_t rememberPage = tMEscreen.FBStartAdress;
241 tMEscreen.FBStartAdress = getFrame(9);
242 refresh_ButtonValuesFromPIC();
243 GFX_SetFrameTop(tMEscreen.FBStartAdress);
244 releaseFrame(9,rememberPage);
245 }
246 /*
247 else if(get_globalState() == (StMHARD6_ScooterDrag & MaskFieldDigit))
248 {
249 uint32_t rememberPage = tMEscreen.FBStartAdress;
250 tMEscreen.FBStartAdress = getFrame(9);
251 refresh_ScooterControl();
252 GFX_SetFrameTop(tMEscreen.FBStartAdress);
253 releaseFrame(9,rememberPage);
254 }
255 */
256 else if(get_globalState() == (StMSYS3_Units & MaskFieldDigit))
257 {
258 uint32_t rememberPage = tMEscreen.FBStartAdress;
259 tMEscreen.FBStartAdress = getFrame(9);
260 refresh_Design();
261 GFX_SetFrameTop(tMEscreen.FBStartAdress);
262 releaseFrame(9,rememberPage);
263 }
264 else if(get_globalState() == (StMSYS4_CViewTimeout & MaskFieldDigit))
265 {
266 uint32_t rememberPage = tMEscreen.FBStartAdress;
267 tMEscreen.FBStartAdress = getFrame(9);
268 refresh_Customviews();
269 GFX_SetFrameTop(tMEscreen.FBStartAdress);
270 releaseFrame(9,rememberPage);
271 }
272 }
273
274 void tMenuEdit_writeSettingsToFlash(void)
275 {
276 if(WriteSettings)
277 {
278 GFX_logoAutoOff();
279 ext_flash_write_settings();
280 WriteSettings = 0;
281 }
282 }
283
284 void helperLeaveMenuEditField(uint8_t idID)
285 {
286 if(ident[idID].maintype == FIELD_NUMBERS)
287 {
288 change_CLUT_entry((CLUT_MenuEditField0 + idID), CLUT_MenuEditFieldRegular);
289 }
290 }
291
292
293 void helperGotoMenuEditField(uint8_t idID)
294 {
295 /*
296 if(ident[idID].maintype == FIELD_NUMBERS)
297 {
298 change_CLUT_entry((CLUT_MenuEditField0 + idID), CLUT_MenuEditFieldSelected);
299 }
300 */
301 set_cursorNew(idID);
302 // set_cursor(idID);
303 }
304
305
306 void exitMenuEdit_to_BackMenu(void)
307 {
308 _Bool EnterPressedBackup = EnterPressed;
309
310 if(backmenu.pEventFunction)
311 {
312 ((void (*)(uint8_t))(backmenu.pEventFunction))(backmenu.functionParameter);
313
314 EnterPressed = EnterPressedBackup;
315 // if(backmenu.line > 1)
316 // helperGotoMenuEditField(backmenu.line);
317 }
318 }
319
320
321 void exitMenuEdit_to_Menu_with_Menu_Update(void)
322 {
323 EnterPressed = 1;
324 exitMenuEdit(1);
325 }
326
327
328 void exitMenuEdit_to_Menu_with_Menu_Update_do_not_write_settings_for_this_only(void)
329 {
330 EnterPressed = 1;
331 exitMenuEdit(0);
332 }
333
334
335 void exitMenuEdit_to_Home_with_Menu_Update(void)
336 {
337 EnterPressed = 1;
338 exitMenuEdit(1);
339 set_globalState_tHome();
340 }
341
342
343 void exitMenuEdit_to_InfoCompassCalibration(void)
344 {
345 exitMenuEdit(1);
346 openInfo_Compass();
347 }
348
349
350 void exitMenuEdit_to_Home(void)
351 {
352 exitMenuEdit(1);
353 set_globalState_tHome();
354 }
355
356
357 void exitMenuEdit(uint8_t writeSettingsIfEnterPressed)
358 {
359 openMenu(0);
360 if(EnterPressed)
361 {
362 updateMenu();
363 if((stateUsed->mode == MODE_SURFACE) && writeSettingsIfEnterPressed)
364 WriteSettings = 1;
365 }
366 releaseFrame(9,tMEscreen.FBStartAdress);
367 }
368
369
370 void exitMenuEditBackMenuOption(void)
371 {
372 if(backmenu.pEventFunction == 0)
373 exitMenuEdit(1);
374 else
375 exitMenuEdit_to_BackMenu();
376 }
377
378
379 void startMenuEditFieldSelect(void)
380 {
381 id = 0;
382 helperGotoMenuEditField(id);
383 }
384
385
386 void nextMenuEditField(void)
387 {
388 helperLeaveMenuEditField(id);
389
390 if(id < idLast)
391 id++;
392 else
393 id = 0;
394 helperGotoMenuEditField(id);
395 }
396
397 /*
398 void previousMenuEditField(void)
399 {
400 helperLeaveMenuEditField(id);
401 if(id > 0)
402 id--;
403 else
404 id = idLast;
405 helperGotoMenuEditField(id);
406 }
407 */
408
409 _Bool inc_subBlock_or_block_of_actual_id(void)
410 {
411 if(event[evid].callerID != ident[id].callerID)
412 return 0;
413
414 if((ident[id].subtype != FIELD_3DIGIT) && (ident[id].subtype != FIELD_2DIGIT) && ((subBlockPosition + 1) < ident[id].size[block]))
415 {
416 subBlockPosition++;
417 return 1;
418 }
419
420 if(((block + 1) < 4) && (ident[id].size[block+1] > 0))
421 {
422 block++;
423 subBlockPosition = 0;
424 return 1;
425 }
426
427 return 0;
428 }
429
430
431 uint8_t get_newContent_of_actual_id_block_and_subBlock(uint8_t action)
432 {
433 uint8_t (*onActionFunc)(uint32_t, uint8_t, uint8_t, uint8_t, uint8_t);
434 uint8_t content;
435
436 if(event[evid].callerID != ident[id].callerID)
437 return 0;
438
439 onActionFunc = (uint8_t (*)(uint32_t, uint8_t, uint8_t, uint8_t, uint8_t))(event[evid].pEventFunction);
440
441 if((ident[id].maintype == FIELD_NUMBERS) && (ident[id].subtype == FIELD_3DIGIT))
442 {
443 content = 100 * ( ident[id].newText[ident[id].begin[block] + 0] - '0');
444 content += 10 * ( ident[id].newText[ident[id].begin[block] + 1] - '0');
445 content += ident[id].newText[ident[id].begin[block] + 2];
446 }
447 else
448 if((ident[id].maintype == FIELD_NUMBERS) && (ident[id].subtype == FIELD_2DIGIT))
449 {
450 content = 10 * (ident[id].newText[ident[id].begin[block] + 0] - '0');
451 content += ident[id].newText[ident[id].begin[block] + 1];
452 }
453 else
454 if(ident[id].maintype == FIELD_NUMBERS)
455 content = ident[id].newText[ident[id].begin[block] + subBlockPosition];
456 else
457 if(ident[id].maintype == FIELD_ON_OFF)
458 content = ident[id].input[block];
459 else
460 content = 0; /* just a default for protection */
461
462 return onActionFunc(ident[id].callerID, block, subBlockPosition, content, action);
463 }
464
465 void mark_digit_of_actual_id_with_this_block_and_subBlock(int8_t oldblock, int8_t oldsubblockpos)
466 {
467 char oneCharText[2];
468 uint16_t positionOffset;
469
470 if(event[evid].callerID != ident[id].callerID)
471 return;
472
473 if(ident[id].maintype == FIELD_NUMBERS)
474 {
475 oneCharText[0] = ident[id].newText[ident[id].begin[oldblock] + oldsubblockpos];
476 oneCharText[1] = 0;
477 positionOffset = GFX_return_offset(ident[id].fontUsed, ident[id].newText, ident[id].begin[oldblock] + oldsubblockpos);
478 write_content( ident[id].coord[0] + positionOffset, ident[id].coord[1], ident[id].coord[2], ident[id].fontUsed, oneCharText, CLUT_MenuEditFieldSelected);
479 }
480 }
481
482
483 void mark_new_2digit_of_actual_id_block(void)
484 {
485 char oneCharText[3];
486 uint16_t positionOffset;
487
488 if(event[evid].callerID != ident[id].callerID)
489 return;
490
491 if(ident[id].maintype == FIELD_NUMBERS)
492 {
493 oneCharText[0] = ident[id].newText[ident[id].begin[block] + 0];
494 oneCharText[1] = ident[id].newText[ident[id].begin[block] + 1];
495 oneCharText[2] = 0;
496 positionOffset = GFX_return_offset(ident[id].fontUsed, ident[id].newText, ident[id].begin[block] + 0);
497 write_content( ident[id].coord[0] + positionOffset, ident[id].coord[1], ident[id].coord[2], ident[id].fontUsed, oneCharText, CLUT_MenuEditDigit);
498 }
499 }
500
501
502 void mark_new_3digit_of_actual_id_block(void)
503 {
504 char oneCharText[4];
505 uint16_t positionOffset;
506
507 if(event[evid].callerID != ident[id].callerID)
508 return;
509
510 if(ident[id].maintype == FIELD_NUMBERS)
511 {
512 oneCharText[0] = ident[id].newText[ident[id].begin[block] + 0];
513 oneCharText[1] = ident[id].newText[ident[id].begin[block] + 1];
514 oneCharText[2] = ident[id].newText[ident[id].begin[block] + 2];
515 oneCharText[3] = 0;
516 positionOffset = GFX_return_offset(ident[id].fontUsed, ident[id].newText, ident[id].begin[block] + 0);
517 write_content( ident[id].coord[0] + positionOffset, ident[id].coord[1], ident[id].coord[2], ident[id].fontUsed, oneCharText, CLUT_MenuEditDigit);
518 }
519 }
520
521
522 void mark_new_digit_of_actual_id_block_and_subBlock(void)
523 {
524 char oneCharText[2];
525 uint16_t positionOffset;
526
527 if(event[evid].callerID != ident[id].callerID)
528 return;
529
530 if(ident[id].maintype == FIELD_NUMBERS)
531 {
532 oneCharText[0] = ident[id].newText[ident[id].begin[block] + subBlockPosition];
533 oneCharText[1] = 0;
534 positionOffset = GFX_return_offset(ident[id].fontUsed, ident[id].newText, ident[id].begin[block] + subBlockPosition);
535 write_content( ident[id].coord[0] + positionOffset, ident[id].coord[1], ident[id].coord[2], ident[id].fontUsed, oneCharText, CLUT_MenuEditDigit);
536 }
537 }
538
539
540 void enterMenuEditField(void)
541 {
542 uint8_t newContent;
543 uint8_t digit100;
544 uint8_t digit10;
545 uint8_t digit1;
546
547 evid = 0;
548 while((evid < evidLast) && (event[evid].callerID != ident[id].callerID))
549 {
550 evid++;
551 }
552
553 if(event[evid].callerID != ident[id].callerID)
554 return;
555
556 set_globalState(event[evid].callerID);
557 block = 0;
558 subBlockPosition = 0;
559
560
561 if(ident[id].maintype == FIELD_NUMBERS)
562 {
563 change_CLUT_entry(CLUT_MenuEditLineSelected, CLUT_MenuEditCursor);
564 // old stuff? hw 150916, reactivated 150923, this shows which digit will be changed now as it marks the other grey/black
565 // now fixed for button settings with newContent <= '0'+99 condition
566 change_CLUT_entry((CLUT_MenuEditField0 + id), CLUT_MenuEditFieldSelected);
567 }
568
569 newContent = get_newContent_of_actual_id_block_and_subBlock(ACTION_BUTTON_ENTER);
570
571 if (((newContent == UPDATE_DIVESETTINGS) || (newContent == UPDATE_AND_EXIT_TO_HOME) || (newContent == UPDATE_AND_EXIT_TO_MENU)) && (actual_menu_content == MENU_SURFACE))
572 createDiveSettings();
573
574 if(newContent == EXIT_TO_MENU_WITH_LOGO)
575 {
576 GFX_logoAutoOff();
577 }
578
579 if((newContent == EXIT_TO_MENU) || (newContent == UPDATE_AND_EXIT_TO_MENU) || (newContent == EXIT_TO_MENU_WITH_LOGO))
580 {
581 if(backmenu.pEventFunction == 0)
582 exitMenuEdit(1);
583 else
584 exitMenuEdit_to_BackMenu();
585 return;
586 }
587
588 if((newContent == EXIT_TO_HOME) || (newContent == UPDATE_AND_EXIT_TO_HOME))
589 {
590 exitMenuEdit_to_Home();
591 return;
592 }
593
594 if(newContent == EXIT_TO_INFO_COMPASS)
595 {
596 exitMenuEdit_to_InfoCompassCalibration();
597 return;
598 }
599
600
601 switch(ident[id].maintype)
602 {
603 case FIELD_NUMBERS:
604 write_buttonTextline(TXT2BYTE_ButtonMinus,TXT2BYTE_ButtonEnter,TXT2BYTE_ButtonPlus);
605
606 if(ident[id].subtype == FIELD_UDIGIT)
607 {
608 if((newContent >= '0') && (newContent <= '9'))
609 ident[id].newText[ident[id].begin[block] + subBlockPosition] = newContent;
610
611 mark_new_digit_of_actual_id_block_and_subBlock();
612 }
613 else if(ident[id].subtype == FIELD_3DIGIT)
614 {
615 if((newContent >= '0') && (newContent <= '0'+200))
616 {
617 split_Content_to_Digit_helper( newContent, &digit100, &digit10, &digit1);
618 ident[id].newText[ident[id].begin[block] + 0] = '0' + digit100;
619 ident[id].newText[ident[id].begin[block] + 1] = '0' + digit10;
620 ident[id].newText[ident[id].begin[block] + 2] = '0' + digit1;
621 mark_new_3digit_of_actual_id_block();
622 }
623 }
624 else // FIELD_2DIGIT
625 {
626 if((newContent >= '0') && (newContent <= '0'+99))
627 {
628 ident[id].newText[ident[id].begin[block]] = '0' + (newContent - '0')/10;
629 ident[id].newText[ident[id].begin[block] + 1] = '0' + ((newContent - '0') - (10*((newContent - '0')/10)));
630 mark_new_2digit_of_actual_id_block();
631 }
632 }
633 break;
634 case FIELD_BUTTON:
635 set_globalState(menuID);
636 break;
637 case FIELD_ON_OFF:
638 set_globalState(menuID);
639 break;
640 case FIELD_SYMBOL:
641 ident[id].input[0] += 1;
642 if(ident[id].input[0] >= ident[id].input[1])
643 ident[id].input[0] = 0;
644 ident[id].newText[0] = ident[id].orgText[ident[id].input[0]];
645 write_content_of_actual_Id();
646 set_globalState(menuID);
647 break;
648 }
649 }
650
651
652 void exitMenuEditField(void)
653 {
654 uint8_t newContent;
655
656 set_globalState(menuID);
657
658 if(event[evid].callerID != ident[id].callerID)
659 return;
660
661 newContent = get_newContent_of_actual_id_block_and_subBlock(ACTION_TIMEOUT);
662
663 /*
664 uint8_t (*onActionFunc)(uint32_t, uint8_t, uint8_t, uint8_t, uint8_t);
665 uint8_t newContent;
666
667 onActionFunc = (uint8_t (*)(uint32_t, uint8_t, uint8_t, uint8_t, uint8_t))(event[evid].pEventFunction);
668
669 newContent = onActionFunc(ident[id].callerID, 0, 0, 255, ACTION_BUTTON_BACK);
670 */
671
672 /* destroy changes of editing in newText */
673 change_CLUT_entry(CLUT_MenuEditLineSelected, CLUT_MenuLineSelected);
674 change_CLUT_entry((CLUT_MenuEditField0 + id), CLUT_MenuEditFieldRegular);
675
676 create_newText_for_actual_Id();
677 write_content_of_actual_Id();
678
679 if((newContent == EXIT_TO_MENU) || (newContent == UPDATE_AND_EXIT_TO_MENU))
680 {
681 exitMenuEdit(1);
682 return;
683 }
684
685 if((newContent == EXIT_TO_HOME) || (newContent == UPDATE_AND_EXIT_TO_HOME))
686 {
687 exitMenuEdit_to_Home();
688 return;
689 }
690
691 }
692
693 void nextMenuEditFieldDigit(void)
694 {
695 uint8_t action;
696 uint8_t newContent;
697 int8_t blockOld = 0;
698 int8_t subBlockPositionOld = 0;
699
700 if(event[evid].callerID != ident[id].callerID)
701 return;
702
703 blockOld = block;
704 subBlockPositionOld = subBlockPosition;
705
706 if(inc_subBlock_or_block_of_actual_id())
707 action = ACTION_BUTTON_ENTER;
708 else
709 action = ACTION_BUTTON_ENTER_FINAL;
710
711 newContent = get_newContent_of_actual_id_block_and_subBlock(action);
712
713 if(action == ACTION_BUTTON_ENTER_FINAL)
714 {
715 write_buttonTextline(TXT2BYTE_ButtonBack,TXT2BYTE_ButtonEnter,TXT2BYTE_ButtonNext);
716
717 change_CLUT_entry(CLUT_MenuEditLineSelected, CLUT_MenuLineSelected);
718 for(int i = 0;i<=9;i++)
719 change_CLUT_entry((CLUT_MenuEditField0 + i), CLUT_MenuEditFieldRegular);
720
721 if(((newContent == UPDATE_DIVESETTINGS) || (newContent == UPDATE_AND_EXIT_TO_HOME) || (newContent == UPDATE_AND_EXIT_TO_MENU)) && (actual_menu_content == MENU_SURFACE))
722 createDiveSettings();
723
724 if((newContent == EXIT_TO_MENU) || (newContent == UPDATE_AND_EXIT_TO_MENU))
725 {
726 exitMenuEdit(1);
727 return;
728 }
729
730 if((newContent == EXIT_TO_HOME) || (newContent == UPDATE_AND_EXIT_TO_HOME))
731 {
732 exitMenuEdit_to_Home();
733 return;
734 }
735 }
736
737 if((ident[id].maintype == FIELD_NUMBERS) && (ident[id].subtype == FIELD_3DIGIT) && (action == ACTION_BUTTON_ENTER) &&(newContent >= '0') && (newContent <= '0' + 99))
738 {
739 ident[id].newText[ident[id].begin[block] + 0] = '0' + (newContent - '0')/100;
740 ident[id].newText[ident[id].begin[block] + 1] = '0' + (newContent - '0')/10;
741 ident[id].newText[ident[id].begin[block] + 2] = '0' + ((newContent - '0') - (10*((newContent - '0')/10)));
742 }
743 else
744 if((ident[id].maintype == FIELD_NUMBERS) && (ident[id].subtype == FIELD_2DIGIT) && (action == ACTION_BUTTON_ENTER) &&(newContent >= '0') && (newContent <= '0' + 99))
745 {
746 ident[id].newText[ident[id].begin[block] + 0] = '0' + (newContent - '0')/10;
747 ident[id].newText[ident[id].begin[block] + 1] = '0' + ((newContent - '0') - (10*((newContent - '0')/10)));
748 }
749 else
750 if((ident[id].maintype == FIELD_NUMBERS) && (action == ACTION_BUTTON_ENTER) && (newContent >= '0') && (newContent <= '9'))
751 ident[id].newText[ident[id].begin[block] + subBlockPosition] = newContent;
752
753 if(action == ACTION_BUTTON_ENTER)
754 {
755 if((ident[id].maintype == FIELD_NUMBERS) && (ident[id].subtype == FIELD_3DIGIT))
756 {
757 mark_new_3digit_of_actual_id_block();
758 mark_digit_of_actual_id_with_this_block_and_subBlock(blockOld,0);
759 mark_digit_of_actual_id_with_this_block_and_subBlock(blockOld,1);
760 mark_digit_of_actual_id_with_this_block_and_subBlock(blockOld,2);
761 }
762 else
763 if((ident[id].maintype == FIELD_NUMBERS) && (ident[id].subtype == FIELD_2DIGIT))
764 {
765 mark_new_2digit_of_actual_id_block();
766 mark_digit_of_actual_id_with_this_block_and_subBlock(blockOld,0);
767 mark_digit_of_actual_id_with_this_block_and_subBlock(blockOld,1);
768 }
769 else
770 {
771 mark_new_digit_of_actual_id_block_and_subBlock();
772 mark_digit_of_actual_id_with_this_block_and_subBlock(blockOld,subBlockPositionOld);
773 }
774 }
775 else /* action == ACTION_BUTTON_ENTER_FINAL */
776 set_globalState(menuID);
777 }
778
779 uint8_t split_Content_to_Digit_helper(uint8_t inContentAscii, uint8_t *outDigit100, uint8_t *outDigit10, uint8_t *outDigit1)
780 {
781 uint8_t newContent, tempDigit, CopyContent;
782
783 newContent = inContentAscii - '0';
784 CopyContent = newContent;
785
786 tempDigit = newContent / 100;
787 newContent -= tempDigit * 100;
788 if(outDigit100)
789 *outDigit100 = tempDigit;
790
791 tempDigit = newContent / 10;
792 newContent -= tempDigit * 10;
793 if(outDigit10)
794 *outDigit10 = tempDigit;
795
796 tempDigit = newContent;
797 if(outDigit1)
798 *outDigit1 = tempDigit;
799
800 return CopyContent;
801 }
802
803 void upMenuEditFieldDigit(void)
804 {
805 uint8_t newContent;
806 uint8_t digit100;
807 uint8_t digit10;
808 uint8_t digit1;
809
810 if(event[evid].callerID != ident[id].callerID)
811 return;
812
813 newContent = get_newContent_of_actual_id_block_and_subBlock(ACTION_BUTTON_NEXT);
814
815 if((ident[id].maintype == FIELD_NUMBERS) && (ident[id].subtype == FIELD_3DIGIT) &&(newContent >= '0') && (newContent <= '0' + 200))
816 {
817 split_Content_to_Digit_helper( newContent, &digit100, &digit10, &digit1);
818 ident[id].newText[ident[id].begin[block] + 0] = '0' + digit100;
819 ident[id].newText[ident[id].begin[block] + 1] = '0' + digit10;
820 ident[id].newText[ident[id].begin[block] + 2] = '0' + digit1;
821 mark_new_3digit_of_actual_id_block();
822 return;
823 }
824
825 if((ident[id].maintype == FIELD_NUMBERS) && (ident[id].subtype == FIELD_2DIGIT) &&(newContent >= '0') && (newContent <= '0' + 99))
826 {
827 ident[id].newText[ident[id].begin[block] + 0] = '0' + (newContent - '0')/10;
828 ident[id].newText[ident[id].begin[block] + 1] = '0' + ((newContent - '0') - (10*((newContent - '0')/10)));
829 mark_new_2digit_of_actual_id_block();
830 return;
831 }
832
833 if((ident[id].maintype == FIELD_NUMBERS) && (newContent >= '0') && (newContent <= '9'))
834 ident[id].newText[ident[id].begin[block] + subBlockPosition] = newContent;
835
836 mark_new_digit_of_actual_id_block_and_subBlock();
837 }
838
839
840 void downMenuEditFieldDigit(void)
841 {
842 uint8_t newContent;
843 uint8_t digit100;
844 uint8_t digit10;
845 uint8_t digit1;
846
847 if(event[evid].callerID != ident[id].callerID)
848 return;
849
850 newContent = get_newContent_of_actual_id_block_and_subBlock(ACTION_BUTTON_BACK);
851
852 if((ident[id].maintype == FIELD_NUMBERS) && (ident[id].subtype == FIELD_3DIGIT) &&(newContent >= '0') && (newContent <= '0' + 200))
853 {
854 split_Content_to_Digit_helper( newContent, &digit100, &digit10, &digit1);
855 ident[id].newText[ident[id].begin[block] + 0] = '0' + digit100;
856 ident[id].newText[ident[id].begin[block] + 1] = '0' + digit10;
857 ident[id].newText[ident[id].begin[block] + 2] = '0' + digit1;
858 mark_new_3digit_of_actual_id_block();
859 return;
860 }
861
862 if((ident[id].maintype == FIELD_NUMBERS) && (ident[id].subtype == FIELD_2DIGIT) &&(newContent >= '0') && (newContent <= '0' + 99))
863 {
864 ident[id].newText[ident[id].begin[block] + 0] = '0' + (newContent - '0')/10;
865 ident[id].newText[ident[id].begin[block] + 1] = '0' + ((newContent - '0') - (10*((newContent - '0')/10)));
866 mark_new_2digit_of_actual_id_block();
867 return;
868 }
869
870 if((ident[id].maintype == FIELD_NUMBERS) && (newContent >= '0') && (newContent <= '9'))
871 ident[id].newText[ident[id].begin[block] + subBlockPosition] = newContent;
872
873 mark_new_digit_of_actual_id_block_and_subBlock();
874 }
875
876
877 void evaluateNewString(uint32_t editID, uint32_t *pNewValue1, uint32_t *pNewValue2, uint32_t *pNewValue3, uint32_t *pNewValue4)
878 {
879 if(editID != ident[id].callerID)
880 return;
881
882 uint8_t i, digitCount, digit;
883 uint32_t sum[4], multiplier;
884
885 for(i=0;i<4;i++)
886 sum[i] = 0;
887
888 i = 0;
889 while( ident[id].size[i] && (i < 4))
890 {
891 multiplier = 1;
892 for(digitCount = 1; digitCount < ident[id].size[i]; digitCount++)
893 multiplier *= 10;
894
895 for(digitCount = 0; digitCount < ident[id].size[i]; digitCount++)
896 {
897 digit = ident[id].newText[ident[id].begin[i] + digitCount];
898
899 if(digit > '0')
900 digit -= '0';
901 else
902 digit = 0;
903
904 if(digit > 9)
905 digit = 9;
906
907 sum[i] += digit * multiplier;
908
909 if(multiplier >= 10)
910 multiplier /= 10;
911 else
912 multiplier = 0;
913 }
914 i++;
915 }
916
917 *pNewValue1 = sum[0];
918 *pNewValue2 = sum[1];
919 *pNewValue3 = sum[2];
920 *pNewValue4 = sum[3];
921 }
922
923
924 uint8_t get_id_of(uint32_t editID)
925 {
926 uint8_t temp_id;
927
928 if(editID == ident[id].callerID)
929 return id;
930 else
931 {
932 temp_id = 0;
933 while((temp_id < 9) && (editID != ident[temp_id].callerID))
934 temp_id++;
935 if(editID != ident[temp_id].callerID)
936 temp_id = 255;
937 return temp_id;
938 }
939 }
940
941
942 void tMenuEdit_newButtonText(uint32_t editID, char *text)
943 {
944 uint8_t backup_id, temp_id;
945
946 temp_id = get_id_of(editID);
947 if(temp_id == 255)
948 return;
949
950 backup_id = id;
951 id = temp_id;
952
953 strncpy(ident[id].newText, text, 32);
954 ident[id].newText[31] = 0;
955
956 clean_content_of_actual_Id();
957 write_content_of_actual_Id();
958
959 id = backup_id;
960 }
961
962
963 void tMenuEdit_set_on_off(uint32_t editID, uint32_t int1)
964 {
965 uint8_t backup_id, temp_id;
966
967 temp_id = get_id_of(editID);
968 if(temp_id == 255)
969 return;
970
971 backup_id = id;
972 id = temp_id;
973
974 ident[id].input[0] = int1;
975
976 if(int1)
977 ident[id].newText[0] = '\005';
978 else
979 ident[id].newText[0] = '\006';
980
981 clean_content_of_actual_Id();
982 write_content_of_actual_Id();
983
984 id = backup_id;
985 }
986
987
988 void tMenuEdit_select(uint32_t editID, uint32_t int1, uint32_t int2, uint32_t int3, uint32_t int4)
989 {
990 if(int1 > 4)
991 return;
992
993 uint8_t backup_id, temp_id;
994
995 temp_id = get_id_of(editID);
996 if(temp_id == 255)
997 return;
998
999 backup_id = id;
1000 id = temp_id;
1001
1002 ident[id].input[0] = int1;
1003 ident[id].input[1] = int1;
1004 ident[id].input[2] = int1;
1005 ident[id].input[3] = int1;
1006
1007 create_newText_for_actual_Id();
1008 clean_content_of_actual_Id();
1009 write_content_of_actual_Id();
1010
1011 id = backup_id;
1012 }
1013
1014
1015 void tMenuEdit_newInput(uint32_t editID, uint32_t int1, uint32_t int2, uint32_t int3, uint32_t int4)
1016 {
1017 uint8_t backup_id, temp_id;
1018
1019 temp_id = get_id_of(editID);
1020 if(temp_id == 255)
1021 return;
1022
1023 backup_id = id;
1024 id = temp_id;
1025
1026 if(editID != ident[id].callerID)
1027 {
1028 temp_id = 0;
1029 while((temp_id < 9) && (editID != ident[temp_id].callerID))
1030 temp_id++;
1031 if(editID != ident[temp_id].callerID)
1032 return;
1033 id = temp_id;
1034 }
1035 ident[id].input[0] = int1;
1036 ident[id].input[1] = int2;
1037 ident[id].input[2] = int3;
1038 ident[id].input[3] = int4;
1039
1040 create_newText_for_actual_Id();
1041 if(id <= idLast)
1042 change_CLUT_entry((CLUT_MenuEditField0 + id), CLUT_MenuEditFieldRegular);
1043 write_content_of_actual_Id();
1044
1045 id = backup_id;
1046 }
1047
1048
1049 void resetEnterPressedToStateBeforeButtonAction(void)
1050 {
1051 EnterPressed = EnterPressedBeforeButtonAction;
1052 }
1053
1054
1055 void sendActionToMenuEdit(uint8_t sendAction)
1056 {
1057 if(get_globalState() == menuID)
1058 {
1059 switch(sendAction)
1060 {
1061 case ACTION_BUTTON_ENTER:
1062 EnterPressedBeforeButtonAction = EnterPressed;
1063 EnterPressed = 1;
1064 enterMenuEditField();
1065 break;
1066 case ACTION_BUTTON_NEXT:
1067 nextMenuEditField();
1068 // previousMenuEditField();
1069 break;
1070 case ACTION_BUTTON_BACK:
1071 exitMenuEditBackMenuOption();
1072 break;
1073 case ACTION_TIMEOUT:
1074 case ACTION_MODE_CHANGE:
1075 exitMenuEdit(1);
1076 default:
1077 break;
1078 case ACTION_IDLE_TICK:
1079 case ACTION_IDLE_SECOND:
1080 break;
1081 }
1082 }
1083 else
1084 if(get_globalState() == event[evid].callerID)
1085 {
1086 switch(sendAction)
1087 {
1088 case ACTION_BUTTON_ENTER:
1089 nextMenuEditFieldDigit();
1090 break;
1091 case ACTION_BUTTON_NEXT:
1092 upMenuEditFieldDigit();
1093 break;
1094 case ACTION_BUTTON_BACK:
1095 downMenuEditFieldDigit();
1096 break;
1097 case ACTION_TIMEOUT:
1098 case ACTION_MODE_CHANGE:
1099 exitMenuEditField();
1100 default:
1101 break;
1102 case ACTION_IDLE_TICK:
1103 case ACTION_IDLE_SECOND:
1104 break;
1105 }
1106 }
1107 else
1108 {
1109 switch(sendAction)
1110 {
1111 case ACTION_BUTTON_ENTER:
1112 break;
1113 case ACTION_BUTTON_NEXT:
1114 break;
1115 case ACTION_BUTTON_BACK:
1116 break;
1117 case ACTION_TIMEOUT:
1118 case ACTION_MODE_CHANGE:
1119 exitMenuEdit(1);
1120 default:
1121 break;
1122 case ACTION_IDLE_TICK:
1123 case ACTION_IDLE_SECOND:
1124 break;
1125 }
1126 }
1127 }
1128
1129
1130 void create_newText_for_actual_Id_and_field_select(void)
1131 {
1132 uint8_t i;
1133
1134 i = 0;
1135 while( ident[id].size[i] && (i < 4))
1136 {
1137 if(ident[id].input[i])
1138 ident[id].newText[ident[id].begin[i]] = '\005';
1139 else
1140 ident[id].newText[ident[id].begin[i]] = '\006';
1141 i++;
1142 }
1143 }
1144
1145
1146 void create_newText_for_actual_Id(void)
1147 {
1148 if( ident[id].maintype == FIELD_SELECT)
1149 {
1150 create_newText_for_actual_Id_and_field_select();
1151 return;
1152 }
1153
1154 uint8_t i, digitCount;
1155 uint32_t remainder, digit, divider;
1156
1157 i = 0;
1158 while( ident[id].size[i] && (i < 4))
1159 {
1160 remainder = ident[id].input[i];
1161 divider = 1;
1162
1163 for(digitCount = 1; digitCount < ident[id].size[i]; digitCount++)
1164 divider *= 10;
1165
1166 for(digitCount = 0; digitCount < ident[id].size[i]; digitCount++)
1167 {
1168 digit = remainder / divider;
1169 remainder -= digit * divider;
1170 divider /= 10;
1171 if(digit < 10)
1172 ident[id].newText[ident[id].begin[i] + digitCount] = digit + '0';
1173 else
1174 ident[id].newText[ident[id].begin[i] + digitCount] = 'x';
1175 }
1176 i++;
1177 }
1178 }
1179
1180
1181 void write_content_without_Id(void)
1182 {
1183 write_content( ident[id].coord[0], ident[id].coord[1], ident[id].coord[2], ident[id].fontUsed, ident[id].newText, CLUT_MenuEditFieldRegular);
1184 }
1185
1186
1187 void write_content_of_actual_Id(void)
1188 {
1189 write_content( ident[id].coord[0], ident[id].coord[1], ident[id].coord[2], ident[id].fontUsed, ident[id].newText, (CLUT_MenuEditField0 + id));
1190 }
1191
1192
1193 void clean_content_of_actual_Id(void)
1194 {
1195 clean_content( ident[id].coord[0], ident[id].coord[1], ident[id].coord[2], ident[id].fontUsed);
1196 }
1197
1198
1199 void write_field_udigit_and_2digit(uint8_t subtype, uint32_t editID, uint16_t XleftGimpStyle, uint16_t XrightGimpStyle, uint16_t YtopGimpStyle, const tFont *Font, const char *text, uint32_t int1, uint32_t int2, uint32_t int3, uint32_t int4)
1200 {
1201 if(id >= 9)
1202 return;
1203
1204 ident[id].maintype = FIELD_NUMBERS;
1205 ident[id].subtype = subtype;
1206
1207 ident[id].coord[0] = XleftGimpStyle;
1208 ident[id].coord[1] = XrightGimpStyle;
1209 ident[id].coord[2] = YtopGimpStyle;
1210 ident[id].fontUsed = (tFont *)Font;
1211 ident[id].callerID = editID;
1212
1213 strncpy(ident[id].orgText, text, 32);
1214 strncpy(ident[id].newText, text, 32);
1215 ident[id].orgText[31] = 0;
1216 ident[id].newText[31] = 0;
1217
1218 /* uint32_t has max 10 digits */
1219
1220 int8_t beginTmp, sizeTmp;
1221 uint8_t i;
1222
1223 ident[id].input[0] = int1;
1224 ident[id].input[1] = int2;
1225 ident[id].input[2] = int3;
1226 ident[id].input[3] = int4;
1227
1228 for(i=0;i<4;i++)
1229 ident[id].size[i] = 0;
1230
1231 beginTmp = 0;
1232 for(i=0;i<4;i++)
1233 {
1234 while((ident[id].orgText[beginTmp] != '#')&& ident[id].orgText[beginTmp])
1235 beginTmp++;
1236
1237 if(ident[id].orgText[beginTmp] == '#')
1238 {
1239 sizeTmp = 1;
1240 while(ident[id].orgText[beginTmp + sizeTmp] == '#')
1241 sizeTmp++;
1242
1243 ident[id].begin[i] = beginTmp;
1244 ident[id].size[i] = sizeTmp;
1245 beginTmp = ident[id].begin[i] + ident[id].size[i];
1246 }
1247 else
1248 break;
1249 }
1250
1251 if(!tME_stop)
1252 change_CLUT_entry((CLUT_MenuEditField0 + id), CLUT_MenuEditFieldRegular);
1253 else
1254 change_CLUT_entry((CLUT_MenuEditField0 + id), CLUT_MenuEditInfo);
1255
1256 create_newText_for_actual_Id();
1257
1258 if(editID == NULL)
1259 write_content_without_Id();
1260 else
1261 {
1262 write_content_of_actual_Id();
1263 if(!tME_stop)
1264 idLast = id;
1265 id++;
1266 }
1267 }
1268
1269 void write_field_udigit(uint32_t editID, uint16_t XleftGimpStyle, uint16_t XrightGimpStyle, uint16_t YtopGimpStyle, const tFont *Font, const char *text, uint32_t int1, uint32_t int2, uint32_t int3, uint32_t int4)
1270 {
1271 write_field_udigit_and_2digit(FIELD_UDIGIT, editID,XleftGimpStyle,XrightGimpStyle,YtopGimpStyle,Font,text,int1,int2,int3,int4);
1272 }
1273
1274 void write_field_2digit(uint32_t editID, uint16_t XleftGimpStyle, uint16_t XrightGimpStyle, uint16_t YtopGimpStyle, const tFont *Font, const char *text, uint32_t int1, uint32_t int2, uint32_t int3, uint32_t int4)
1275 {
1276 write_field_udigit_and_2digit(FIELD_2DIGIT, editID,XleftGimpStyle,XrightGimpStyle,YtopGimpStyle,Font,text,int1,int2,int3,int4);
1277 }
1278
1279 void write_field_3digit(uint32_t editID, uint16_t XleftGimpStyle, uint16_t XrightGimpStyle, uint16_t YtopGimpStyle, const tFont *Font, const char *text, uint32_t int1, uint32_t int2, uint32_t int3, uint32_t int4)
1280 {
1281 write_field_udigit_and_2digit(FIELD_3DIGIT, editID,XleftGimpStyle,XrightGimpStyle,YtopGimpStyle,Font,text,int1,int2,int3,int4);
1282 }
1283
1284 /*
1285 void write_field_sdigit(uint32_t editID, uint16_t XleftGimpStyle, uint16_t XrightGimpStyle, uint16_t YtopGimpStyle, const tFont *Font, const char *text, int32_t int1, int32_t int2, int32_t int3, int32_t int4)
1286 {
1287 }
1288 */
1289
1290 void write_field_select(uint32_t editID, uint16_t XleftGimpStyle, uint16_t XrightGimpStyle, uint16_t YtopGimpStyle, const tFont *Font, const char *text, uint8_t int1, uint8_t int2, uint8_t int3, uint8_t int4)
1291 {
1292 if(id >= 9)
1293 return;
1294
1295 int8_t beginTmp;
1296
1297 ident[id].maintype = FIELD_SELECT;
1298 ident[id].subtype = FIELD_SELECT;
1299
1300 ident[id].coord[0] = XleftGimpStyle;
1301 ident[id].coord[1] = XrightGimpStyle;
1302 ident[id].coord[2] = YtopGimpStyle;
1303 ident[id].fontUsed = (tFont *)Font;
1304 ident[id].callerID = editID;
1305
1306 strncpy(ident[id].orgText, text, 32);
1307 strncpy(ident[id].newText, text, 32);
1308 ident[id].orgText[31] = 0;
1309 ident[id].newText[31] = 0;
1310
1311 ident[id].input[0] = int1;
1312 ident[id].input[1] = int2;
1313 ident[id].input[2] = int3;
1314 ident[id].input[3] = int4;
1315
1316 for(int i=0;i<4;i++)
1317 ident[id].size[i] = 0;
1318
1319 beginTmp = 0;
1320 for(int i=0;i<4;i++)
1321 {
1322 while((ident[id].orgText[beginTmp] != '#')&& ident[id].orgText[beginTmp])
1323 beginTmp++;
1324
1325 if(ident[id].orgText[beginTmp] == '#')
1326 {
1327
1328 ident[id].begin[i] = beginTmp;
1329 ident[id].size[i] = 1;
1330 beginTmp = ident[id].begin[i] + ident[id].size[i];
1331 }
1332 else
1333 break;
1334 }
1335
1336 change_CLUT_entry((CLUT_MenuEditField0 + id), CLUT_MenuEditFieldRegular);
1337
1338 create_newText_for_actual_Id();
1339
1340 if(editID == NULL)
1341 write_content_without_Id();
1342 else
1343 {
1344 write_content_of_actual_Id();
1345 if(!tME_stop)
1346 idLast = id;
1347 id++;
1348 }
1349 }
1350
1351 void write_field_button(uint32_t editID, uint16_t XleftGimpStyle, uint16_t XrightGimpStyle, uint16_t YtopGimpStyle, const tFont *Font, const char *text)
1352 {
1353 if(id >= 9)
1354 return;
1355
1356 ident[id].maintype = FIELD_BUTTON;
1357 ident[id].subtype = FIELD_BUTTON;
1358
1359 ident[id].coord[0] = XleftGimpStyle;
1360 ident[id].coord[1] = XrightGimpStyle;
1361 ident[id].coord[2] = YtopGimpStyle;
1362 ident[id].fontUsed = (tFont *)Font;
1363 ident[id].callerID = editID;
1364
1365 strncpy(ident[id].orgText, text, 32);
1366 strncpy(ident[id].newText, text, 32);
1367 ident[id].orgText[31] = 0;
1368 ident[id].newText[31] = 0;
1369
1370 change_CLUT_entry((CLUT_MenuEditField0 + id), CLUT_MenuEditButtonColor1);
1371
1372 if(editID == NULL)
1373 write_content_without_Id();
1374 else
1375 {
1376 write_content_of_actual_Id();
1377 if(!tME_stop)
1378 idLast = id;
1379 id++;
1380 }
1381 }
1382
1383
1384 void write_field_symbol(uint32_t editID, uint16_t XleftGimpStyle, uint16_t XrightGimpStyle, uint16_t YtopGimpStyle, const tFont *Font, const char *text, uint8_t int1)
1385 {
1386 if(id >= 9)
1387 return;
1388
1389 ident[id].maintype = FIELD_SYMBOL;
1390 ident[id].subtype = FIELD_SYMBOL;
1391
1392 ident[id].coord[0] = XleftGimpStyle;
1393 ident[id].coord[1] = XrightGimpStyle;
1394 ident[id].coord[2] = YtopGimpStyle;
1395 ident[id].fontUsed = (tFont *)Font;
1396 ident[id].callerID = editID;
1397
1398 strncpy(ident[id].orgText, text, 32);
1399 strncpy(ident[id].newText, text, 32);
1400 ident[id].orgText[31] = 0;
1401
1402 ident[id].newText[0] = text[0];
1403 ident[id].newText[1] = 0;
1404
1405 ident[id].input[0] = int1;
1406 ident[id].input[1] = strlen(ident[id].orgText);
1407
1408 change_CLUT_entry((CLUT_MenuEditField0 + id), CLUT_MenuEditButtonColor1);
1409
1410 if(editID == NULL)
1411 write_content_without_Id();
1412 else
1413 {
1414 write_content_of_actual_Id();
1415 if(!tME_stop)
1416 idLast = id;
1417 id++;
1418 }
1419 }
1420
1421
1422 /* was build for field_on_off
1423 * to be tested for other purposes first
1424 */
1425 void tMenuEdit_refresh_field(uint32_t editID)
1426 {
1427 uint8_t temp_id;
1428
1429 temp_id = get_id_of(editID);
1430 if(temp_id == 255)
1431 return;
1432
1433 clean_content( ident[temp_id].coord[0], ident[temp_id].coord[1], ident[temp_id].coord[2], ident[temp_id].fontUsed);
1434 write_content( ident[temp_id].coord[0], ident[temp_id].coord[1], ident[temp_id].coord[2], ident[temp_id].fontUsed, ident[temp_id].newText, (CLUT_MenuEditField0 + temp_id));
1435 }
1436
1437
1438 void write_field_on_off(uint32_t editID, uint16_t XleftGimpStyle, uint16_t XrightGimpStyle, uint16_t YtopGimpStyle, const tFont *Font, const char *text, uint8_t int1)
1439 {
1440 if(id >= 9)
1441 return;
1442
1443 ident[id].maintype = FIELD_ON_OFF;
1444 ident[id].subtype = FIELD_ON_OFF;
1445
1446 ident[id].coord[0] = XleftGimpStyle;
1447 ident[id].coord[1] = XrightGimpStyle;
1448 ident[id].coord[2] = YtopGimpStyle;
1449 ident[id].fontUsed = (tFont *)Font;
1450 ident[id].callerID = editID;
1451
1452 if(int1)
1453 ident[id].orgText[0] = '\005';
1454 else
1455 ident[id].orgText[0] = '\006';
1456
1457 ident[id].orgText[1] = ' ';
1458
1459 strncpy(&ident[id].orgText[2], text, 30);
1460 strncpy(ident[id].newText, ident[id].orgText, 32);
1461 ident[id].orgText[31] = 0;
1462 ident[id].newText[31] = 0;
1463
1464 if(!tME_stop)
1465 change_CLUT_entry((CLUT_MenuEditField0 + id), CLUT_MenuEditFieldRegular);
1466 else
1467 change_CLUT_entry((CLUT_MenuEditField0 + id), CLUT_MenuEditInfo);
1468
1469 if(editID == NULL)
1470 write_content_without_Id();
1471 else
1472 {
1473 write_content_of_actual_Id();
1474 if(!tME_stop)
1475 idLast = id;
1476 id++;
1477 }
1478 }
1479
1480
1481 void write_field_fpoint(uint32_t editID, uint16_t XleftGimpStyle, uint16_t XrightGimpStyle, uint16_t YtopGimpStyle, const tFont *Font, const char *text, float input)
1482 {
1483 if(id >= 9)
1484 return;
1485
1486 ident[id].maintype = FIELD_NUMBERS;
1487 ident[id].subtype = FIELD_FLOAT;
1488
1489 ident[id].coord[0] = XleftGimpStyle;
1490 ident[id].coord[1] = XrightGimpStyle;
1491 ident[id].coord[2] = YtopGimpStyle;
1492 ident[id].fontUsed = (tFont *)Font;
1493 ident[id].callerID = editID;
1494
1495 strncpy(ident[id].orgText, text, 32);
1496 strncpy(ident[id].newText, text, 32);
1497 ident[id].orgText[31] = 0;
1498 ident[id].newText[31] = 0;
1499
1500 change_CLUT_entry((CLUT_MenuEditField0 + id), CLUT_MenuEditFieldRegular);
1501
1502 if(editID == NULL)
1503 write_content_without_Id();
1504 else
1505 {
1506 write_content_of_actual_Id();
1507 if(!tME_stop)
1508 idLast = id;
1509 id++;
1510 }
1511 }
1512
1513
1514 void setBackMenu(uint32_t inputFunctionCall, uint8_t functionCallParameter, uint8_t gotoMenuEditField)
1515 {
1516 backmenu.pEventFunction = inputFunctionCall;
1517 backmenu.functionParameter = functionCallParameter;
1518 backmenu.line = gotoMenuEditField;
1519 }
1520
1521
1522 void setEvent(uint32_t inputEventID, uint32_t inputFunctionCall)
1523 {
1524 if(evidLast >= 9)
1525 return;
1526
1527 /* set cursor to first field */
1528 if(evidLast < 0)
1529 {
1530 startMenuEditFieldSelect();
1531 }
1532
1533 event[evid].callerID = inputEventID;
1534 event[evid].pEventFunction = inputFunctionCall;
1535
1536 evidLast = evid;
1537 evid++;
1538 }
1539
1540 void startEdit(void)
1541 {
1542 EnterPressed = 1;
1543 helperGotoMenuEditField(0);
1544 enterMenuEditField();
1545 }
1546
1547 void exitEditWithUpdate(void)
1548 {
1549 createDiveSettings();
1550 EnterPressed = 1;
1551 exitMenuEdit(1);
1552 }
1553
1554 /*
1555 void set_cursor(uint8_t forThisIdentID)
1556 {
1557 int16_t x0, x1, y0, y1;
1558
1559 uint32_t xtra_left_right = 10;
1560 uint32_t xtra_top_bottom = 10;
1561
1562 // y geht von 0 bis 799
1563 // x geht von 0 bis 479
1564
1565 x0 = (int16_t)ident[forThisIdentID].coord[0];
1566 x1 = (int16_t)ident[forThisIdentID].coord[1];
1567 y0 = (int16_t)ident[forThisIdentID].coord[2];
1568 y1 = y0 + (int16_t)ident[forThisIdentID].fontUsed->height;
1569
1570 if(((int16_t)ident[forThisIdentID].fontUsed->height) > 70)
1571 {
1572 xtra_left_right = 10;
1573 xtra_top_bottom = 10;
1574 }
1575 else
1576 {
1577 xtra_left_right = 10;
1578 xtra_top_bottom = 0;
1579 }
1580
1581 x0 -= xtra_left_right;
1582 x1 += xtra_left_right;
1583 y0 -= xtra_top_bottom;
1584 y1 += xtra_top_bottom;
1585
1586 GFX_SetWindowLayer0(tMEcursor.FBStartAdress, x0, x1, y0, y1);
1587 }
1588 */
1589
1590 void set_cursorNew(uint8_t forThisIdentID)
1591 {
1592 int16_t y0;
1593 uint8_t lineMinusOne;
1594
1595 y0 = (int16_t)ident[forThisIdentID].coord[2];
1596
1597 y0 -= ME_Y_LINE1;
1598 y0 /= ME_Y_LINE_STEP;
1599 if((y0 >= 0) && (y0 <=5))
1600 lineMinusOne = y0;
1601 else
1602 lineMinusOne = 0;
1603 GFX_SetFrameBottom((tMEcursorNew.FBStartAdress) + 65*2*(lineMinusOne), 0, 25, 800, 390);
1604 }
1605
1606
1607 void write_topline( char *text)
1608 {
1609 GFX_DrawCfgWindow hgfx;
1610 const tFont *Font = &FontT48;
1611
1612 hgfx.Image = &tMEscreen;
1613 hgfx.WindowNumberOfTextLines = 1;
1614 hgfx.WindowLineSpacing = 0;
1615 hgfx.WindowTab = 0;
1616 hgfx.WindowX0 = 20;
1617 hgfx.WindowX1 = 779;
1618 hgfx.WindowY1 = 479;
1619 hgfx.WindowY0 = hgfx.WindowY1 - Font->height;
1620
1621 GFX_write_label(Font, &hgfx, text, menuColor);
1622 }
1623
1624
1625 void write_buttonTextline( uint8_t left2ByteCode, char middle2ByteCode, char right2ByteCode)
1626 {
1627 GFX_clean_area(&tMEscreen, 0, 800, 480-24,480);
1628
1629 char localtext[32];
1630
1631 if(left2ByteCode)
1632 {
1633 localtext[0] = TXT_2BYTE;
1634 localtext[1] = left2ByteCode;
1635 localtext[2] = 0;
1636 write_content_simple(&tMEscreen, 0, 800, 480-24, &FontT24,localtext,CLUT_ButtonSurfaceScreen);
1637 }
1638
1639 if(middle2ByteCode)
1640 {
1641 localtext[0] = '\001';
1642 localtext[1] = TXT_2BYTE;
1643 localtext[2] = middle2ByteCode;
1644 localtext[3] = 0;
1645 write_content_simple(&tMEscreen, 0, 800, 480-24, &FontT24,localtext,CLUT_ButtonSurfaceScreen);
1646 }
1647
1648 if(right2ByteCode)
1649 {
1650 localtext[0] = '\002';
1651 localtext[1] = TXT_2BYTE;
1652 localtext[2] = right2ByteCode;
1653 localtext[3] = 0;
1654 write_content_simple(&tMEscreen, 0, 800, 480-24, &FontT24,localtext,CLUT_ButtonSurfaceScreen);
1655 }
1656 }
1657
1658
1659
1660 void write_label_var(uint16_t XleftGimpStyle, uint16_t XrightGimpStyle, uint16_t YtopGimpStyle, const tFont *Font, const char *text)
1661 {
1662 GFX_DrawCfgWindow hgfx;
1663
1664 if(XrightGimpStyle > 799)
1665 XrightGimpStyle = 799;
1666 if(XleftGimpStyle >= XrightGimpStyle)
1667 XleftGimpStyle = 0;
1668 if(YtopGimpStyle > 479)
1669 YtopGimpStyle = 479;
1670 hgfx.Image = &tMEscreen;
1671 hgfx.WindowNumberOfTextLines = 1;
1672 hgfx.WindowLineSpacing = 0;
1673 hgfx.WindowTab = 0;
1674 hgfx.WindowX0 = XleftGimpStyle;
1675 hgfx.WindowX1 = XrightGimpStyle;
1676 hgfx.WindowY1 = 479 - YtopGimpStyle;
1677 if(hgfx.WindowY1 < Font->height)
1678 hgfx.WindowY0 = 0;
1679 else
1680 hgfx.WindowY0 = hgfx.WindowY1 - Font->height;
1681
1682 GFX_write_label(Font, &hgfx, text, 0);/*menuColor);*/
1683 }
1684
1685
1686 void write_content(uint16_t XleftGimpStyle, uint16_t XrightGimpStyle, uint16_t YtopGimpStyle, const tFont *Font, const char *text, uint8_t color)
1687 {
1688 GFX_DrawCfgWindow hgfx;
1689
1690 if(XrightGimpStyle > 799)
1691 XrightGimpStyle = 799;
1692 if(XleftGimpStyle >= XrightGimpStyle)
1693 XleftGimpStyle = 0;
1694 if(YtopGimpStyle > 479)
1695 YtopGimpStyle = 479;
1696 hgfx.Image = &tMEscreen;
1697 hgfx.WindowNumberOfTextLines = 1;
1698 hgfx.WindowLineSpacing = 0;
1699 hgfx.WindowTab = 0;
1700 hgfx.WindowX0 = XleftGimpStyle;
1701 hgfx.WindowX1 = XrightGimpStyle;
1702 hgfx.WindowY1 = 479 - YtopGimpStyle;
1703 if(hgfx.WindowY1 < Font->height)
1704 hgfx.WindowY0 = 0;
1705 else
1706 hgfx.WindowY0 = hgfx.WindowY1 - Font->height;
1707
1708 GFX_write_label(Font, &hgfx, text, color);
1709 }
1710
1711
1712 void write_label_fix(uint16_t XleftGimpStyle, uint16_t XrightGimpStyle, uint16_t YtopGimpStyle, const tFont *Font, const char textId)
1713 {
1714 char text[2];
1715
1716 text[0] = textId;
1717 text[1] = 0;
1718
1719 write_label_var(XleftGimpStyle, XrightGimpStyle, YtopGimpStyle, Font, text);
1720 }
1721
1722
1723 void clean_content(uint16_t XleftGimpStyle, uint16_t XrightGimpStyle, uint16_t YtopGimpStyle, const tFont *Font)
1724 {
1725 GFX_DrawCfgWindow hgfx;
1726
1727 if(XrightGimpStyle > 799)
1728 XrightGimpStyle = 799;
1729 if(XleftGimpStyle >= XrightGimpStyle)
1730 XleftGimpStyle = 0;
1731 if(YtopGimpStyle > 479)
1732 YtopGimpStyle = 479;
1733 hgfx.Image = &tMEscreen;
1734 hgfx.WindowX0 = XleftGimpStyle;
1735 hgfx.WindowX1 = XrightGimpStyle;
1736 hgfx.WindowY1 = 479 - YtopGimpStyle;
1737 if(hgfx.WindowY1 < Font->height)
1738 hgfx.WindowY0 = 0;
1739 else
1740 hgfx.WindowY0 = hgfx.WindowY1 - Font->height;
1741
1742 GFX_clear_window_immediately(&hgfx);
1743 }
1744
1745
1746 /* Private functions ---------------------------------------------------------*/
1747
1748 void draw_tMEdesign(void)
1749 {
1750 GFX_draw_header(&tMEscreen,menuColor);
1751 }
1752
1753 void draw_tMEdesignSubUnselected(uint32_t *ppDestination)
1754 {
1755 union al88_u
1756 {
1757 uint8_t al8[2];
1758 uint16_t al88;
1759 };
1760
1761 union al88_u color_seperator;
1762 union al88_u color_unselected;
1763 int i;
1764
1765 color_seperator.al8[0] = CLUT_MenuLineUnselectedSeperator;
1766 color_unselected.al8[0] = CLUT_MenuLineUnselected;
1767
1768 color_seperator.al8[1] = 0xFF;
1769 color_unselected.al8[1] = 0xFF;
1770
1771 *(__IO uint16_t*)*ppDestination = color_seperator.al88;
1772 *ppDestination += 2;
1773 *(__IO uint16_t*)*ppDestination = color_seperator.al88;
1774 *ppDestination += 2;
1775
1776 for(i = 61; i > 0; i--)
1777 {
1778 *(__IO uint16_t*)*ppDestination = color_unselected.al88;
1779 *ppDestination += 2;
1780 }
1781
1782 *(__IO uint16_t*)*ppDestination = color_seperator.al88;
1783 *ppDestination += 2;
1784 *(__IO uint16_t*)*ppDestination = color_seperator.al88;
1785 *ppDestination += 2;
1786 }
1787
1788
1789 void draw_tMEdesignSubSelected(uint32_t *ppDestination)
1790 {
1791 union al88_u
1792 {
1793 uint8_t al8[2];
1794 uint16_t al88;
1795 };
1796
1797 union al88_u color_selected;
1798 union al88_u color_seperator;
1799 int i;
1800
1801 color_selected.al8[0] = CLUT_MenuEditLineSelected;
1802 color_selected.al8[1] = 0xFF;
1803
1804 color_seperator.al8[0] = CLUT_MenuLineSelectedSeperator;
1805 color_seperator.al8[1] = 0xFF;
1806
1807 *(__IO uint16_t*)*ppDestination = color_seperator.al88;
1808 *ppDestination += 2;
1809 *(__IO uint16_t*)*ppDestination = color_seperator.al88;
1810 *ppDestination += 2;
1811
1812 for(i = 61; i > 0; i--)
1813 {
1814 *(__IO uint16_t*)*ppDestination = color_selected.al88;
1815 *ppDestination += 2;
1816 }
1817
1818 *(__IO uint16_t*)*ppDestination = color_seperator.al88;
1819 *ppDestination += 2;
1820 *(__IO uint16_t*)*ppDestination = color_seperator.al88;
1821 *ppDestination += 2;
1822 }
1823
1824
1825 void draw_tMEdesignSubSelectedBorder(uint32_t *ppDestination)
1826 {
1827 union al88_u
1828 {
1829 uint8_t al8[2];
1830 uint16_t al88;
1831 };
1832
1833 union al88_u color_selected_sides;
1834
1835 int i;
1836
1837 color_selected_sides.al8[0] = CLUT_MenuLineSelectedSides;
1838 color_selected_sides.al8[1] = 0xFF;
1839
1840 for(i = 65; i > 0; i--)
1841 {
1842 *(__IO uint16_t*)*ppDestination = color_selected_sides.al88;
1843 *ppDestination += 2;
1844 }
1845 }
1846
1847
1848 void draw_tMEcursorNewDesign(void)
1849 {
1850 int i,j;
1851 uint32_t pDestination;
1852
1853 pDestination = tMEcursorNew.FBStartAdress;
1854
1855 for(j = 801; j > 0; j--)
1856 {
1857 for(i = 5; i > 0; i--)
1858 {
1859 draw_tMEdesignSubUnselected(&pDestination);
1860 }
1861 if((j > 787) || (j < 17))
1862 draw_tMEdesignSubSelectedBorder(&pDestination);
1863 else
1864 draw_tMEdesignSubSelected(&pDestination);
1865 }
1866 }