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