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

include in ostc4 repository
author heinrichsweikamp
date Sat, 28 Apr 2018 11:52:34 +0200
parents
children b7689d9e888a
comparison
equal deleted inserted replaced
37:ccc45c0e1ea2 38:5f11787b4f42
1 ///////////////////////////////////////////////////////////////////////////////
2 /// -*- coding: UTF-8 -*-
3 ///
4 /// \file Discovery/Src/tMenuEditDeco.c
5 /// \brief Main Template file for Menu Edit Deco Parameters
6 /// \author heinrichs weikamp gmbh
7 /// \date 31-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 "tMenuEditDeco.h"
31
32 #include "gfx_fonts.h"
33 #include "tMenuEdit.h"
34
35 /* Private variables ---------------------------------------------------------*/
36 uint8_t lineSelected = 0;
37
38 /* Private function prototypes -----------------------------------------------*/
39
40 void openEdit_DiveMode(void);
41 void openEdit_CCRModeSensorOrFixedSP(void);
42 void openEdit_ppO2max(void);
43 void openEdit_SafetyStop(void);
44 void openEdit_FutureTTS(void);
45 void openEdit_Salinity(void);
46
47 /* Announced function prototypes -----------------------------------------------*/
48
49 uint8_t OnAction_OC (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action);
50 uint8_t OnAction_CC (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action);
51 uint8_t OnAction_Apnea (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action);
52 uint8_t OnAction_Gauge (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action);
53 uint8_t OnAction_FutureTTS (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action);
54 uint8_t OnAction_ppO2Max (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action);
55 uint8_t OnAction_SafetyStop (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action);
56 uint8_t OnAction_Salinity (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action);
57 /* Exported functions --------------------------------------------------------*/
58
59 void openEdit_Deco(uint8_t line)
60 {
61 set_globalState_Menu_Line(line);
62 resetMenuEdit(CLUT_MenuPageDeco);
63
64 SSettings *data = settingsGetPointer();
65
66 lineSelected = line;
67
68 if((data->dive_mode != DIVEMODE_CCR )&& (line > 1))
69 line += 1;
70
71 switch(line)
72 {
73 case 1:
74 default:
75 openEdit_DiveMode();
76 break;
77 case 2:
78 openEdit_CCRModeSensorOrFixedSP();
79 break;
80 case 3:
81 openEdit_ppO2max();
82 break;
83 case 4:
84 openEdit_SafetyStop();
85 break;
86 case 5:
87 openEdit_FutureTTS();
88 break;
89 case 6:
90 openEdit_Salinity();
91 break;
92 }
93 }
94
95 /* Private functions ---------------------------------------------------------*/
96
97
98 void openEdit_DiveMode(void)
99 {
100 #define APNEAANDGAUGE
101
102 char text[32];
103 uint8_t actualDiveMode, active;
104 SSettings *pSettings = settingsGetPointer();
105 actualDiveMode = pSettings->dive_mode;
106
107 text[0] = '\001';
108 text[1] = TXT_DiveMode;
109 text[2] = 0;
110 write_topline(text);
111
112 text[1] = 0;
113
114
115 text[0] = TXT_OpenCircuit;
116 if(actualDiveMode == DIVEMODE_OC)
117 active = 1;
118 else
119 active = 0;
120 write_field_on_off(StMDECO1_OC, 30, 500, ME_Y_LINE1, &FontT48, text, active);
121
122 text[0] = TXT_ClosedCircuit;
123 if(actualDiveMode == DIVEMODE_CCR)
124 active = 1;
125 else
126 active = 0;
127 write_field_on_off(StMDECO1_CC, 30, 500, ME_Y_LINE2, &FontT48, text, active);
128
129 #ifdef APNEAANDGAUGE
130 text[0] = TXT_Apnoe;
131 if(actualDiveMode == DIVEMODE_Apnea)
132 active = 1;
133 else
134 active = 0;
135 write_field_on_off(StMDECO1_Apnea, 30, 500, ME_Y_LINE3, &FontT48, text, active);
136
137 text[0] = TXT_Gauge;
138 if(actualDiveMode == DIVEMODE_Gauge)
139 active = 1;
140 else
141 active = 0;
142 write_field_on_off(StMDECO1_Gauge, 30, 500, ME_Y_LINE4, &FontT48, text, active);
143 #endif
144
145 setEvent(StMDECO1_OC, (uint32_t)OnAction_OC);
146 setEvent(StMDECO1_CC, (uint32_t)OnAction_CC);
147 #ifdef APNEAANDGAUGE
148 setEvent(StMDECO1_Apnea, (uint32_t)OnAction_Apnea);
149 setEvent(StMDECO1_Gauge, (uint32_t)OnAction_Gauge);
150 #endif
151
152 write_buttonTextline(TXT2BYTE_ButtonBack,TXT2BYTE_ButtonEnter,TXT2BYTE_ButtonNext);
153 }
154
155 uint8_t OnAction_OC (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action)
156 {
157 SSettings *pSettings = settingsGetPointer();
158 if(pSettings->dive_mode == DIVEMODE_OC)
159 return EXIT_TO_MENU;
160 pSettings->dive_mode = DIVEMODE_OC;
161 setActualGasFirst(&stateRealGetPointerWrite()->lifeData);
162 tMenuEdit_set_on_off(editId, 1);
163 tMenuEdit_set_on_off(StMDECO1_CC, 0);
164 tMenuEdit_set_on_off(StMDECO1_Apnea, 0);
165 tMenuEdit_set_on_off(StMDECO1_Gauge, 0);
166 return UPDATE_DIVESETTINGS;
167 }
168
169
170 uint8_t OnAction_CC (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action)
171 {
172 SSettings *pSettings = settingsGetPointer();
173 if(pSettings->dive_mode == DIVEMODE_CCR)
174 return EXIT_TO_MENU;
175 pSettings->dive_mode = DIVEMODE_CCR;
176 setActualGasFirst(&stateRealGetPointerWrite()->lifeData);
177 tMenuEdit_set_on_off(editId, 1);
178 tMenuEdit_set_on_off(StMDECO1_OC, 0);
179 tMenuEdit_set_on_off(StMDECO1_Apnea, 0);
180 tMenuEdit_set_on_off(StMDECO1_Gauge, 0);
181 return UPDATE_DIVESETTINGS;
182 }
183
184
185 uint8_t OnAction_Apnea (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action)
186 {
187 SSettings *pSettings = settingsGetPointer();
188 if(pSettings->dive_mode == DIVEMODE_Apnea)
189 return EXIT_TO_MENU;
190 pSettings->dive_mode = DIVEMODE_Apnea;
191 setActualGasFirst(&stateRealGetPointerWrite()->lifeData);
192 tMenuEdit_set_on_off(editId, 1);
193 tMenuEdit_set_on_off(StMDECO1_CC, 0);
194 tMenuEdit_set_on_off(StMDECO1_OC, 0);
195 tMenuEdit_set_on_off(StMDECO1_Gauge, 0);
196 return UPDATE_DIVESETTINGS;
197 }
198
199
200 uint8_t OnAction_Gauge (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action)
201 {
202 SSettings *pSettings = settingsGetPointer();
203 if(pSettings->dive_mode == DIVEMODE_Gauge)
204 return EXIT_TO_MENU;
205 pSettings->dive_mode = DIVEMODE_Gauge;
206 setActualGasFirst(&stateRealGetPointerWrite()->lifeData);
207 tMenuEdit_set_on_off(editId, 1);
208 tMenuEdit_set_on_off(StMDECO1_CC, 0);
209 tMenuEdit_set_on_off(StMDECO1_Apnea, 0);
210 tMenuEdit_set_on_off(StMDECO1_OC, 0);
211 return UPDATE_DIVESETTINGS;
212 }
213
214
215 void openEdit_CCRModeSensorOrFixedSP(void)
216 {
217 SSettings *pSettings = settingsGetPointer();
218
219 if(pSettings->CCR_Mode == CCRMODE_Sensors)
220 pSettings->CCR_Mode = CCRMODE_FixedSetpoint;
221 else
222 pSettings->CCR_Mode = CCRMODE_Sensors;
223
224 exitEditWithUpdate();
225 }
226
227
228 void openEdit_SafetyStop(void)
229 {
230 uint32_t safetystopDuration, safetystopDepth;
231 char text[64];
232 uint16_t y_line;
233
234 safetystopDuration = settingsGetPointer()->safetystopDuration;
235 safetystopDepth = settingsGetPointer()->safetystopDepth;
236
237 y_line = ME_Y_LINE_BASE + (lineSelected * ME_Y_LINE_STEP);
238
239 text[0] = '\001';
240 text[1] = TXT_SafetyStop;
241 text[2] = 0;
242 write_topline(text);
243
244 write_label_fix( 20, 800, y_line, &FontT48, TXT_SafetyStop);
245
246 strcpy(text,"\016\016");
247 text[2] = TXT_Minutes;
248 if(settingsGetPointer()->nonMetricalSystem)
249 {
250 strcpy(&text[3],
251 "\017"
252 " @ "
253 "\016\016"
254 " ft"
255 "\017"
256 );
257 }
258 else
259 {
260 strcpy(&text[3],
261 "\017"
262 " @ "
263 "\016\016"
264 " m"
265 "\017"
266 );
267 }
268 write_label_var( 410, 800, y_line, &FontT48, text);
269
270 if(settingsGetPointer()->nonMetricalSystem)
271 {
272 write_field_2digit(StMDECO4_SafetyStop, 350, 800, y_line, &FontT48, "## ##", safetystopDuration, unit_depth_integer(safetystopDepth), 0, 0);
273 }
274 else
275 {
276 write_field_udigit(StMDECO4_SafetyStop, 370, 800, y_line, &FontT48, "# #", safetystopDuration, safetystopDepth, 0, 0);
277 }
278
279 write_buttonTextline(TXT2BYTE_ButtonMinus,TXT2BYTE_ButtonEnter,TXT2BYTE_ButtonPlus);
280
281 setEvent(StMDECO4_SafetyStop, (uint32_t)OnAction_SafetyStop);
282 startEdit();
283 }
284
285
286 uint8_t OnAction_SafetyStop (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action)
287 {
288 uint8_t digitContentNew;
289 uint32_t newSafetystopDuration, newSafetystopDepth;
290
291 if(action == ACTION_BUTTON_ENTER)
292 {
293 return digitContent;
294 }
295 if(action == ACTION_BUTTON_ENTER_FINAL)
296 {
297 evaluateNewString(editId, &newSafetystopDuration, &newSafetystopDepth, 0, 0);
298
299 if(settingsGetPointer()->nonMetricalSystem != 0) // new hw 170718
300 {
301 newSafetystopDepth += 2; // f�r rundung
302 newSafetystopDepth = (newSafetystopDepth * 3) / 10;
303 }
304
305
306 settingsGetPointer()->safetystopDuration = newSafetystopDuration;
307 settingsGetPointer()->safetystopDepth = newSafetystopDepth;
308
309 tMenuEdit_newInput(editId, newSafetystopDuration, newSafetystopDepth, 0, 0);
310 return UPDATE_AND_EXIT_TO_MENU;
311 }
312 if(action == ACTION_BUTTON_NEXT)
313 {
314 digitContentNew = digitContent + 1;
315 if(blockNumber == 0)
316 {
317 if(digitContentNew > '5')
318 digitContentNew = '0';
319 }
320 else
321 {
322 if(settingsGetPointer()->nonMetricalSystem == 0)
323 {
324 if(digitContentNew > '6')
325 digitContentNew = '3';
326 }
327 else
328 {
329 if(digitContent < 13 + '0')
330 digitContentNew = 13 + '0';
331 else if(digitContent < 16 + '0')
332 digitContentNew = 16 + '0';
333 else if(digitContent < 20 + '0')
334 digitContentNew = 20 + '0';
335 else
336 digitContentNew = 10 + '0';
337 }
338 }
339 return digitContentNew;
340 }
341 if(action == ACTION_BUTTON_BACK)
342 {
343 digitContentNew = digitContent - 1;
344 if(blockNumber == 0)
345 {
346 if(digitContentNew < '0')
347 digitContentNew = '5';
348 }
349 else
350 {
351 if(settingsGetPointer()->nonMetricalSystem == 0)
352 {
353 if(digitContentNew < '3')
354 digitContentNew = '6';
355 }
356 else
357 {
358 if(digitContent >= 20 + '0')
359 digitContentNew = 16 + '0';
360 else if(digitContent >= 16 + '0')
361 digitContentNew = 13 + '0';
362 else if(digitContent >= 13 + '0')
363 digitContentNew = 10 + '0';
364 else
365 digitContentNew = 20 + '0';
366 }
367 }
368 return digitContentNew;
369 }
370 return EXIT_TO_MENU;
371 }
372
373
374 void openEdit_Salinity(void)
375 {
376 char text[32];
377 uint16_t y_line;
378
379 text[0] = '\001';
380 text[1] = TXT_Salinity;
381 text[2] = 0;
382 write_topline(text);
383
384 y_line = ME_Y_LINE_BASE + (lineSelected * ME_Y_LINE_STEP);
385
386 write_label_fix( 30, 800, y_line, &FontT48, TXT_Salinity);
387 write_label_var( 400, 800, y_line, &FontT48, "\016\016 %\017");
388
389 write_field_udigit(StMDECO6_SALINITY, 370, 800, y_line, &FontT48, "#", (uint32_t)settingsGetPointer()->salinity, 0, 0, 0);
390
391 write_buttonTextline(TXT2BYTE_ButtonMinus,TXT2BYTE_ButtonEnter,TXT2BYTE_ButtonPlus);
392
393 setEvent(StMDECO6_SALINITY, (uint32_t)OnAction_Salinity);
394 startEdit();
395 }
396
397
398 uint8_t OnAction_Salinity(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action)
399 {
400 SSettings *pSettings;
401 uint8_t digitContentNew;
402 uint32_t salinity;
403
404 if(action == ACTION_BUTTON_ENTER)
405 {
406 return digitContent;
407 }
408 if(action == ACTION_BUTTON_ENTER_FINAL)
409 {
410 evaluateNewString(editId, &salinity, 0, 0, 0);
411
412 if(salinity >= 4)
413 salinity = 4;
414
415 pSettings = settingsGetPointer();
416
417 pSettings->salinity = salinity;
418
419 tMenuEdit_newInput(editId, salinity, 0, 0, 0);
420 return UPDATE_AND_EXIT_TO_MENU;
421 }
422 if(action == ACTION_BUTTON_NEXT)
423 {
424 digitContentNew = digitContent + 1;
425 if(digitContentNew > '4')
426 digitContentNew = '0';
427 return digitContentNew;
428 }
429 if(action == ACTION_BUTTON_BACK)
430 {
431 digitContentNew = digitContent - 1;
432 if(digitContentNew < '0')
433 digitContentNew = '4';
434 return digitContentNew;
435 }
436
437 return EXIT_TO_MENU;
438 }
439
440
441 void openEdit_ppO2max(void)
442 {
443 uint8_t maxL_std, maxL_deco;
444 uint16_t y_line;
445 char text[32];
446 SSettings *pSettings = settingsGetPointer();
447
448 maxL_std = pSettings->ppO2_max_std - 100;
449 maxL_deco = pSettings->ppO2_max_deco - 100;
450
451 y_line = ME_Y_LINE_BASE + (lineSelected * ME_Y_LINE_STEP);
452
453 text[0] = '\001';
454 text[1] = TXT_ppO2Name;
455 text[2] = 0;
456 write_topline(text);
457
458 strcpy(text,"ppO2\016\016max\017");
459 write_label_var( 20, 800, y_line, &FontT48, text);
460 strcpy(text,
461 "\016\016"
462 " bar "
463 " deco "
464 "\017"
465 " "
466 "\016\016"
467 " bar"
468 "\017"
469 );
470 write_label_var( 460, 800, y_line, &FontT48, text);
471
472 // write_field_udigit(StMDECO4_PPO2Max, 410, 800, y_line, &FontT48, "## ##", (uint32_t)maxL_std, (uint32_t)maxL_deco, 0, 0);
473 write_field_udigit(StMDECO3_PPO2Max, 370, 800, y_line, &FontT48, "1.## 1.##", (uint32_t)maxL_std, (uint32_t)maxL_deco, 0, 0);
474
475 write_buttonTextline(TXT2BYTE_ButtonMinus,TXT2BYTE_ButtonEnter,TXT2BYTE_ButtonPlus);
476
477 setEvent(StMDECO3_PPO2Max, (uint32_t)OnAction_ppO2Max);
478 startEdit();
479 }
480
481
482 uint8_t OnAction_ppO2Max(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action)
483 {
484 SSettings *pSettings;
485 uint8_t digitContentNew;
486 uint32_t newPPO2LStd, newPPO2LDeco;
487
488 if(action == ACTION_BUTTON_ENTER)
489 {
490 return digitContent;
491 }
492 if(action == ACTION_BUTTON_ENTER_FINAL)
493 {
494 evaluateNewString(editId, &newPPO2LStd, &newPPO2LDeco, 0, 0);
495
496 if(newPPO2LStd > 90)
497 newPPO2LStd = 90;
498
499 if(newPPO2LDeco > 90)
500 newPPO2LDeco = 90;
501
502 pSettings = settingsGetPointer();
503 pSettings->ppO2_max_std = 100 + newPPO2LStd;
504 pSettings->ppO2_max_deco = 100 + newPPO2LDeco;
505
506 tMenuEdit_newInput(editId, newPPO2LStd, newPPO2LDeco, 0, 0);
507 return UPDATE_AND_EXIT_TO_MENU;
508 }
509 if(action == ACTION_BUTTON_NEXT)
510 {
511 digitContentNew = digitContent + 1;
512 if(digitContentNew > '9')
513 digitContentNew = '0';
514 return digitContentNew;
515 }
516 if(action == ACTION_BUTTON_BACK)
517 {
518 digitContentNew = digitContent - 1;
519 if(digitContentNew < '0')
520 digitContentNew = '9';
521 return digitContentNew;
522 }
523 return EXIT_TO_MENU;
524 }
525
526
527 void openEdit_FutureTTS(void)
528 {
529 uint8_t futureTTS;
530 uint16_t y_line;
531
532 char text[32];
533 SSettings *pSettings = settingsGetPointer();
534 futureTTS = pSettings->future_TTS;
535
536 y_line = ME_Y_LINE_BASE + (lineSelected * ME_Y_LINE_STEP);
537
538 text[0] = '\001';
539 text[1] = TXT_FutureTTS;
540 text[2] = 0;
541 write_topline(text);
542
543 strcpy(text,"\016\016");
544 text[2] = TXT_Minutes;
545 text[3] = 0;
546 write_label_fix( 20, 800, y_line, &FontT48, TXT_FutureTTS);
547 write_label_var( 435, 800, y_line, &FontT48, text);
548 write_field_2digit(StMDECO5_FUTURE, 370, 500, y_line, &FontT48, "##", (uint32_t)futureTTS, 0, 0, 0);
549
550 write_buttonTextline(TXT2BYTE_ButtonMinus,TXT2BYTE_ButtonEnter,TXT2BYTE_ButtonPlus);
551
552 setEvent(StMDECO5_FUTURE, (uint32_t)OnAction_FutureTTS);
553 startEdit();
554 }
555
556
557 uint8_t OnAction_FutureTTS(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action)
558 {
559 SSettings *pSettings;
560 int8_t digitContentNew;
561 uint32_t newFutureTTS;
562
563 if(action == ACTION_BUTTON_ENTER)
564 {
565 return digitContent;
566 }
567 if(action == ACTION_BUTTON_ENTER_FINAL)
568 {
569 evaluateNewString(editId, &newFutureTTS, 0, 0, 0);
570
571 if(newFutureTTS > 15)
572 newFutureTTS = 15;
573
574 pSettings = settingsGetPointer();
575 pSettings->future_TTS = newFutureTTS;
576
577 tMenuEdit_newInput(editId, newFutureTTS, 0, 0, 0);
578 return UPDATE_AND_EXIT_TO_MENU;
579 }
580 if(action == ACTION_BUTTON_NEXT)
581 {
582 digitContentNew = digitContent + 1;
583 if(digitContentNew > '0'+ 15)
584 digitContentNew = '0';
585 return digitContentNew;
586 }
587 if(action == ACTION_BUTTON_BACK)
588 {
589 digitContentNew = digitContent - 1;
590 if(digitContentNew < '0')
591 digitContentNew = '0' + 15;
592 return digitContentNew;
593 }
594 /*
595 if(action == ACTION_BUTTON_NEXT)
596 {
597 digitContentNew = digitContent + 1;
598 if((digitNumber == 0) && (digitContentNew > '1'))
599 digitContentNew = '0';
600 else
601 if(digitContentNew > '9')
602 digitContentNew = '0';
603 return digitContentNew;
604 }
605 if(action == ACTION_BUTTON_BACK)
606 {
607 digitContentNew = digitContent - 1;
608 if((digitNumber == 0) && (digitContentNew < '0'))
609 digitContentNew = '1';
610 else
611 if(digitContentNew < '0')
612 digitContentNew = '9';
613 return digitContentNew;
614 }
615 */
616 return EXIT_TO_MENU;
617 }
618
619