comparison Discovery/Src/tMenuEditSetpoint.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/tMenuEditSetpoint.c
5 /// \brief
6 /// \author heinrichs weikamp gmbh
7 /// \date 19-Dec-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 "tMenuEditSetpoint.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 spID;
41 SSetpointLine * pSetpointLine;
42 } SEditSetpointPage;
43
44
45 /* Private variables ---------------------------------------------------------*/
46 SEditSetpointPage editSetpointPage;
47
48 /* Private function prototypes -----------------------------------------------*/
49
50 void openEdit_DiveSetpointSelect(uint8_t line);
51 void openEdit_DiveSetpointSelect_Subroutine(uint8_t line);
52
53 /* Announced function prototypes -----------------------------------------------*/
54 uint8_t OnAction_SP_Setpoint (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action);
55 uint8_t OnAction_SP_Depth (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action);
56 uint8_t On (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action);
57 //uint8_t OnAction_SP_First (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action);
58 //uint8_t OnAction_SP_Active (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action);
59 //uint8_t OnAction_SP_DM_Select (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action);
60 uint8_t OnAction_SP_DM_Sensor1 (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action);
61 uint8_t OnAction_SP_DM_Sensor2 (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action);
62 uint8_t OnAction_SP_DM_Sensor3 (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action);
63
64 /* Exported functions --------------------------------------------------------*/
65
66 void openEdit_Setpoint(uint8_t line)
67 {
68 uint8_t useSensorSubMenu = 0;
69
70 /* dive mode */
71 if(actual_menu_content != MENU_SURFACE)
72 {
73 uint8_t setpointCbar, actualGasID;
74 SDiveState *pState;
75
76 if(actual_menu_content == MENU_DIVE_REAL)
77 pState = stateRealGetPointerWrite();
78 else
79 pState = stateSimGetPointerWrite();
80
81 // actualGasID
82 if(pState->diveSettings.diveMode != DIVEMODE_CCR)
83 {
84 actualGasID = pState->lifeData.lastDiluent_GasIdInSettings;
85 if((actualGasID <= NUM_OFFSET_DILUENT) || (actualGasID > NUM_GASES + NUM_OFFSET_DILUENT))
86 actualGasID = NUM_OFFSET_DILUENT + 1;
87 }
88 else
89 actualGasID = pState->lifeData.actualGas.GasIdInSettings;
90
91 // setpointCbar, CCR_Mode and sensor menu
92 if(line < 6)
93 {
94 setpointCbar = pState->diveSettings.setpoint[line].setpoint_cbar;
95 pState->diveSettings.CCR_Mode = CCRMODE_FixedSetpoint;
96
97 // BetterSetpoint warning only once
98 if(actualBetterSetpointId() == line)
99 {
100 uint8_t depth;
101 depth = pState->diveSettings.setpoint[line].depth_meter;
102 // BetterSetpoint warning only once -> clear active
103 for(int i=0; i<=NUM_GASES; i++)
104 {
105 pState->diveSettings.setpoint[i].note.ub.first = 0;
106 if(pState->diveSettings.setpoint[i].depth_meter <= depth)
107 pState->diveSettings.setpoint[i].note.ub.active = 0;
108 }
109 pState->diveSettings.setpoint[line].note.ub.first = 1;
110 }
111 }
112 else
113 {
114 if(pState->diveSettings.CCR_Mode != CCRMODE_Sensors)
115 {
116 /* setpoint_cbar will be written by updateSetpointStateUsed() in main.c loop */
117 setpointCbar = 255;
118 pState->diveSettings.CCR_Mode = CCRMODE_Sensors;
119 }
120 else
121 {
122 useSensorSubMenu = 1;
123 }
124 }
125
126 setActualGas_DM(&pState->lifeData,actualGasID,setpointCbar);
127
128 if(pState->diveSettings.diveMode != DIVEMODE_CCR)
129 {
130 pState->diveSettings.diveMode = DIVEMODE_CCR;
131 unblock_diluent_page();
132 }
133
134 clear_warning_fallback();
135
136 if(!useSensorSubMenu)
137 {
138 exitMenuEdit_to_Home();
139 }
140 else // entire sub menu during dive to select sensors active
141 {
142 set_globalState_Menu_Line(line);
143 resetMenuEdit(CLUT_MenuPageGasSP);
144
145 char text[3];
146 uint8_t sensorActive[3];
147
148 text[0] = '\001';
149 text[1] = TXT_o2Sensors;
150 text[2] = 0;
151 write_topline(text);
152
153 write_label_var( 96, 340, ME_Y_LINE1, &FontT48, "Sensor 1");
154 write_label_var( 96, 340, ME_Y_LINE2, &FontT48, "Sensor 2");
155 write_label_var( 96, 340, ME_Y_LINE3, &FontT48, "Sensor 3");
156
157 sensorActive[0] = 1;
158 sensorActive[1] = 1;
159 sensorActive[2] = 1;
160 if(pState->diveSettings.ppo2sensors_deactivated & 1)
161 sensorActive[0] = 0;
162 if(pState->diveSettings.ppo2sensors_deactivated & 2)
163 sensorActive[1] = 0;
164 if(pState->diveSettings.ppo2sensors_deactivated & 4)
165 sensorActive[2] = 0;
166
167 write_field_on_off(StMSP_Sensor1, 30, 95, ME_Y_LINE1, &FontT48, "", sensorActive[0]);
168 write_field_on_off(StMSP_Sensor2, 30, 95, ME_Y_LINE2, &FontT48, "", sensorActive[1]);
169 write_field_on_off(StMSP_Sensor3, 30, 95, ME_Y_LINE3, &FontT48, "", sensorActive[2]);
170
171 setEvent(StMSP_Sensor1, (uint32_t)OnAction_SP_DM_Sensor1);
172 setEvent(StMSP_Sensor2, (uint32_t)OnAction_SP_DM_Sensor2);
173 setEvent(StMSP_Sensor3, (uint32_t)OnAction_SP_DM_Sensor3);
174 }
175 return;
176 }
177 else
178 {
179 /* surface mode */
180 uint8_t spId, setpoint_cbar, sp_high, depthDeco, first;
181 // uint8_t active,
182 char text[70], textPointer;
183 uint16_t y_line;
184
185 set_globalState_Menu_Line(line);
186
187 resetMenuEdit(CLUT_MenuPageGasSP);
188
189 spId = line;
190 editSetpointPage.spID = spId;
191 SSettings *data = settingsGetPointer();
192 editSetpointPage.pSetpointLine = data->setpoint;
193
194 setpoint_cbar = editSetpointPage.pSetpointLine[spId].setpoint_cbar;
195 depthDeco = editSetpointPage.pSetpointLine[spId].depth_meter;
196 //active = editSetpointPage.pSetpointLine[spId].note.ub.active;
197 first = editSetpointPage.pSetpointLine[spId].note.ub.first;
198
199 sp_high = setpoint_cbar / 100;
200
201 strcpy(text, "\001" "Setpoint #0 X");
202 text[11] += spId;
203 text[13] = TXT_Setpoint_Edit;
204 write_topline(text);
205
206
207 y_line = ME_Y_LINE_BASE + (line * ME_Y_LINE_STEP);
208
209 textPointer = 0;
210 text[textPointer++] = 'S';
211 text[textPointer++] = 'P';
212 text[textPointer++] = '0' + spId;
213 text[textPointer++] = ' ';
214 text[textPointer++] = ' ';
215
216 if(first == 0)
217 strcpy(&text[textPointer++],"\177");
218
219 textPointer += snprintf(&text[textPointer], 60,\
220 "* "
221 " "
222 "\016\016"
223 " bar"
224 "\017"
225 "\034"
226 " "
227 "\016\016"
228 " "
229 "\017"
230 " "
231 "\016\016"
232 "meter"
233 "\017"
234 "\035"
235 "\n\r"
236 );
237 write_label_var( 20, 800, y_line, &FontT48, text);
238
239 write_field_udigit(StMSP_ppo2_setting, 160, 800, y_line, &FontT48, "#.## ###", (uint32_t)sp_high, (uint32_t)(setpoint_cbar - (100 * sp_high)), depthDeco, 0);
240 setEvent(StMSP_ppo2_setting, (uint32_t)OnAction_SP_Setpoint);
241 startEdit();
242 }
243 }
244
245 uint8_t OnAction_SP_Setpoint(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action)
246 {
247 int8_t digitContentNew;
248 uint32_t new_integer_part, new_fractional_part, new_cbar, newDepth;
249
250 if(action == ACTION_BUTTON_ENTER)
251 return digitContent;
252
253 if(action == ACTION_BUTTON_ENTER_FINAL)
254 {
255 evaluateNewString(editId, &new_integer_part, &new_fractional_part, &newDepth, 0);
256
257 new_cbar = (new_integer_part * 100) + new_fractional_part;
258
259 if(new_cbar < 50)
260 new_cbar = 50;
261
262 if(new_cbar > 160)
263 new_cbar = 160;
264
265 new_integer_part = new_cbar / 100;
266 new_fractional_part = new_cbar - (new_integer_part * 100);
267
268 editSetpointPage.pSetpointLine[editSetpointPage.spID].setpoint_cbar = new_cbar;
269
270 if(newDepth > 255)
271 newDepth = 255;
272
273 editSetpointPage.pSetpointLine[editSetpointPage.spID].depth_meter = newDepth;
274
275 return UPDATE_AND_EXIT_TO_MENU;
276 }
277
278 if(action == ACTION_BUTTON_NEXT)
279 {
280 digitContentNew = digitContent + 1;
281 if((blockNumber == 0) && (digitContentNew > '1'))
282 digitContentNew = '0';
283 if(digitContentNew > '9')
284 digitContentNew = '0';
285 return digitContentNew;
286 }
287
288 if(action == ACTION_BUTTON_BACK)
289 {
290 digitContentNew = digitContent - 1;
291 if((blockNumber == 0) && (digitContentNew > '1'))
292 digitContentNew = '1';
293 if(digitContentNew < '0')
294 digitContentNew = '9';
295 return digitContentNew;
296 }
297
298 return EXIT_TO_MENU;
299 }
300
301 uint8_t OnAction_SP_Depth(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action)
302 {
303 uint8_t digitContentNew;
304 uint32_t newDepth;
305
306 if(action == ACTION_BUTTON_ENTER)
307 {
308 return digitContent;
309 }
310 if(action == ACTION_BUTTON_ENTER_FINAL)
311 {
312 evaluateNewString(editId, &newDepth, 0, 0, 0);
313 if(newDepth > 255)
314 newDepth = 255;
315
316 editSetpointPage.pSetpointLine[editSetpointPage.spID].depth_meter = newDepth;
317
318 tMenuEdit_newInput(editId, newDepth, 0, 0, 0);
319 return UPDATE_DIVESETTINGS;
320 }
321 if(action == ACTION_BUTTON_NEXT)
322 {
323 digitContentNew = digitContent + 1;
324 if(digitContentNew > '9')
325 digitContentNew = '0';
326 return digitContentNew;
327 }
328 if(action == ACTION_BUTTON_BACK)
329 {
330 digitContentNew = digitContent - 1;
331 if(digitContentNew < '0')
332 digitContentNew = '9';
333 return digitContentNew;
334 }
335
336 return UNSPECIFIC_RETURN;
337 }
338
339 void openEdit_DiveSelectBetterSetpoint(void)
340 {
341 uint8_t spId;
342 SDiveState *pState;
343 uint8_t depth;
344
345 spId = actualBetterSetpointId();
346
347 if(actual_menu_content == MENU_DIVE_REAL)
348 pState = stateRealGetPointerWrite();
349 else
350 pState = stateSimGetPointerWrite();
351
352 depth = pState->diveSettings.setpoint[spId].depth_meter;
353
354 // BetterSetpoint warning only once -> clear active
355 for(int i=0; i<=NUM_GASES; i++)
356 {
357 pState->diveSettings.setpoint[i].note.ub.first = 0;
358 if(pState->diveSettings.setpoint[i].depth_meter <= depth)
359 pState->diveSettings.setpoint[i].note.ub.active = 0;
360 }
361
362 // new setpoint
363 pState->diveSettings.setpoint[spId].note.ub.first = 1;
364
365 // change in lifeData
366 setActualGas_DM(&pState->lifeData, pState->lifeData.actualGas.GasIdInSettings, pState->diveSettings.setpoint[spId].setpoint_cbar);
367 }
368
369 uint8_t OnAction_SP_DM_Sensor1 (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action)
370 {
371 SDiveState * pDiveState = 0;
372
373 if(actual_menu_content == MENU_DIVE_REAL)
374 pDiveState = stateRealGetPointerWrite();
375 else
376 pDiveState = stateSimGetPointerWrite();
377
378 if(pDiveState->diveSettings.ppo2sensors_deactivated & 1)
379 {
380 pDiveState->diveSettings.ppo2sensors_deactivated &= 4+2;
381 tMenuEdit_set_on_off(editId, 1);
382 }
383 else
384 {
385 pDiveState->diveSettings.ppo2sensors_deactivated |= 1;
386 tMenuEdit_set_on_off(editId, 0);
387 }
388
389 return UNSPECIFIC_RETURN;
390 }
391
392 uint8_t OnAction_SP_DM_Sensor2 (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action)
393 {
394 SDiveState * pDiveState = 0;
395
396 if(actual_menu_content == MENU_DIVE_REAL)
397 pDiveState = stateRealGetPointerWrite();
398 else
399 pDiveState = stateSimGetPointerWrite();
400
401 if(pDiveState->diveSettings.ppo2sensors_deactivated & 2)
402 {
403 pDiveState->diveSettings.ppo2sensors_deactivated &= 4+1;
404 tMenuEdit_set_on_off(editId, 1);
405 }
406 else
407 {
408 pDiveState->diveSettings.ppo2sensors_deactivated |= 2;
409 tMenuEdit_set_on_off(editId, 0);
410 }
411
412 return UNSPECIFIC_RETURN;
413 }
414
415 uint8_t OnAction_SP_DM_Sensor3 (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action)
416 {
417 SDiveState * pDiveState = 0;
418
419 if(actual_menu_content == MENU_DIVE_REAL)
420 pDiveState = stateRealGetPointerWrite();
421 else
422 pDiveState = stateSimGetPointerWrite();
423
424 if(pDiveState->diveSettings.ppo2sensors_deactivated & 4)
425 {
426 pDiveState->diveSettings.ppo2sensors_deactivated &= 2+1;
427 tMenuEdit_set_on_off(editId, 1);
428 }
429 else
430 {
431 pDiveState->diveSettings.ppo2sensors_deactivated |= 4;
432 tMenuEdit_set_on_off(editId, 0);
433 }
434 return UNSPECIFIC_RETURN;
435 }
436
437 /* Private functions ---------------------------------------------------------*/
438
439 /*
440 uint8_t OnAction_SP_Active(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action)
441 {
442 uint8_t active, first;
443
444 first = editSetpointPage.pSetpointLine[editSetpointPage.spID].note.ub.first;
445
446 if(first)
447 return UNSPECIFIC_RETURN;
448
449 active = editSetpointPage.pSetpointLine[editSetpointPage.spID].note.ub.active;
450
451 if(active)
452 {
453 active = 0;
454 editSetpointPage.pSetpointLine[editSetpointPage.spID].note.ub.active = 0;
455 }
456 else
457 {
458 active = 1;
459 editSetpointPage.pSetpointLine[editSetpointPage.spID].note.ub.active = 1;
460 }
461 tMenuEdit_set_on_off(editId, active);
462
463 return UPDATE_DIVESETTINGS;
464 }
465
466 uint8_t OnAction_SP_First(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action)
467 {
468 uint8_t active, first, i;
469 SDiveState * pStateReal = stateRealGetPointerWrite();
470
471 first = editSetpointPage.pSetpointLine[editSetpointPage.spID].note.ub.first;
472
473 if(first)
474 return UNSPECIFIC_RETURN;
475
476 for(i=0;i<NUM_GASES;i++)
477 editSetpointPage.pSetpointLine[i].note.ub.first = 0;
478
479 editSetpointPage.pSetpointLine[editSetpointPage.spID].note.ub.first = 1;
480
481 active = editSetpointPage.pSetpointLine[editSetpointPage.spID].note.ub.active;
482 if(active == 0)
483 {
484 editSetpointPage.pSetpointLine[editSetpointPage.spID].note.ub.active = 1;
485 }
486
487 tMenuEdit_set_on_off(editId, 1);
488
489 return UPDATE_DIVESETTINGS;
490 }
491
492 uint8_t OnAction_SP_DM_Select(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action)
493 {
494 SDiveState * pDiveState = 0;
495
496 if(editSetpointPage.pSetpointLine[editSetpointPage.spID].note.ub.active == 0)
497 editSetpointPage.pSetpointLine[editSetpointPage.spID].note.ub.active = 1;
498
499 for(int i=0;i<NUM_GASES;i++)
500 editSetpointPage.pSetpointLine[i].note.ub.first = 0;
501
502 editSetpointPage.pSetpointLine[editSetpointPage.spID].note.ub.first = 1;
503
504 if(actual_menu_content == MENU_DIVE_REAL)
505 pDiveState = stateRealGetPointerWrite();
506 else
507 pDiveState = stateSimGetPointerWrite();
508
509 setActualGas_DM(&pDiveState->lifeData, pDiveState->lifeData.actualGas.GasIdInSettings, editSetpointPage.pSetpointLine[editSetpointPage.spID].setpoint_cbar);
510
511 return EXIT_TO_HOME;
512 }
513 */