Mercurial > public > ostc4
annotate Discovery/Src/tMenuEditSetpoint.c @ 185:1bb24fd3fc92
Merged in Ideenmodellierer/ostc4/Cleanup_Compass_Wireless (pull request #4)
Cleanup Compass Wireless
author | heinrichsweikamp <bitbucket@heinrichsweikamp.com> |
---|---|
date | Fri, 15 Mar 2019 08:22:16 +0000 |
parents | 255eedad4155 |
children | d539ed9aa5b8 |
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, | |
166
255eedad4155
cleanup: get rid of some compile warnings
Jan Mulder <jlmulder@xs4all.nl>
parents:
130
diff
changeset
|
183 char text[70]; |
255eedad4155
cleanup: get rid of some compile warnings
Jan Mulder <jlmulder@xs4all.nl>
parents:
130
diff
changeset
|
184 uint8_t textPointer; |
38 | 185 uint16_t y_line; |
186 | |
187 set_globalState_Menu_Line(line); | |
188 | |
189 resetMenuEdit(CLUT_MenuPageGasSP); | |
190 | |
191 spId = line; | |
192 editSetpointPage.spID = spId; | |
193 SSettings *data = settingsGetPointer(); | |
194 editSetpointPage.pSetpointLine = data->setpoint; | |
195 | |
196 setpoint_cbar = editSetpointPage.pSetpointLine[spId].setpoint_cbar; | |
197 depthDeco = editSetpointPage.pSetpointLine[spId].depth_meter; | |
198 //active = editSetpointPage.pSetpointLine[spId].note.ub.active; | |
199 first = editSetpointPage.pSetpointLine[spId].note.ub.first; | |
200 | |
201 sp_high = setpoint_cbar / 100; | |
202 | |
203 strcpy(text, "\001" "Setpoint #0 X"); | |
204 text[11] += spId; | |
205 text[13] = TXT_Setpoint_Edit; | |
206 write_topline(text); | |
207 | |
208 | |
209 y_line = ME_Y_LINE_BASE + (line * ME_Y_LINE_STEP); | |
210 | |
211 textPointer = 0; | |
212 text[textPointer++] = 'S'; | |
213 text[textPointer++] = 'P'; | |
214 text[textPointer++] = '0' + spId; | |
215 text[textPointer++] = ' '; | |
216 text[textPointer++] = ' '; | |
217 | |
218 if(first == 0) | |
219 strcpy(&text[textPointer++],"\177"); | |
220 | |
221 textPointer += snprintf(&text[textPointer], 60,\ | |
222 "* " | |
223 " " | |
224 "\016\016" | |
225 " bar" | |
226 "\017" | |
227 "\034" | |
228 " " | |
229 "\016\016" | |
230 " " | |
231 "\017" | |
232 " " | |
233 "\016\016" | |
234 "meter" | |
235 "\017" | |
236 "\035" | |
237 "\n\r" | |
238 ); | |
239 write_label_var( 20, 800, y_line, &FontT48, text); | |
240 | |
241 write_field_udigit(StMSP_ppo2_setting, 160, 800, y_line, &FontT48, "#.## ###", (uint32_t)sp_high, (uint32_t)(setpoint_cbar - (100 * sp_high)), depthDeco, 0); | |
242 setEvent(StMSP_ppo2_setting, (uint32_t)OnAction_SP_Setpoint); | |
243 startEdit(); | |
244 } | |
245 } | |
246 | |
247 uint8_t OnAction_SP_Setpoint(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action) | |
248 { | |
249 int8_t digitContentNew; | |
250 uint32_t new_integer_part, new_fractional_part, new_cbar, newDepth; | |
251 | |
252 if(action == ACTION_BUTTON_ENTER) | |
253 return digitContent; | |
254 | |
255 if(action == ACTION_BUTTON_ENTER_FINAL) | |
256 { | |
257 evaluateNewString(editId, &new_integer_part, &new_fractional_part, &newDepth, 0); | |
258 | |
259 new_cbar = (new_integer_part * 100) + new_fractional_part; | |
260 | |
261 if(new_cbar < 50) | |
262 new_cbar = 50; | |
263 | |
264 if(new_cbar > 160) | |
265 new_cbar = 160; | |
266 | |
267 new_integer_part = new_cbar / 100; | |
268 new_fractional_part = new_cbar - (new_integer_part * 100); | |
269 | |
270 editSetpointPage.pSetpointLine[editSetpointPage.spID].setpoint_cbar = new_cbar; | |
271 | |
272 if(newDepth > 255) | |
273 newDepth = 255; | |
274 | |
275 editSetpointPage.pSetpointLine[editSetpointPage.spID].depth_meter = newDepth; | |
276 | |
277 return UPDATE_AND_EXIT_TO_MENU; | |
278 } | |
279 | |
280 if(action == ACTION_BUTTON_NEXT) | |
281 { | |
282 digitContentNew = digitContent + 1; | |
283 if((blockNumber == 0) && (digitContentNew > '1')) | |
284 digitContentNew = '0'; | |
285 if(digitContentNew > '9') | |
286 digitContentNew = '0'; | |
287 return digitContentNew; | |
288 } | |
289 | |
290 if(action == ACTION_BUTTON_BACK) | |
291 { | |
292 digitContentNew = digitContent - 1; | |
293 if((blockNumber == 0) && (digitContentNew > '1')) | |
294 digitContentNew = '1'; | |
295 if(digitContentNew < '0') | |
296 digitContentNew = '9'; | |
297 return digitContentNew; | |
298 } | |
299 | |
300 return EXIT_TO_MENU; | |
301 } | |
302 | |
303 uint8_t OnAction_SP_Depth(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action) | |
304 { | |
305 uint8_t digitContentNew; | |
306 uint32_t newDepth; | |
307 | |
308 if(action == ACTION_BUTTON_ENTER) | |
309 { | |
310 return digitContent; | |
311 } | |
312 if(action == ACTION_BUTTON_ENTER_FINAL) | |
313 { | |
314 evaluateNewString(editId, &newDepth, 0, 0, 0); | |
315 if(newDepth > 255) | |
316 newDepth = 255; | |
317 | |
318 editSetpointPage.pSetpointLine[editSetpointPage.spID].depth_meter = newDepth; | |
319 | |
320 tMenuEdit_newInput(editId, newDepth, 0, 0, 0); | |
321 return UPDATE_DIVESETTINGS; | |
322 } | |
323 if(action == ACTION_BUTTON_NEXT) | |
324 { | |
325 digitContentNew = digitContent + 1; | |
326 if(digitContentNew > '9') | |
327 digitContentNew = '0'; | |
328 return digitContentNew; | |
329 } | |
330 if(action == ACTION_BUTTON_BACK) | |
331 { | |
332 digitContentNew = digitContent - 1; | |
333 if(digitContentNew < '0') | |
334 digitContentNew = '9'; | |
335 return digitContentNew; | |
336 } | |
337 | |
338 return UNSPECIFIC_RETURN; | |
339 } | |
340 | |
341 void openEdit_DiveSelectBetterSetpoint(void) | |
342 { | |
343 uint8_t spId; | |
344 SDiveState *pState; | |
345 uint8_t depth; | |
346 | |
347 spId = actualBetterSetpointId(); | |
348 | |
349 if(actual_menu_content == MENU_DIVE_REAL) | |
350 pState = stateRealGetPointerWrite(); | |
351 else | |
352 pState = stateSimGetPointerWrite(); | |
353 | |
354 depth = pState->diveSettings.setpoint[spId].depth_meter; | |
355 | |
356 // BetterSetpoint warning only once -> clear active | |
357 for(int i=0; i<=NUM_GASES; i++) | |
358 { | |
359 pState->diveSettings.setpoint[i].note.ub.first = 0; | |
360 if(pState->diveSettings.setpoint[i].depth_meter <= depth) | |
361 pState->diveSettings.setpoint[i].note.ub.active = 0; | |
362 } | |
363 | |
364 // new setpoint | |
365 pState->diveSettings.setpoint[spId].note.ub.first = 1; | |
366 | |
367 // change in lifeData | |
368 setActualGas_DM(&pState->lifeData, pState->lifeData.actualGas.GasIdInSettings, pState->diveSettings.setpoint[spId].setpoint_cbar); | |
369 } | |
370 | |
371 uint8_t OnAction_SP_DM_Sensor1 (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action) | |
372 { | |
373 SDiveState * pDiveState = 0; | |
374 | |
375 if(actual_menu_content == MENU_DIVE_REAL) | |
376 pDiveState = stateRealGetPointerWrite(); | |
377 else | |
378 pDiveState = stateSimGetPointerWrite(); | |
379 | |
380 if(pDiveState->diveSettings.ppo2sensors_deactivated & 1) | |
381 { | |
382 pDiveState->diveSettings.ppo2sensors_deactivated &= 4+2; | |
383 tMenuEdit_set_on_off(editId, 1); | |
384 } | |
385 else | |
386 { | |
387 pDiveState->diveSettings.ppo2sensors_deactivated |= 1; | |
388 tMenuEdit_set_on_off(editId, 0); | |
389 } | |
390 | |
391 return UNSPECIFIC_RETURN; | |
392 } | |
393 | |
394 uint8_t OnAction_SP_DM_Sensor2 (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action) | |
395 { | |
396 SDiveState * pDiveState = 0; | |
397 | |
398 if(actual_menu_content == MENU_DIVE_REAL) | |
399 pDiveState = stateRealGetPointerWrite(); | |
400 else | |
401 pDiveState = stateSimGetPointerWrite(); | |
402 | |
403 if(pDiveState->diveSettings.ppo2sensors_deactivated & 2) | |
404 { | |
405 pDiveState->diveSettings.ppo2sensors_deactivated &= 4+1; | |
406 tMenuEdit_set_on_off(editId, 1); | |
407 } | |
408 else | |
409 { | |
410 pDiveState->diveSettings.ppo2sensors_deactivated |= 2; | |
411 tMenuEdit_set_on_off(editId, 0); | |
412 } | |
413 | |
414 return UNSPECIFIC_RETURN; | |
415 } | |
416 | |
417 uint8_t OnAction_SP_DM_Sensor3 (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action) | |
418 { | |
419 SDiveState * pDiveState = 0; | |
420 | |
421 if(actual_menu_content == MENU_DIVE_REAL) | |
422 pDiveState = stateRealGetPointerWrite(); | |
423 else | |
424 pDiveState = stateSimGetPointerWrite(); | |
425 | |
426 if(pDiveState->diveSettings.ppo2sensors_deactivated & 4) | |
427 { | |
428 pDiveState->diveSettings.ppo2sensors_deactivated &= 2+1; | |
429 tMenuEdit_set_on_off(editId, 1); | |
430 } | |
431 else | |
432 { | |
433 pDiveState->diveSettings.ppo2sensors_deactivated |= 4; | |
434 tMenuEdit_set_on_off(editId, 0); | |
435 } | |
436 return UNSPECIFIC_RETURN; | |
437 } | |
438 | |
439 /* Private functions ---------------------------------------------------------*/ | |
440 | |
441 /* | |
442 uint8_t OnAction_SP_Active(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action) | |
443 { | |
444 uint8_t active, first; | |
445 | |
446 first = editSetpointPage.pSetpointLine[editSetpointPage.spID].note.ub.first; | |
447 | |
448 if(first) | |
449 return UNSPECIFIC_RETURN; | |
450 | |
451 active = editSetpointPage.pSetpointLine[editSetpointPage.spID].note.ub.active; | |
452 | |
453 if(active) | |
454 { | |
455 active = 0; | |
456 editSetpointPage.pSetpointLine[editSetpointPage.spID].note.ub.active = 0; | |
457 } | |
458 else | |
459 { | |
460 active = 1; | |
461 editSetpointPage.pSetpointLine[editSetpointPage.spID].note.ub.active = 1; | |
462 } | |
463 tMenuEdit_set_on_off(editId, active); | |
464 | |
465 return UPDATE_DIVESETTINGS; | |
466 } | |
467 | |
468 uint8_t OnAction_SP_First(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action) | |
469 { | |
470 uint8_t active, first, i; | |
471 SDiveState * pStateReal = stateRealGetPointerWrite(); | |
472 | |
473 first = editSetpointPage.pSetpointLine[editSetpointPage.spID].note.ub.first; | |
474 | |
475 if(first) | |
476 return UNSPECIFIC_RETURN; | |
477 | |
478 for(i=0;i<NUM_GASES;i++) | |
479 editSetpointPage.pSetpointLine[i].note.ub.first = 0; | |
480 | |
481 editSetpointPage.pSetpointLine[editSetpointPage.spID].note.ub.first = 1; | |
482 | |
483 active = editSetpointPage.pSetpointLine[editSetpointPage.spID].note.ub.active; | |
484 if(active == 0) | |
485 { | |
486 editSetpointPage.pSetpointLine[editSetpointPage.spID].note.ub.active = 1; | |
487 } | |
488 | |
489 tMenuEdit_set_on_off(editId, 1); | |
490 | |
491 return UPDATE_DIVESETTINGS; | |
492 } | |
493 | |
494 uint8_t OnAction_SP_DM_Select(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action) | |
495 { | |
496 SDiveState * pDiveState = 0; | |
497 | |
498 if(editSetpointPage.pSetpointLine[editSetpointPage.spID].note.ub.active == 0) | |
499 editSetpointPage.pSetpointLine[editSetpointPage.spID].note.ub.active = 1; | |
500 | |
501 for(int i=0;i<NUM_GASES;i++) | |
502 editSetpointPage.pSetpointLine[i].note.ub.first = 0; | |
503 | |
504 editSetpointPage.pSetpointLine[editSetpointPage.spID].note.ub.first = 1; | |
505 | |
506 if(actual_menu_content == MENU_DIVE_REAL) | |
507 pDiveState = stateRealGetPointerWrite(); | |
508 else | |
509 pDiveState = stateSimGetPointerWrite(); | |
510 | |
511 setActualGas_DM(&pDiveState->lifeData, pDiveState->lifeData.actualGas.GasIdInSettings, editSetpointPage.pSetpointLine[editSetpointPage.spID].setpoint_cbar); | |
512 | |
513 return EXIT_TO_HOME; | |
514 } | |
515 */ |