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

include in ostc4 repository
author heinrichsweikamp
date Sat, 28 Apr 2018 11:52:34 +0200
parents
children e1d66bc78f9a
comparison
equal deleted inserted replaced
37:ccc45c0e1ea2 38:5f11787b4f42
1 ///////////////////////////////////////////////////////////////////////////////
2 /// -*- coding: UTF-8 -*-
3 ///
4 /// \file Discovery/Src/tMenuEditGasOC.c
5 /// \brief Main Template file for editing Open Circuit Gas Settings
6 /// \author heinrichs weikamp gmbh
7 /// \date 09-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 "tMenuEditGasOC.h"
31
32 #include "check_warning.h"
33 #include "gfx_fonts.h"
34 #include "tMenuEdit.h"
35 #include "unit.h"
36
37 /* Private types -------------------------------------------------------------*/
38 typedef struct
39 {
40 uint8_t gasID;
41 SGasLine * pGasLine;
42 uint8_t mod;
43 uint8_t ccr;
44 uint8_t setpoint;
45 } SEditGasPage;
46
47 #define MAX_SENDER_AT_ONCE 5
48
49 /* Private variables ---------------------------------------------------------*/
50 SEditGasPage editGasPage;
51
52 uint16_t wirelessSender[MAX_SENDER_AT_ONCE];
53
54 /* Private function prototypes -----------------------------------------------*/
55 void create_text_with_u8(char *text, const char *text1, uint8_t inputU8, const char *text2);
56
57 void openEdit_Gas(uint8_t line, uint8_t ccr);
58 void openEdit_GasType(void);
59 void openEdit_Wireless(void);
60
61 void openEdit_DiveGasSelect(uint8_t line, uint8_t ccr);
62 void openEdit_SpecialDiveGasMenu(uint8_t ccr);
63 void openEdit_DiveGasSelect_Subroutine(uint8_t line, uint8_t ccr);
64
65 void tMEGas_check_switch_to_bailout(void);
66
67 /* Announced function prototypes -----------------------------------------------*/
68 uint8_t OnAction_Mix (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action);
69 uint8_t OnAction_GasType (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action);
70 uint8_t OnAction_ChangeDepth (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action);
71 uint8_t OnAction_SetToMOD (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action);
72 uint8_t OnAction_BottleSize (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action);
73 uint8_t OnAction_Wireless (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action);
74
75 uint8_t OnAction_First (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action);
76 uint8_t OnAction_Deco (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action);
77 uint8_t OnAction_Travel (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action);
78 uint8_t OnAction_Inactive (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action);
79
80 uint8_t OnAction_WirelessID (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action);
81 uint8_t OnAction_NoWireless (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action);
82
83 uint8_t OnAction_DM_Active (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action);
84 uint8_t OnAction_DM_Mix (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action);
85
86 /*
87 uint8_t OnAction_DefaultMix (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action);
88 uint8_t OnAction_ToggleDepth (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action);
89 uint8_t OnAction_ToggleDefault (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action);
90 uint8_t OnAction_DefaultDepth (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action);
91 */
92
93 /* Exported functions --------------------------------------------------------*/
94
95 void openEdit_GasCC(uint8_t line)
96 {
97 if(actual_menu_content == MENU_SURFACE)
98 openEdit_Gas(line , 1);
99 else
100 if(line == 6)
101 openEdit_SpecialDiveGasMenu(1);
102 else
103 openEdit_DiveGasSelect(line, 1);
104 }
105
106
107 void openEdit_GasOC(uint8_t line)
108 {
109 if(actual_menu_content == MENU_SURFACE)
110 openEdit_Gas(line, 0);
111 else
112 if(line == 6)
113 openEdit_SpecialDiveGasMenu(0);
114 else
115 openEdit_DiveGasSelect(line, 0);
116 }
117
118
119 /* dive mode */
120 void openEdit_DiveSelectBetterGas(void)
121 {
122 uint8_t gasId, ccr;
123
124 gasId = actualBetterGasId();
125 ccr = 0;
126 if(gasId>5)
127 {
128 gasId -= 5;
129 ccr = 1;
130 }
131 openEdit_DiveGasSelect_Subroutine(gasId,ccr);
132 if(ccr)
133 updateSpecificMenu(StMCG); // is this necessary? openEdit_DiveGasSelect_Subroutine has update. hw 151209
134 else
135 updateSpecificMenu(StMOG); // is this necessary? openEdit_DiveGasSelect_Subroutine has update. hw 151209
136 }
137
138
139 /* select gas in divemode */
140 void openEdit_DiveGasSelect(uint8_t line, uint8_t ccr)
141 {
142 openEdit_DiveGasSelect_Subroutine(line, ccr);
143 if(!ccr)
144 tMEGas_check_switch_to_bailout();
145 exitMenuEdit_to_Home_with_Menu_Update();
146 }
147
148
149 void openEdit_DiveGasSelect_Subroutine(uint8_t line, uint8_t ccr)
150 {
151 SDiveState * pState;
152 uint8_t setpoint;
153
154 if(actual_menu_content == MENU_DIVE_REAL)
155 {
156 pState = stateRealGetPointerWrite();
157 editGasPage.pGasLine = pState->diveSettings.gas;
158 }
159 else
160 {
161 pState = stateSimGetPointerWrite();
162 editGasPage.pGasLine = pState->diveSettings.gas;
163 }
164
165 if(ccr)
166 {
167 editGasPage.gasID = line + NUM_OFFSET_DILUENT;
168 setpoint = pState->lifeData.actualGas.setPoint_cbar;
169 }
170 else
171 {
172 editGasPage.gasID = line;
173 setpoint = 0;
174 }
175
176 for(int i=0;i<(1+ (2*NUM_GASES));i++)
177 editGasPage.pGasLine[i].note.ub.first = 0;
178
179 editGasPage.pGasLine[editGasPage.gasID].note.ub.active = 1;
180 editGasPage.pGasLine[editGasPage.gasID].note.ub.first = 1;
181 setActualGas_DM(&pState->lifeData,editGasPage.gasID,setpoint);
182 }
183
184 /* extra gas and gas on/off option */
185 void openEdit_SpecialDiveGasMenu(uint8_t ccr)
186 {
187 char text[32];
188 uint8_t oxygen, helium, gasOffset, textpointer, lineCount, ptrGas;
189 SDiveState * pState;
190
191 if(actual_menu_content == MENU_DIVE_REAL)
192 {
193 pState = stateRealGetPointerWrite();
194 editGasPage.pGasLine = pState->diveSettings.gas;
195 }
196 else
197 {
198 pState = stateSimGetPointerWrite();
199 editGasPage.pGasLine = pState->diveSettings.gas;
200 }
201 if(ccr)
202 {
203 editGasPage.setpoint = pState->lifeData.actualGas.setPoint_cbar;
204 }
205 editGasPage.ccr = ccr;
206
207 set_globalState_Menu_Line(6);
208
209 if(ccr)
210 resetMenuEdit(CLUT_MenuPageGasCC);
211 else
212 resetMenuEdit(CLUT_MenuPageGasOC);
213
214 if(ccr)
215 gasOffset = NUM_OFFSET_DILUENT;
216 else
217 gasOffset = 0;
218
219
220 text[0] = '\001';
221 text[1] = TXT_2BYTE;
222 if(ccr)
223 text[2] = TXT2BYTE_SpecialDiveGasMenuCCR;
224 else
225 text[2] = TXT2BYTE_SpecialDiveGasMenu;
226 text[3] = 0;
227 write_topline(text);
228
229 lineCount = 1;
230
231
232 for(int i=1; i<=5; i++)
233 {
234 ptrGas = i + gasOffset;
235 oxygen = stateUsed->diveSettings.gas[ptrGas].oxygen_percentage;
236 helium = stateUsed->diveSettings.gas[ptrGas].helium_percentage;
237
238 if(oxygen == 100)
239 textpointer = snprintf(text,10,"Oxy");
240 else
241 if((oxygen == 21) && (helium == 0))
242 textpointer = snprintf(text,10,"Air");
243 else
244 textpointer = snprintf(text,10,"%02i/%02i",oxygen,helium);
245
246 if(editGasPage.pGasLine[ptrGas].note.ub.first)
247 strcpy(&text[textpointer]," *");
248
249 write_field_on_off(StMOG_DM_ActiveBase+i, 30, 500, ME_Y_LINE_BASE + (lineCount * ME_Y_LINE_STEP), &FontT48, text, stateUsed->diveSettings.gas[ptrGas].note.ub.active);
250 lineCount++;
251 }
252
253 if(!ccr)
254 {
255 if(stateUsed->diveSettings.gas[0].note.ub.first)
256 {
257 oxygen = stateUsed->diveSettings.gas[0].oxygen_percentage;
258 helium = stateUsed->diveSettings.gas[0].helium_percentage;
259 write_field_udigit(StMOG_DM_ExtraMix, 30, 800, ME_Y_LINE6, &FontT48, "##/## Extra Gas *", oxygen, helium, 0, 0);
260 }
261 else
262 {
263 write_field_udigit(StMOG_DM_ExtraMix, 30, 800, ME_Y_LINE6, &FontT48, "##/## Extra Gas", 0, 0, 0, 0);
264 }
265 }
266
267 for(int i=1; i<=5; i++)
268 {
269 setEvent(StMOG_DM_ActiveBase + i,(uint32_t)OnAction_DM_Active);
270 }
271
272 if(!ccr)
273 setEvent(StMOG_DM_ExtraMix,(uint32_t)OnAction_DM_Mix);
274 }
275
276
277 uint8_t OnAction_DM_Active (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action)
278 {
279 uint8_t gasOffset, newActive;
280
281 if(editGasPage.ccr)
282 gasOffset = NUM_OFFSET_DILUENT;
283 else
284 gasOffset = 0;
285
286 editGasPage.gasID = editId + gasOffset - StMOG_DM_ActiveBase;
287
288 if(editGasPage.pGasLine[editGasPage.gasID].note.ub.first)
289 return UNSPECIFIC_RETURN;
290
291 if(editGasPage.pGasLine[editGasPage.gasID].note.ub.active)
292 newActive = 0;
293 else
294 newActive = 1;
295
296 tMenuEdit_set_on_off(editId, newActive);
297 editGasPage.pGasLine[editGasPage.gasID].note.ub.active = newActive;
298
299 return UNSPECIFIC_RETURN;
300 }
301
302 /* only for OC */
303 uint8_t OnAction_DM_Mix(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action)
304 {
305 uint8_t digitContentNew;
306 uint32_t newOxygen, newHelium;
307
308 if(action == ACTION_BUTTON_ENTER)
309 {
310 return digitContent;
311 }
312 if(action == ACTION_BUTTON_ENTER_FINAL)
313 {
314 evaluateNewString(editId, &newOxygen, &newHelium, 0, 0);
315
316 if(newOxygen < 5)
317 newOxygen = 5;
318 if(newOxygen == 99)
319 newOxygen = 100;
320 if(newHelium > 95)
321 newHelium = 95;
322 if((newOxygen + newHelium) > 100)
323 newOxygen = 100 - newHelium;
324
325 SDiveState * pDiveState = 0;
326
327 for(int i=1;i<=(2*NUM_GASES);i++)
328 editGasPage.pGasLine[i].note.ub.first = 0;
329
330 if(actual_menu_content == MENU_DIVE_REAL)
331 pDiveState = stateRealGetPointerWrite();
332 else
333 pDiveState = stateSimGetPointerWrite();
334
335 setActualGas_ExtraGas(&pDiveState->lifeData, newOxygen, newHelium, 0);
336 tMEGas_check_switch_to_bailout();
337 return EXIT_TO_HOME;
338 }
339 if(action == ACTION_BUTTON_NEXT)
340 {
341 digitContentNew = digitContent + 1;
342 if(digitContentNew > '9')
343 digitContentNew = '0';
344 return digitContentNew;
345 }
346 if(action == ACTION_BUTTON_BACK)
347 {
348 digitContentNew = digitContent - 1;
349 if(digitContentNew < '0')
350 digitContentNew = '9';
351 return digitContentNew;
352 }
353
354 return UNSPECIFIC_RETURN;
355 }
356
357
358 void tMEGas_check_switch_to_bailout(void)
359 {
360 SDiveState *pState;
361
362 if(actual_menu_content == MENU_DIVE_REAL)
363 pState = stateRealGetPointerWrite();
364 else
365 pState = stateSimGetPointerWrite();
366
367 if(pState->diveSettings.diveMode == DIVEMODE_CCR)
368 {
369 pState->diveSettings.diveMode = DIVEMODE_OC;
370 block_diluent_page();
371 }
372 }
373
374
375 /* surface mode */
376 void openEdit_Gas(uint8_t line, uint8_t ccr)
377 {
378 uint8_t gasID, oxygen, helium, depthDeco, active, first, depthMOD, deco, travel, inactive;//, bottleSizeLiter;, bottleWirelessStatus;
379 //uint16_t bottleWirelessId;//, bottleWirelessIdSmall;
380
381 char text[32];
382 char textMOD[32];
383 uint8_t txtptr;
384
385 if(line)
386 set_globalState_Menu_Line(line);
387 else
388 set_globalState_Menu_Line(NUM_GASES + 1);
389
390 if(ccr)
391 resetMenuEdit(CLUT_MenuPageGasCC);
392 else
393 resetMenuEdit(CLUT_MenuPageGasOC);
394
395 if(ccr)
396 gasID = line + NUM_OFFSET_DILUENT;
397 else
398 gasID = line;
399
400 editGasPage.ccr = ccr;
401 editGasPage.gasID = gasID;
402 editGasPage.mod = calc_MOD(gasID);
403
404 SSettings *data = settingsGetPointer();
405 editGasPage.pGasLine = data->gas;
406
407 oxygen = editGasPage.pGasLine[gasID].oxygen_percentage;
408 if(oxygen > 99)
409 oxygen = 99;
410 helium = editGasPage.pGasLine[gasID].helium_percentage;
411 depthDeco = editGasPage.pGasLine[gasID].depth_meter;
412 //depthTravel = editGasPage.pGasLine[gasID].depth_meter_travel;
413 active = editGasPage.pGasLine[gasID].note.ub.active;
414 first = editGasPage.pGasLine[gasID].note.ub.first;
415 deco = editGasPage.pGasLine[gasID].note.ub.deco;
416 travel = editGasPage.pGasLine[gasID].note.ub.travel;
417
418 //bottleSizeLiter = editGasPage.pGasLine[gasID].bottle_size_liter;
419 // bottleWirelessStatus = editGasPage.pGasLine[gasID].bottle_wireless_status;
420 //bottleWirelessId = editGasPage.pGasLine[gasID].bottle_wireless_id;
421 //bottleWirelessIdSmall = bottleWirelessId & 0x0F;
422
423 if(active)
424 inactive = 0;
425 else
426 inactive = 1;
427
428 depthMOD = editGasPage.mod;
429
430 int i = 0;
431 if(gasID >= 10)
432 {
433 i = 1;
434 strcpy(text, "\001" "Gas #10 X");
435 }
436 else
437 strcpy(text, "\001" "Gas #0 X");
438
439 if(ccr)
440 text[8+i] = TXT_Diluent_Gas_Edit;
441 else
442 text[8+i] = TXT_OC_Gas_Edit;
443
444 if(gasID >= 10)
445 text[6+i] += gasID - 10;
446 else
447 text[6+i] += gasID;
448
449 write_topline(text);
450 if(actual_menu_content == MENU_SURFACE)
451 {
452 write_label_fix( 20, 800, ME_Y_LINE1, &FontT48, TXT_Mix);
453 write_field_udigit(StMOG_Mix, 210, 400, ME_Y_LINE1, &FontT48, "##/##", (uint32_t)oxygen, (uint32_t)helium, 0, 0);
454
455
456 text[1] = 0;
457 if(inactive)
458 text[0] = TXT_Inactive;
459 else
460 if(first)
461 text[0] = TXT_First;
462 else
463 if(deco)
464 text[0] = TXT_Deco;
465 else
466 if(travel)
467 text[0] = TXT_Travel;
468 else
469 text[0] = TXT_Inactive;
470
471 write_field_button(StMOG_GasType, 20, 710, ME_Y_LINE2, &FontT48, text);
472
473
474 if(deco)
475 {
476 text[0] = TXT_ChangeDepth;
477 text[1] = ' ';
478 text[2] = TXT_Deco;
479 text[3] = 0;
480 write_label_var( 20 ,800, ME_Y_LINE3, &FontT48, text);
481
482 textMOD[0] = '#';
483 textMOD[1] = '#';
484 textMOD[2] = '#';
485 textMOD[3] = unit_depth_char1();
486 textMOD[4] = unit_depth_char2();
487 textMOD[5] = 0;
488 write_field_udigit(StMOG_ChangeDepth, 600, 710, ME_Y_LINE3, &FontT48,textMOD, (uint32_t)unit_depth_integer(depthDeco), 0, 0, 0);
489
490 txtptr = 0;
491 text[txtptr++] = TXT_2BYTE;
492 text[txtptr++] = TXT2BYTE_SetToMOD;
493 text[txtptr++] = 0;
494 write_field_button(StMOG_SetToMOD, 20, 710, ME_Y_LINE4, &FontT48,text);
495 }
496 else
497 {
498 txtptr = 0;
499 text[txtptr++] = '\021';
500 text[txtptr++] = TXT_ChangeDepth;
501 text[txtptr++] = ' ';
502 text[txtptr++] = TXT_Deco;
503 text[txtptr++] = 0;
504 write_label_var( 20 ,800, ME_Y_LINE3, &FontT48, text);
505
506 txtptr = 0;
507 text[txtptr++] = '\021';
508 text[txtptr++] = TXT_2BYTE;
509 text[txtptr++] = TXT2BYTE_SetToMOD;
510 text[txtptr++] = 0;
511 write_label_var( 20 ,800, ME_Y_LINE4, &FontT48, text);
512 }
513 /*
514 txtptr = 0;
515 text[txtptr++] = TXT_2BYTE;
516 text[txtptr++] = TXT2BYTE_Bottle;
517 text[txtptr++] = 0;
518 write_label_var( 20 ,800, ME_Y_LINE5, &FontT48, text);
519 write_field_2digit(StMOG_Bottle, 600, 710, ME_Y_LINE5, &FontT48,"## ltr", (uint32_t)bottleSizeLiter, 0, 0, 0);
520
521 txtptr = 0;
522 text[txtptr++] = TXT_2BYTE;
523 text[txtptr++] = TXT2BYTE_WirelessSender;
524 text[txtptr++] = ' ';
525 if(!bottleWirelessId)
526 text[txtptr++] = '\021';
527 txtptr += snprintf(&text[txtptr],20,"%u (%04X)",bottleWirelessIdSmall, bottleWirelessId);
528 write_field_button(StMOG_Wireless, 20, 710, ME_Y_LINE6, &FontT48, text);
529 */
530 stop_cursor_fields();
531
532 textMOD[0] = '#';
533 textMOD[1] = '#';
534 textMOD[2] = '#';
535 textMOD[3] = unit_depth_char1();
536 textMOD[4] = unit_depth_char2();
537 textMOD[5] = ' ';
538 textMOD[6] = 'M';
539 textMOD[7] = 'O';
540 textMOD[8] = 'D';
541 textMOD[9] = 0;
542
543 write_field_udigit(StMOG_MOD, 401, 780, ME_Y_LINE1, &FontT48, textMOD, (uint32_t)unit_depth_integer(depthMOD), 0, 0, 0);
544 // write_field_udigit(StMOG_MOD, 401, 780, ME_Y_LINE1, &FontT48, "###m MOD", (uint32_t)depthMOD, 0, 0, 0);
545
546 setEvent(StMOG_Mix, (uint32_t)OnAction_Mix);
547 setEvent(StMOG_GasType, (uint32_t)OnAction_GasType);
548
549 if(deco)
550 {
551 setEvent(StMOG_ChangeDepth, (uint32_t)OnAction_ChangeDepth);
552 setEvent(StMOG_SetToMOD, (uint32_t)OnAction_SetToMOD);
553 }
554 /*
555 setEvent(StMOG_Bottle, (uint32_t)OnAction_BottleSize);
556 setEvent(StMOG_Wireless, (uint32_t)OnAction_Wireless);
557 */
558 write_buttonTextline(TXT2BYTE_ButtonBack,TXT2BYTE_ButtonEnter,TXT2BYTE_ButtonNext);
559 }
560 }
561
562 /* surface mode */
563 void openEdit_GasType(void)
564 {
565 uint8_t gasID, active, first, deco, travel, inactive;
566 char text[32];
567
568
569 if(editGasPage.ccr)
570 {
571 resetMenuEdit(CLUT_MenuPageGasCC);
572 setBackMenu((uint32_t)openEdit_GasCC, editGasPage.gasID - NUM_OFFSET_DILUENT, 2);
573 }
574 else
575 {
576 resetMenuEdit(CLUT_MenuPageGasOC);
577 setBackMenu((uint32_t)openEdit_GasOC, editGasPage.gasID, 2);
578 }
579
580 gasID = editGasPage.gasID;
581 active = editGasPage.pGasLine[gasID].note.ub.active;
582 first = editGasPage.pGasLine[gasID].note.ub.first;
583 deco = editGasPage.pGasLine[gasID].note.ub.deco;
584 travel = editGasPage.pGasLine[gasID].note.ub.travel;
585
586 if(active)
587 inactive = 0;
588 else
589 inactive = 1;
590
591
592 /* header */
593 int i = 0;
594 if(gasID >= 10)
595 {
596 i = 1;
597 strcpy(text, "\001" "Gas #10 X");
598 }
599 else
600 strcpy(text, "\001" "Gas #0 X");
601
602 if(editGasPage.ccr)
603 text[8+i] = TXT_Diluent_Gas_Edit;
604 else
605 text[8+i] = TXT_OC_Gas_Edit;
606
607 if(gasID >= 10)
608 text[6+i] += gasID - 10;
609 else
610 text[6+i] += gasID;
611 write_topline(text);
612
613 text[1] = 0;
614 text[0] = TXT_First;
615 write_field_on_off(StMOG_First, 30, 400, ME_Y_LINE1, &FontT48, text, first);
616
617 text[0] = TXT_Deco;
618 write_field_on_off(StMOG_Deco, 30, 400, ME_Y_LINE2, &FontT48, text, deco);
619
620 text[0] = TXT_Travel;
621 write_field_on_off(StMOG_Travel, 30, 400, ME_Y_LINE3, &FontT48, text, travel);
622
623 text[0] = TXT_Inactive;
624 write_field_on_off(StMOG_Inactive, 30, 400, ME_Y_LINE4, &FontT48, text, inactive);
625
626 setEvent(StMOG_First, (uint32_t)OnAction_First);
627 setEvent(StMOG_Deco, (uint32_t)OnAction_Deco);
628 setEvent(StMOG_Travel, (uint32_t)OnAction_Travel);
629 setEvent(StMOG_Inactive, (uint32_t)OnAction_Inactive);
630
631 write_buttonTextline(TXT2BYTE_ButtonBack,TXT2BYTE_ButtonEnter,TXT2BYTE_ButtonNext);
632 }
633
634 uint8_t OnAction_GasType(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action)
635 {
636 openEdit_GasType();
637 return UNSPECIFIC_RETURN;
638 }
639
640 void openEdit_Wireless(void)
641 {
642 uint8_t gasID, wirelessSenderAvailable, isNotMatched, isMatchedWithThis, wirelessSenderActive[MAX_SENDER_AT_ONCE], senderCount, isInList; //, wirelessStatus;
643 uint16_t wirelessId, wirelessSenderIdSmall, wirelessIdTemp;
644 char text[32];
645 uint8_t txtptr;
646
647 if(editGasPage.ccr)
648 {
649 resetMenuEdit(CLUT_MenuPageGasCC);
650 setBackMenu((uint32_t)openEdit_GasCC, editGasPage.gasID - NUM_OFFSET_DILUENT, 5);
651 }
652 else
653 {
654 resetMenuEdit(CLUT_MenuPageGasOC);
655 setBackMenu((uint32_t)openEdit_GasOC, editGasPage.gasID, 5);
656 }
657
658 gasID = editGasPage.gasID;
659 wirelessId = editGasPage.pGasLine[gasID].bottle_wireless_id;
660 // wirelessStatus = editGasPage.pGasLine[gasID].bottle_wireless_status;
661
662
663 /* header */
664 int i = 0;
665 if(gasID >= 10)
666 {
667 i = 1;
668 strcpy(text, "\001" "Gas #10 X");
669 }
670 else
671 strcpy(text, "\001" "Gas #0 X");
672
673 if(editGasPage.ccr)
674 text[8+i] = TXT_Diluent_Gas_Edit;
675 else
676 text[8+i] = TXT_OC_Gas_Edit;
677
678 if(gasID >= 10)
679 text[6+i] += gasID - 10;
680 else
681 text[6+i] += gasID;
682 write_topline(text);
683
684 senderCount = 0;
685 wirelessSenderAvailable = 0;
686 if(wirelessId)
687 {
688 wirelessSender[senderCount] = wirelessId;
689 wirelessSenderActive[senderCount] = 0;
690 wirelessSenderAvailable++;
691 senderCount++;
692 }
693
694 for(int i=0;i<4;i++)
695 {
696 if((stateUsed->lifeData.wireless_data[i].ageInMilliSeconds) && (stateUsed->lifeData.wireless_data[i].ageInMilliSeconds <= 60000) && ((stateUsed->lifeData.wireless_data[i].data[1] & 0x0F) != 0))
697 {
698 wirelessIdTemp = stateUsed->lifeData.wireless_data[i].data[0] * 256;
699 wirelessIdTemp += stateUsed->lifeData.wireless_data[i].data[1];
700 if(wirelessId && (wirelessId == wirelessIdTemp))
701 wirelessSenderActive[0] = 1;
702 else
703 {
704 isInList = 0;
705 for(int j=0;j<wirelessSenderAvailable;j++)
706 {
707 if(wirelessSender[j] == wirelessIdTemp)
708 {
709 isInList = 1;
710 break;
711 }
712 }
713 if(!isInList)
714 {
715 wirelessSender[senderCount] = wirelessIdTemp;
716 wirelessSenderActive[senderCount] = 1;
717 wirelessSenderAvailable++;
718 senderCount++;
719 }
720 }
721 }
722 }
723
724 if(wirelessSenderAvailable > MAX_SENDER_AT_ONCE)
725 wirelessSenderAvailable = MAX_SENDER_AT_ONCE;
726
727 isNotMatched = 1;
728
729 for(int i=0;i<wirelessSenderAvailable;i++)
730 {
731 wirelessSenderIdSmall = wirelessSender[i] & 0x0F;
732
733 txtptr = 0;
734 if(!wirelessSenderActive[i])
735 text[txtptr++] = '\021';
736 txtptr += snprintf(&text[txtptr],10,"%u (%04X)",wirelessSenderIdSmall, wirelessSender[i]);
737
738 if(wirelessId == wirelessSender[i])
739 {
740 isMatchedWithThis = 1;
741 isNotMatched = 0;
742 }
743 else
744 {
745 isMatchedWithThis = 0;
746 for(int j=1; j <= 2*NUM_GASES; j++)
747 {
748 if((gasID != j) && (settingsGetPointer()->gas[j].bottle_wireless_id == wirelessSender[i]))
749 {
750 txtptr += snprintf(&text[txtptr],20," used by Gas #%i",i);
751 break;
752 }
753 }
754 }
755 write_field_on_off(StMOG_Transmitter1 + i, 30, 710, ME_Y_LINE1 + (i * ME_Y_LINE_STEP), &FontT48, text, isMatchedWithThis);
756 }
757
758
759 txtptr = 0;
760 text[txtptr++] = TXT_2BYTE;
761 text[txtptr++] = TXT2BYTE_WirelessDisconnect;
762 text[txtptr++] = 0;
763 write_field_on_off(StMOG_NoTransmitter, 30, 400, ME_Y_LINE6, &FontT48, text, isNotMatched);
764
765 // setEvent has to be _after_ all fields are written
766 for(int i=0;i<wirelessSenderAvailable;i++)
767 setEvent(StMOG_Transmitter1 + i, (uint32_t)OnAction_WirelessID);
768
769 setEvent(StMOG_NoTransmitter, (uint32_t)OnAction_NoWireless);
770 }
771
772
773 uint8_t OnAction_Wireless(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action)
774 {
775 openEdit_Wireless();
776 return UNSPECIFIC_RETURN;
777 }
778
779
780 uint8_t OnAction_WirelessID (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action)
781 {
782 if((editId < StMOG_Transmitter1) || (editId > StMOG_Transmitter5))
783 return UNSPECIFIC_RETURN;
784
785 uint8_t line, isMatched;
786
787 line = editId - StMOG_Transmitter1;
788
789
790 if(editGasPage.pGasLine[editGasPage.gasID].bottle_wireless_id == wirelessSender[line])
791 isMatched = 1;
792 else
793 isMatched = 0;
794
795 editGasPage.pGasLine[editGasPage.gasID].bottle_wireless_id = wirelessSender[line];
796 // editGasPage.pGasLine[editGasPage.gasID].bottle_wireless_status = 0;
797
798 for(int i=0;i<5;i++)
799 {
800 if((StMOG_Transmitter1 + i) != editId)
801 tMenuEdit_set_on_off(StMOG_Transmitter1 + i, 0);
802 }
803 tMenuEdit_set_on_off(editId, 1);
804 tMenuEdit_set_on_off(StMOG_NoTransmitter, 0);
805
806 if(!isMatched)
807 return UPDATE_DIVESETTINGS;
808 else
809 return UPDATE_AND_EXIT_TO_MENU;
810 }
811
812
813 uint8_t OnAction_NoWireless (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action)
814 {
815 uint8_t isNotMatched;
816
817 if(editGasPage.pGasLine[editGasPage.gasID].bottle_wireless_id == 0)
818 isNotMatched = 1;
819 else
820 isNotMatched = 1;
821
822 editGasPage.pGasLine[editGasPage.gasID].bottle_wireless_id = 0;
823 // editGasPage.pGasLine[editGasPage.gasID].bottle_wireless_status = 0;
824
825 tMenuEdit_set_on_off(StMOG_Transmitter1, 0);
826 tMenuEdit_set_on_off(StMOG_Transmitter2, 0);
827 tMenuEdit_set_on_off(StMOG_Transmitter3, 0);
828 tMenuEdit_set_on_off(StMOG_Transmitter4, 0);
829 tMenuEdit_set_on_off(StMOG_Transmitter5, 0);
830 tMenuEdit_set_on_off(StMOG_NoTransmitter, 1);
831
832 if(!isNotMatched)
833 return UPDATE_DIVESETTINGS;
834 else
835 return UPDATE_AND_EXIT_TO_MENU;
836 }
837
838
839 uint8_t OnAction_Mix(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action)
840 {
841 uint8_t digitContentNew;
842 uint32_t newOxygen, newHelium;
843
844 if(action == ACTION_BUTTON_ENTER)
845 {
846 return digitContent;
847 }
848 if(action == ACTION_BUTTON_ENTER_FINAL)
849 {
850 evaluateNewString(editId, &newOxygen, &newHelium, 0, 0);
851
852 if(newOxygen < 5)
853 newOxygen = 5;
854 if(newOxygen == 99)
855 newOxygen = 100;
856 if(newHelium > 95)
857 newHelium = 95;
858 if((newOxygen + newHelium) > 100)
859 newOxygen = 100 - newHelium;
860
861 editGasPage.pGasLine[editGasPage.gasID].oxygen_percentage = newOxygen;
862 editGasPage.pGasLine[editGasPage.gasID].helium_percentage = newHelium;
863 editGasPage.mod = calc_MOD(editGasPage.gasID);
864
865 if(newOxygen == 100)
866 newOxygen = 99;
867
868 tMenuEdit_newInput(editId, newOxygen, newHelium, 0, 0);
869 tMenuEdit_newInput(StMOG_MOD, (uint32_t)unit_depth_integer(editGasPage.mod), 0, 0, 0);
870
871 return UPDATE_DIVESETTINGS;
872 }
873 if(action == ACTION_BUTTON_NEXT)
874 {
875 digitContentNew = digitContent + 1;
876 if(digitContentNew > '9')
877 digitContentNew = '0';
878 return digitContentNew;
879 }
880 if(action == ACTION_BUTTON_BACK)
881 {
882 digitContentNew = digitContent - 1;
883 if(digitContentNew < '0')
884 digitContentNew = '9';
885 return digitContentNew;
886 }
887
888 return UNSPECIFIC_RETURN;
889 }
890
891 /*
892 uint8_t OnAction_DefaultMix(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action)
893 {
894 uint32_t newOxygen, newHelium;
895 uint8_t depthDEFAULT;
896 char text[32];
897
898 newOxygen = 21;
899 newHelium = 0;
900
901 editGasPage.pGasLine[editGasPage.gasID].oxygen_percentage = newOxygen;
902 editGasPage.pGasLine[editGasPage.gasID].helium_percentage = newHelium;
903
904 tMenuEdit_newInput(StMOG_Mix, newOxygen, newHelium, 0, 0);
905
906 depthDEFAULT = calc_MOD(editGasPage.gasID);
907 create_text_with_u8(text, "", depthDEFAULT, "m MOD");
908 tMenuEdit_newButtonText(StMOG_DefaultDepth, text);
909
910 return UPDATE_DIVESETTINGS;
911 }
912
913 uint8_t OnAction_ToggleDepth(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action)
914 {
915 uint8_t depth;
916 uint32_t newDefaultDepth;
917 char text[32];
918
919 if(editGasPage.depth_mode == 0)
920 {
921 editGasPage.depth_mode = 1;
922 depth = editGasPage.pGasLine[editGasPage.gasID].depth_meter_travel;
923 newDefaultDepth = calc_MinOD(editGasPage.gasID);
924 create_text_with_u8(text, "", newDefaultDepth, "m Min");
925 }
926 else
927 {
928 editGasPage.depth_mode = 0;
929 depth = editGasPage.pGasLine[editGasPage.gasID].depth_meter;
930 newDefaultDepth = calc_MOD(editGasPage.gasID);
931 create_text_with_u8(text, "", newDefaultDepth, "m MOD");
932 }
933 tMenuEdit_newInput(StMOG_Depth, (uint32_t)depth, 0, 0, 0);
934 tMenuEdit_newButtonText(StMOG_DefaultDepth, text);
935
936 return UNSPECIFIC_RETURN;
937 }
938
939
940 uint8_t OnAction_Depth(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action)
941 {
942 uint8_t digitContentNew;
943 uint32_t newDepth;
944
945 if(action == ACTION_BUTTON_ENTER)
946 {
947 return digitContent;
948 }
949 if(action == ACTION_BUTTON_ENTER_FINAL)
950 {
951 evaluateNewString(editId, &newDepth, 0, 0, 0);
952 if(newDepth > 255)
953 newDepth = 255;
954 if(editGasPage.depth_mode == 0)
955 editGasPage.pGasLine[editGasPage.gasID].depth_meter = newDepth;
956 else
957 editGasPage.pGasLine[editGasPage.gasID].depth_meter_travel = newDepth;
958 tMenuEdit_newInput(editId, newDepth, 0, 0, 0);
959 return UPDATE_DIVESETTINGS;
960 }
961 if(action == ACTION_BUTTON_NEXT)
962 {
963 digitContentNew = digitContent + 1;
964 if(digitContentNew > '9')
965 digitContentNew = '0';
966 return digitContentNew;
967 }
968 if(action == ACTION_BUTTON_BACK)
969 {
970 digitContentNew = digitContent - 1;
971 if(digitContentNew < '0')
972 digitContentNew = '9';
973 return digitContentNew;
974 }
975
976 return UNSPECIFIC_RETURN;
977 }
978
979
980 uint8_t OnAction_DefaultDepth(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action)
981 {
982 uint32_t newDepth;
983
984 if(editGasPage.depth_mode == 0)
985 {
986 newDepth = calc_MOD(editGasPage.gasID);
987 editGasPage.pGasLine[editGasPage.gasID].depth_meter = newDepth;
988 }
989 else
990 {
991 newDepth = calc_MinOD(editGasPage.gasID);
992 editGasPage.pGasLine[editGasPage.gasID].depth_meter_travel = newDepth;
993 }
994
995 tMenuEdit_newInput(StMOG_Depth, newDepth, 0, 0, 0);
996
997 return UPDATE_DIVESETTINGS;
998 }
999
1000
1001 uint8_t OnAction_Active(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action)
1002 {
1003 uint8_t active, first;
1004
1005 first = editGasPage.pGasLine[editGasPage.gasID].note.ub.first;
1006
1007 if(first)
1008 return UNSPECIFIC_RETURN;
1009
1010 active = editGasPage.pGasLine[editGasPage.gasID].note.ub.active;
1011
1012 if(active)
1013 {
1014 active = 0;
1015 editGasPage.pGasLine[editGasPage.gasID].note.ub.active = 0;
1016 }
1017 else
1018 {
1019 active = 1;
1020 editGasPage.pGasLine[editGasPage.gasID].note.ub.active = 1;
1021 }
1022 tMenuEdit_set_on_off(editId, active);
1023
1024 return UPDATE_DIVESETTINGS;
1025 }
1026 */
1027
1028
1029 uint8_t OnAction_First(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action)
1030 {
1031 uint8_t first, i, gasOne;
1032
1033
1034 SDiveState * pStateReal = stateRealGetPointerWrite();
1035
1036 if(editGasPage.ccr)
1037 gasOne = 1 + NUM_OFFSET_DILUENT;
1038 else
1039 gasOne = 1;
1040
1041 first = editGasPage.pGasLine[editGasPage.gasID].note.ub.first;
1042
1043 if(!first)
1044 {
1045 for(i=gasOne;i<NUM_GASES + gasOne;i++)
1046 {
1047 if(editGasPage.pGasLine[i].note.ub.first)
1048 {
1049 editGasPage.pGasLine[i].note.ub.first = 0;
1050 editGasPage.pGasLine[i].note.ub.active = 0;
1051 }
1052 }
1053 }
1054
1055 editGasPage.pGasLine[editGasPage.gasID].note.ub.first = 1;
1056 editGasPage.pGasLine[editGasPage.gasID].note.ub.active = 1;
1057 editGasPage.pGasLine[editGasPage.gasID].note.ub.deco = 0;
1058 editGasPage.pGasLine[editGasPage.gasID].note.ub.travel = 0;
1059 editGasPage.pGasLine[editGasPage.gasID].depth_meter = 0;
1060 editGasPage.pGasLine[editGasPage.gasID].depth_meter_travel = 0;
1061
1062 tMenuEdit_set_on_off(StMOG_First, 1);
1063 tMenuEdit_set_on_off(StMOG_Deco, 0);
1064 tMenuEdit_set_on_off(StMOG_Travel, 0);
1065 tMenuEdit_set_on_off(StMOG_Inactive, 0);
1066
1067 if(!first)
1068 return UPDATE_DIVESETTINGS;
1069 else
1070 return UPDATE_AND_EXIT_TO_MENU;
1071 }
1072
1073
1074 uint8_t OnAction_Deco(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action)
1075 {
1076 uint8_t first, deco, gasOne;
1077 SDiveState * pStateReal = stateRealGetPointerWrite();
1078
1079 if(editGasPage.ccr)
1080 gasOne = 1 + NUM_OFFSET_DILUENT;
1081 else
1082 gasOne = 1;
1083
1084 first = editGasPage.pGasLine[editGasPage.gasID].note.ub.first;
1085 deco = editGasPage.pGasLine[editGasPage.gasID].note.ub.deco;
1086
1087 if(first)
1088 {
1089 if(editGasPage.gasID == gasOne)
1090 return UNSPECIFIC_RETURN;
1091 else
1092 {
1093 editGasPage.pGasLine[gasOne].note.ub.first = 1;
1094 editGasPage.pGasLine[gasOne].note.ub.active = 1;
1095 editGasPage.pGasLine[gasOne].note.ub.deco = 0;
1096 editGasPage.pGasLine[gasOne].note.ub.travel = 0;
1097 editGasPage.pGasLine[gasOne].depth_meter = 0;
1098 editGasPage.pGasLine[gasOne].depth_meter_travel = 0;
1099 }
1100 }
1101
1102 editGasPage.pGasLine[editGasPage.gasID].note.ub.first = 0;
1103 editGasPage.pGasLine[editGasPage.gasID].note.ub.active = 1;
1104 editGasPage.pGasLine[editGasPage.gasID].note.ub.deco = 1;
1105 editGasPage.pGasLine[editGasPage.gasID].note.ub.travel = 0;
1106 editGasPage.pGasLine[editGasPage.gasID].depth_meter_travel = 0;
1107 editGasPage.mod = calc_MOD(editGasPage.gasID);
1108 editGasPage.pGasLine[editGasPage.gasID].depth_meter = editGasPage.mod;
1109
1110 /*
1111 if(deco)
1112 {
1113 editGasPage.pGasLine[editGasPage.gasID].depth_meter = editGasPage.mod;
1114 tMenuEdit_newInput(StMOG_ChangeDepth, editGasPage.pGasLine[editGasPage.gasID].depth_meter, 0, 0, 0);
1115 }
1116 */
1117
1118 tMenuEdit_set_on_off(StMOG_First, 0);
1119 tMenuEdit_set_on_off(StMOG_Deco, 1);
1120 tMenuEdit_set_on_off(StMOG_Travel, 0);
1121 tMenuEdit_set_on_off(StMOG_Inactive, 0);
1122
1123 if(!deco)
1124 return UPDATE_DIVESETTINGS;
1125 else
1126 return UPDATE_AND_EXIT_TO_MENU;
1127 }
1128
1129
1130 uint8_t OnAction_Travel(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action)
1131 {
1132 uint8_t first, travel, gasOne;
1133 SDiveState * pStateReal = stateRealGetPointerWrite();
1134
1135 if(editGasPage.ccr)
1136 gasOne = 1 + NUM_OFFSET_DILUENT;
1137 else
1138 gasOne = 1;
1139
1140 first = editGasPage.pGasLine[editGasPage.gasID].note.ub.first;
1141 travel = editGasPage.pGasLine[editGasPage.gasID].note.ub.travel;
1142
1143 if(first)
1144 {
1145 if(editGasPage.gasID == gasOne)
1146 return UNSPECIFIC_RETURN;
1147 else
1148 {
1149 editGasPage.pGasLine[gasOne].note.ub.first = 1;
1150 editGasPage.pGasLine[gasOne].note.ub.active = 1;
1151 editGasPage.pGasLine[gasOne].note.ub.deco = 0;
1152 editGasPage.pGasLine[gasOne].note.ub.travel = 0;
1153 editGasPage.pGasLine[gasOne].depth_meter = 0;
1154 editGasPage.pGasLine[gasOne].depth_meter_travel = 0;
1155 }
1156 }
1157
1158 editGasPage.pGasLine[editGasPage.gasID].note.ub.first = 0;
1159 editGasPage.pGasLine[editGasPage.gasID].note.ub.active = 1;
1160 editGasPage.pGasLine[editGasPage.gasID].note.ub.deco = 0;
1161 editGasPage.pGasLine[editGasPage.gasID].note.ub.travel = 1;
1162 editGasPage.pGasLine[editGasPage.gasID].depth_meter = 0;
1163 editGasPage.pGasLine[editGasPage.gasID].depth_meter_travel = 0;
1164
1165 tMenuEdit_set_on_off(StMOG_First, 0);
1166 tMenuEdit_set_on_off(StMOG_Deco, 0);
1167 tMenuEdit_set_on_off(StMOG_Travel, 1);
1168 tMenuEdit_set_on_off(StMOG_Inactive, 0);
1169
1170 if(!travel)
1171 return UPDATE_DIVESETTINGS;
1172 else
1173 return UPDATE_AND_EXIT_TO_MENU;
1174 }
1175
1176
1177 uint8_t OnAction_Inactive(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action)
1178 {
1179 uint8_t first, inactive, gasOne;
1180 SDiveState * pStateReal = stateRealGetPointerWrite();
1181
1182 if(editGasPage.ccr)
1183 gasOne = 1 + NUM_OFFSET_DILUENT;
1184 else
1185 gasOne = 1;
1186
1187 first = editGasPage.pGasLine[editGasPage.gasID].note.ub.first;
1188
1189 if(editGasPage.pGasLine[editGasPage.gasID].note.ub.active)
1190 inactive = 0;
1191 else
1192 inactive = 1;
1193
1194 if(first)
1195 {
1196 if(editGasPage.gasID == gasOne)
1197 return UNSPECIFIC_RETURN;
1198 else
1199 {
1200 editGasPage.pGasLine[gasOne].note.ub.first = 1;
1201 editGasPage.pGasLine[gasOne].note.ub.active = 1;
1202 editGasPage.pGasLine[gasOne].note.ub.deco = 0;
1203 editGasPage.pGasLine[gasOne].note.ub.travel = 0;
1204 editGasPage.pGasLine[gasOne].depth_meter = 0;
1205 editGasPage.pGasLine[gasOne].depth_meter_travel = 0;
1206 }
1207 }
1208
1209 editGasPage.pGasLine[editGasPage.gasID].note.ub.first = 0;
1210 editGasPage.pGasLine[editGasPage.gasID].note.ub.active = 0;
1211 editGasPage.pGasLine[editGasPage.gasID].note.ub.deco = 0;
1212 editGasPage.pGasLine[editGasPage.gasID].note.ub.travel = 0;
1213
1214 tMenuEdit_set_on_off(StMOG_First, 0);
1215 tMenuEdit_set_on_off(StMOG_Deco, 0);
1216 tMenuEdit_set_on_off(StMOG_Travel, 0);
1217 tMenuEdit_set_on_off(StMOG_Inactive, 1);
1218
1219 if(!inactive)
1220 return UPDATE_DIVESETTINGS;
1221 else
1222 return UPDATE_AND_EXIT_TO_MENU;
1223 }
1224
1225
1226 uint8_t OnAction_SetToMOD (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action)
1227 {
1228 uint8_t newChangeDepth = editGasPage.mod;
1229
1230 editGasPage.pGasLine[editGasPage.gasID].depth_meter = newChangeDepth;
1231 tMenuEdit_newInput(StMOG_ChangeDepth, unit_depth_integer(newChangeDepth), 0, 0, 0);
1232
1233 return UPDATE_DIVESETTINGS;
1234 }
1235
1236
1237 uint8_t OnAction_ChangeDepth(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action)
1238 {
1239 uint8_t digitContentNew;
1240 uint32_t newDepth;
1241
1242 if(action == ACTION_BUTTON_ENTER)
1243 {
1244 return digitContent;
1245 }
1246 if(action == ACTION_BUTTON_ENTER_FINAL)
1247 {
1248 evaluateNewString(editId, &newDepth, 0, 0, 0);
1249 if(settingsGetPointer()->nonMetricalSystem != 0) // new hw 170703
1250 {
1251 newDepth += 2; // f�r rundung
1252 newDepth = (newDepth * 3) / 10;
1253 }
1254 if(newDepth > 255)
1255 newDepth = 255;
1256 editGasPage.pGasLine[editGasPage.gasID].depth_meter = newDepth;
1257 tMenuEdit_newInput(editId, unit_depth_integer(newDepth), 0, 0, 0);
1258 return UPDATE_DIVESETTINGS;
1259 }
1260 if(action == ACTION_BUTTON_NEXT)
1261 {
1262 digitContentNew = digitContent + 1;
1263 if(digitContentNew > '9')
1264 digitContentNew = '0';
1265 return digitContentNew;
1266 }
1267 if(action == ACTION_BUTTON_BACK)
1268 {
1269 digitContentNew = digitContent - 1;
1270 if(digitContentNew < '0')
1271 digitContentNew = '9';
1272 return digitContentNew;
1273 }
1274
1275 return UNSPECIFIC_RETURN;
1276 }
1277
1278
1279 uint8_t OnAction_BottleSize (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action)
1280 {
1281 int8_t digitContentNew;
1282 uint32_t newBottleSize;
1283 // const uint8_t validSize = {4,7,8,10,12,15,16,17,20,24,30,40,255};
1284 const uint8_t validSize[] = {40,30,24,20,17,16,15,12,10,8,7,4,0};
1285
1286 if(action == ACTION_BUTTON_ENTER)
1287 {
1288 return digitContent;
1289 }
1290 if(action == ACTION_BUTTON_ENTER_FINAL)
1291 {
1292 evaluateNewString(editId, &newBottleSize, 0, 0, 0);
1293
1294 if(newBottleSize > validSize[0])
1295 newBottleSize = validSize[0];
1296
1297 editGasPage.pGasLine[editGasPage.gasID].bottle_size_liter = newBottleSize;
1298
1299 tMenuEdit_newInput(editId, newBottleSize, 0, 0, 0);
1300 return UPDATE_DIVESETTINGS;
1301 }
1302 if(action == ACTION_BUTTON_NEXT)
1303 {
1304 // new here for ease of comparison
1305 digitContentNew = digitContent - '0';
1306
1307 if(digitContentNew > 0)
1308 {
1309 int i = 0;
1310 while(digitContentNew < validSize[i])
1311 {
1312 i++;
1313 }
1314 if(i == 0)
1315 digitContentNew = 0; // off
1316 else
1317 digitContentNew = validSize[i-1];
1318 }
1319 else
1320 {
1321 int i = 0;
1322 while(validSize[i] != 0)
1323 i++;
1324 digitContentNew = validSize[i-1]; // smallest tank
1325 }
1326 digitContentNew += '0';
1327 return digitContentNew;
1328 }
1329 if(action == ACTION_BUTTON_BACK)
1330 {
1331 // new here for ease of comparison
1332 digitContentNew = digitContent - '0';
1333 if(digitContentNew > 0)
1334 {
1335 int i = 0;
1336 while(digitContentNew < validSize[i])
1337 {
1338 i++;
1339 }
1340 if(validSize[i] == 0)
1341 digitContentNew = 0; // off
1342 else if(validSize[i+1] == 0)
1343 digitContentNew = 0; // off
1344 else
1345 digitContentNew = validSize[i+1];
1346 }
1347 else
1348 {
1349 digitContentNew = validSize[0];
1350 }
1351 digitContentNew += '0';
1352
1353 return digitContentNew;
1354 }
1355 return EXIT_TO_MENU;
1356 }
1357
1358
1359 /* Private functions ---------------------------------------------------------*/
1360
1361
1362 void create_text_with_u8(char *text, const char *text1, uint8_t inputU8, const char *text2)
1363 {
1364 uint8_t digit1, digit2, digit3, count;
1365
1366 count = 0;
1367
1368 if(*text1)
1369 {
1370 strcpy(&text[count], text1);
1371 count = strlen(text1);
1372 }
1373
1374 digit1 = inputU8 / 100;
1375 inputU8 -= digit1 * 100;
1376 digit2 = inputU8 / 10;
1377 inputU8 -= digit2 * 10;
1378 digit3 = inputU8;
1379 if(digit1)
1380 text[count++] = '0' + digit1;
1381 if(count || digit2)
1382 text[count++] = '0' + digit2;
1383 text[count++] = '0' + digit3;
1384
1385 if(*text2)
1386 {
1387 strcpy(&text[count], text2);
1388 }
1389 }