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