comparison Discovery/Src/tMenuEditSetpoint.c @ 288:ba229a012ac7 div-fixes-6

cleanup: no useless checks for simulator state and some more in the style of commit 74a8296a2318. And in addition more cleanup like removing commented and unused code, and making things static. Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
author Jan Mulder <jlmulder@xs4all.nl>
date Mon, 29 Apr 2019 19:43:05 +0200
parents d539ed9aa5b8
children 4532953ac1a0
comparison
equal deleted inserted replaced
287:ba9d99a2e310 288:ba229a012ac7
41 SSetpointLine * pSetpointLine; 41 SSetpointLine * pSetpointLine;
42 } SEditSetpointPage; 42 } SEditSetpointPage;
43 43
44 44
45 /* Private variables ---------------------------------------------------------*/ 45 /* Private variables ---------------------------------------------------------*/
46 SEditSetpointPage editSetpointPage; 46 static SEditSetpointPage editSetpointPage;
47 47
48 /* Private function prototypes -----------------------------------------------*/ 48 /* Private function prototypes -----------------------------------------------*/
49 49
50
51 /* Announced function prototypes -----------------------------------------------*/ 50 /* Announced function prototypes -----------------------------------------------*/
52 uint8_t OnAction_SP_Setpoint (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action); 51 static 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); 52 static uint8_t OnAction_SP_DM_Sensor1 (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); 53 static uint8_t OnAction_SP_DM_Sensor2 (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); 54 static uint8_t OnAction_SP_DM_Sensor3 (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 55
61 /* Exported functions --------------------------------------------------------*/ 56 /* Exported functions --------------------------------------------------------*/
62 57
63 void openEdit_Setpoint(uint8_t line) 58 void openEdit_Setpoint(uint8_t line)
64 { 59 {
66 61
67 /* dive mode */ 62 /* dive mode */
68 if(actual_menu_content != MENU_SURFACE) 63 if(actual_menu_content != MENU_SURFACE)
69 { 64 {
70 uint8_t setpointCbar, actualGasID; 65 uint8_t setpointCbar, actualGasID;
71 SDiveState *pState;
72 setpointCbar = 100; 66 setpointCbar = 100;
73 67
74 if(actual_menu_content == MENU_DIVE_REAL)
75 pState = stateRealGetPointerWrite();
76 else
77 pState = stateSimGetPointerWrite();
78
79 // actualGasID 68 // actualGasID
80 if(pState->diveSettings.diveMode != DIVEMODE_CCR) 69 if(stateUsedWrite->diveSettings.diveMode != DIVEMODE_CCR)
81 { 70 {
82 actualGasID = pState->lifeData.lastDiluent_GasIdInSettings; 71 actualGasID = stateUsedWrite->lifeData.lastDiluent_GasIdInSettings;
83 if((actualGasID <= NUM_OFFSET_DILUENT) || (actualGasID > NUM_GASES + NUM_OFFSET_DILUENT)) 72 if((actualGasID <= NUM_OFFSET_DILUENT) || (actualGasID > NUM_GASES + NUM_OFFSET_DILUENT))
84 actualGasID = NUM_OFFSET_DILUENT + 1; 73 actualGasID = NUM_OFFSET_DILUENT + 1;
85 } 74 }
86 else 75 else
87 actualGasID = pState->lifeData.actualGas.GasIdInSettings; 76 actualGasID = stateUsedWrite->lifeData.actualGas.GasIdInSettings;
88 77
89 // setpointCbar, CCR_Mode and sensor menu 78 // setpointCbar, CCR_Mode and sensor menu
90 if(line < 6) 79 if(line < 6)
91 { 80 {
92 setpointCbar = pState->diveSettings.setpoint[line].setpoint_cbar; 81 setpointCbar = stateUsedWrite->diveSettings.setpoint[line].setpoint_cbar;
93 pState->diveSettings.CCR_Mode = CCRMODE_FixedSetpoint; 82 stateUsedWrite->diveSettings.CCR_Mode = CCRMODE_FixedSetpoint;
94 83
95 // BetterSetpoint warning only once 84 // BetterSetpoint warning only once
96 if(actualBetterSetpointId() == line) 85 if(actualBetterSetpointId() == line)
97 { 86 {
98 uint8_t depth; 87 uint8_t depth;
99 depth = pState->diveSettings.setpoint[line].depth_meter; 88 depth = stateUsedWrite->diveSettings.setpoint[line].depth_meter;
100 // BetterSetpoint warning only once -> clear active 89 // BetterSetpoint warning only once -> clear active
101 for(int i=0; i<=NUM_GASES; i++) 90 for(int i=0; i<=NUM_GASES; i++)
102 { 91 {
103 pState->diveSettings.setpoint[i].note.ub.first = 0; 92 stateUsedWrite->diveSettings.setpoint[i].note.ub.first = 0;
104 if(pState->diveSettings.setpoint[i].depth_meter <= depth) 93 if(stateUsedWrite->diveSettings.setpoint[i].depth_meter <= depth)
105 pState->diveSettings.setpoint[i].note.ub.active = 0; 94 stateUsedWrite->diveSettings.setpoint[i].note.ub.active = 0;
106 } 95 }
107 pState->diveSettings.setpoint[line].note.ub.first = 1; 96 stateUsedWrite->diveSettings.setpoint[line].note.ub.first = 1;
108 } 97 }
109 } 98 }
110 else 99 else
111 { 100 {
112 if(pState->diveSettings.CCR_Mode != CCRMODE_Sensors) 101 if(stateUsedWrite->diveSettings.CCR_Mode != CCRMODE_Sensors)
113 { 102 {
114 /* setpoint_cbar will be written by updateSetpointStateUsed() in main.c loop */ 103 /* setpoint_cbar will be written by updateSetpointStateUsed() in main.c loop */
115 setpointCbar = 255; 104 setpointCbar = 255;
116 pState->diveSettings.CCR_Mode = CCRMODE_Sensors; 105 stateUsedWrite->diveSettings.CCR_Mode = CCRMODE_Sensors;
117 } 106 }
118 else 107 else
119 { 108 {
120 useSensorSubMenu = 1; 109 useSensorSubMenu = 1;
121 } 110 }
122 } 111 }
123 112
124 setActualGas_DM(&pState->lifeData,actualGasID,setpointCbar); 113 setActualGas_DM(&stateUsedWrite->lifeData,actualGasID,setpointCbar);
125 114
126 if(pState->diveSettings.diveMode != DIVEMODE_CCR) 115 if(stateUsedWrite->diveSettings.diveMode != DIVEMODE_CCR)
127 { 116 {
128 pState->diveSettings.diveMode = DIVEMODE_CCR; 117 stateUsedWrite->diveSettings.diveMode = DIVEMODE_CCR;
129 unblock_diluent_page(); 118 unblock_diluent_page();
130 } 119 }
131 120
132 clear_warning_fallback(); 121 clear_warning_fallback();
133 122
153 write_label_var( 96, 340, ME_Y_LINE3, &FontT48, "Sensor 3"); 142 write_label_var( 96, 340, ME_Y_LINE3, &FontT48, "Sensor 3");
154 143
155 sensorActive[0] = 1; 144 sensorActive[0] = 1;
156 sensorActive[1] = 1; 145 sensorActive[1] = 1;
157 sensorActive[2] = 1; 146 sensorActive[2] = 1;
158 if(pState->diveSettings.ppo2sensors_deactivated & 1) 147 if(stateUsedWrite->diveSettings.ppo2sensors_deactivated & 1)
159 sensorActive[0] = 0; 148 sensorActive[0] = 0;
160 if(pState->diveSettings.ppo2sensors_deactivated & 2) 149 if(stateUsedWrite->diveSettings.ppo2sensors_deactivated & 2)
161 sensorActive[1] = 0; 150 sensorActive[1] = 0;
162 if(pState->diveSettings.ppo2sensors_deactivated & 4) 151 if(stateUsedWrite->diveSettings.ppo2sensors_deactivated & 4)
163 sensorActive[2] = 0; 152 sensorActive[2] = 0;
164 153
165 write_field_on_off(StMSP_Sensor1, 30, 95, ME_Y_LINE1, &FontT48, "", sensorActive[0]); 154 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]); 155 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]); 156 write_field_on_off(StMSP_Sensor3, 30, 95, ME_Y_LINE3, &FontT48, "", sensorActive[2]);
239 setEvent(StMSP_ppo2_setting, (uint32_t)OnAction_SP_Setpoint); 228 setEvent(StMSP_ppo2_setting, (uint32_t)OnAction_SP_Setpoint);
240 startEdit(); 229 startEdit();
241 } 230 }
242 } 231 }
243 232
244 uint8_t OnAction_SP_Setpoint(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action) 233 static uint8_t OnAction_SP_Setpoint(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action)
245 { 234 {
246 int8_t digitContentNew; 235 int8_t digitContentNew;
247 uint32_t new_integer_part, new_fractional_part, new_cbar, newDepth; 236 uint32_t new_integer_part, new_fractional_part, new_cbar, newDepth;
248 237
249 if(action == ACTION_BUTTON_ENTER) 238 if(action == ACTION_BUTTON_ENTER)
295 } 284 }
296 285
297 return EXIT_TO_MENU; 286 return EXIT_TO_MENU;
298 } 287 }
299 288
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) 289 void openEdit_DiveSelectBetterSetpoint(void)
339 { 290 {
340 uint8_t spId; 291 uint8_t spId;
341 SDiveState *pState;
342 uint8_t depth; 292 uint8_t depth;
343 293
344 spId = actualBetterSetpointId(); 294 spId = actualBetterSetpointId();
345 295
346 if(actual_menu_content == MENU_DIVE_REAL) 296 depth = stateUsedWrite->diveSettings.setpoint[spId].depth_meter;
347 pState = stateRealGetPointerWrite();
348 else
349 pState = stateSimGetPointerWrite();
350
351 depth = pState->diveSettings.setpoint[spId].depth_meter;
352 297
353 // BetterSetpoint warning only once -> clear active 298 // BetterSetpoint warning only once -> clear active
354 for(int i=0; i<=NUM_GASES; i++) 299 for(int i=0; i<=NUM_GASES; i++)
355 { 300 {
356 pState->diveSettings.setpoint[i].note.ub.first = 0; 301 stateUsedWrite->diveSettings.setpoint[i].note.ub.first = 0;
357 if(pState->diveSettings.setpoint[i].depth_meter <= depth) 302 if(stateUsedWrite->diveSettings.setpoint[i].depth_meter <= depth)
358 pState->diveSettings.setpoint[i].note.ub.active = 0; 303 stateUsedWrite->diveSettings.setpoint[i].note.ub.active = 0;
359 } 304 }
360 305
361 // new setpoint 306 // new setpoint
362 pState->diveSettings.setpoint[spId].note.ub.first = 1; 307 stateUsedWrite->diveSettings.setpoint[spId].note.ub.first = 1;
363 308
364 // change in lifeData 309 // change in lifeData
365 setActualGas_DM(&pState->lifeData, pState->lifeData.actualGas.GasIdInSettings, pState->diveSettings.setpoint[spId].setpoint_cbar); 310 setActualGas_DM(&stateUsedWrite->lifeData, stateUsedWrite->lifeData.actualGas.GasIdInSettings, stateUsedWrite->diveSettings.setpoint[spId].setpoint_cbar);
366 } 311 }
367 312
368 uint8_t OnAction_SP_DM_Sensor1 (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action) 313 static uint8_t OnAction_SP_DM_Sensor1 (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action)
369 { 314 {
370 SDiveState * pDiveState = 0; 315 if(stateUsedWrite->diveSettings.ppo2sensors_deactivated & 1)
371 316 {
372 if(actual_menu_content == MENU_DIVE_REAL) 317 stateUsedWrite->diveSettings.ppo2sensors_deactivated &= 4+2;
373 pDiveState = stateRealGetPointerWrite(); 318 tMenuEdit_set_on_off(editId, 1);
319 }
374 else 320 else
375 pDiveState = stateSimGetPointerWrite(); 321 {
376 322 stateUsedWrite->diveSettings.ppo2sensors_deactivated |= 1;
377 if(pDiveState->diveSettings.ppo2sensors_deactivated & 1) 323 tMenuEdit_set_on_off(editId, 0);
378 { 324 }
379 pDiveState->diveSettings.ppo2sensors_deactivated &= 4+2; 325
326 return UNSPECIFIC_RETURN;
327 }
328
329 static uint8_t OnAction_SP_DM_Sensor2 (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action)
330 {
331 if(stateUsedWrite->diveSettings.ppo2sensors_deactivated & 2)
332 {
333 stateUsedWrite->diveSettings.ppo2sensors_deactivated &= 4+1;
380 tMenuEdit_set_on_off(editId, 1); 334 tMenuEdit_set_on_off(editId, 1);
381 } 335 }
382 else 336 else
383 { 337 {
384 pDiveState->diveSettings.ppo2sensors_deactivated |= 1; 338 stateUsedWrite->diveSettings.ppo2sensors_deactivated |= 2;
385 tMenuEdit_set_on_off(editId, 0); 339 tMenuEdit_set_on_off(editId, 0);
386 } 340 }
387 341
388 return UNSPECIFIC_RETURN; 342 return UNSPECIFIC_RETURN;
389 } 343 }
390 344
391 uint8_t OnAction_SP_DM_Sensor2 (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action) 345 static uint8_t OnAction_SP_DM_Sensor3 (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action)
392 { 346 {
393 SDiveState * pDiveState = 0; 347 if(stateUsedWrite->diveSettings.ppo2sensors_deactivated & 4)
394 348 {
395 if(actual_menu_content == MENU_DIVE_REAL) 349 stateUsedWrite->diveSettings.ppo2sensors_deactivated &= 2+1;
396 pDiveState = stateRealGetPointerWrite(); 350 tMenuEdit_set_on_off(editId, 1);
351 }
397 else 352 else
398 pDiveState = stateSimGetPointerWrite(); 353 {
399 354 stateUsedWrite->diveSettings.ppo2sensors_deactivated |= 4;
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); 355 tMenuEdit_set_on_off(editId, 0);
409 } 356 }
410
411 return UNSPECIFIC_RETURN; 357 return UNSPECIFIC_RETURN;
412 } 358 }
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 */