Mercurial > public > ostc4
annotate Discovery/Src/check_warning.c @ 1007:65d35e66efb9 GasConsumption
Improve compass calibration dialog:
The previous calibration dialog showed some "magic" numbers and a 60 second count down. The new version is trying to guide the user through the calibration process: first rotate pitch, then roll and at last yaw angle. A step to the next angle is taken when enough data per angle is collected (change from red to green). To enable the yaw visualization a simple calibration is done while rotating the axis.
The function behind the calibration was not modified => the suggested process can be ignored and the same handling as the with old dialog may be applied. With the new process the dialog may be left early. Anyhow it will still be left after 60 seconds and the fine calibration is performed in the same way as before.
| author | Ideenmodellierer |
|---|---|
| date | Mon, 05 May 2025 21:02:34 +0200 |
| parents | 8507a87f6401 |
| children |
| rev | line source |
|---|---|
| 38 | 1 /** |
| 2 ****************************************************************************** | |
| 3 * @file check_warning.c | |
| 4 * @author heinrichs weikamp gmbh | |
| 5 * @date 17-Nov-2014 | |
| 6 * @version V0.0.1 | |
| 7 * @since 17-Nov-2014 | |
| 8 * @brief check and set warnings for warnings | |
| 9 * | |
| 10 @verbatim | |
| 11 ============================================================================== | |
| 12 ##### How to use ##### | |
| 13 ============================================================================== | |
| 14 OSTC3 Warnings: | |
| 15 niedriger Batteriezustand ( | |
| 16 zu hoher oder zu niedriger Sauerstoffpartialdruck (ppO2) 0.2 - 1.6 | |
| 17 zu hoher CNS (Gefahr der Sauerstoffvergiftung) 90% | |
| 18 zu hohe Gradientenfaktoren 90 - 90 | |
| 19 Missachtung der Dekostopps (der �berschrittene Dekostopp wird rot angezeigt) 0 m | |
| 20 zu hohe Aufstiegsgeschwindigkeit 30 m/min | |
| 21 aGF-Warnung: die Berechnung der Dekompression wird �ber alternative GF-Werte durchgef�hrt | |
| 22 Fallback-Warnung bei ausgefallenem Sensor | |
| 23 | |
| 24 @endverbatim | |
| 25 ****************************************************************************** | |
| 26 * @attention | |
| 27 * | |
| 28 * <h2><center>© COPYRIGHT(c) 2014 heinrichs weikamp</center></h2> | |
| 29 * | |
| 30 ****************************************************************************** | |
| 31 */ | |
| 32 | |
| 33 /* Includes ------------------------------------------------------------------*/ | |
| 34 | |
|
771
29d9b5bc7946
Revised automatic setpoint change. The proposed approach is essentially the approach used by most controllers of eCCR ('upshift' on descent, 'downshift' on ascent), so that the OSTC4 when used as a backup computer for eCCR will make the changes at the same time as the eCCR itself.
heinrichsweikamp
parents:
756
diff
changeset
|
35 #include <stdbool.h> |
|
29d9b5bc7946
Revised automatic setpoint change. The proposed approach is essentially the approach used by most controllers of eCCR ('upshift' on descent, 'downshift' on ascent), so that the OSTC4 when used as a backup computer for eCCR will make the changes at the same time as the eCCR itself.
heinrichsweikamp
parents:
756
diff
changeset
|
36 |
| 38 | 37 #include "data_exchange.h" |
| 38 #include "check_warning.h" | |
| 39 #include "settings.h" | |
| 40 #include "decom.h" | |
| 41 #include "tCCR.h" | |
|
788
4abfb8a2a435
Define explicit setpoints for low / high / deco. Add an option to delay the switch to SPlow until all decompression has been cleared. (mikeller)
heinrichsweikamp
parents:
773
diff
changeset
|
42 #include "tHome.h" |
| 38 | 43 |
| 636 | 44 |
| 45 #define DEBOUNCE_FALLBACK_TIME_MS (5000u) /* set warning after 5 seconds of pending error condition */ | |
| 952 | 46 #define GUI_BUZZER_TIMEOUT_MS (200u) /* the buzzer should be active while Warning string is shown, but diver may be in a menu... */ |
| 636 | 47 |
|
788
4abfb8a2a435
Define explicit setpoints for low / high / deco. Add an option to delay the switch to SPlow until all decompression has been cleared. (mikeller)
heinrichsweikamp
parents:
773
diff
changeset
|
48 #define SETPOINT_DECO_START_RANGE_M 3.0 |
|
4abfb8a2a435
Define explicit setpoints for low / high / deco. Add an option to delay the switch to SPlow until all decompression has been cleared. (mikeller)
heinrichsweikamp
parents:
773
diff
changeset
|
49 #define SWITCH_DEPTH_LOW_MINIMUM_M 1.0 |
| 756 | 50 |
|
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
51 /* Private variables with access ----------------------------------------------*/ |
|
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
52 static uint8_t betterGasId = 0; |
|
773
2c243233c999
Menu shortcut for bailout / return to circuit when diving in CCR mode (mikeller)
heinrichsweikamp
parents:
771
diff
changeset
|
53 static uint8_t betterBailoutGasId = 0; |
|
771
29d9b5bc7946
Revised automatic setpoint change. The proposed approach is essentially the approach used by most controllers of eCCR ('upshift' on descent, 'downshift' on ascent), so that the OSTC4 when used as a backup computer for eCCR will make the changes at the same time as the eCCR itself.
heinrichsweikamp
parents:
756
diff
changeset
|
54 static uint8_t betterSetpointId = 1; |
|
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
55 static int8_t fallback = 0; |
| 636 | 56 static uint16_t debounceFallbackTimeMS = 0; |
| 952 | 57 static uint8_t buzzerRequestActive = 0; |
| 38 | 58 |
| 59 /* Private function prototypes -----------------------------------------------*/ | |
|
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
60 static int8_t check_fallback(SDiveState * pDiveState); |
|
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
61 static int8_t check_ppO2(SDiveState * pDiveState); |
|
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
62 static int8_t check_O2_sensors(SDiveState * pDiveState); |
|
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
63 static int8_t check_CNS(SDiveState * pDiveState); |
|
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
64 static int8_t check_Deco(SDiveState * pDiveState); |
|
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
65 static int8_t check_AscentRate(SDiveState * pDiveState); |
|
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
66 static int8_t check_aGF(SDiveState * pDiveState); |
|
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
67 static int8_t check_BetterGas(SDiveState * pDiveState); |
|
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
68 static int8_t check_BetterSetpoint(SDiveState * pDiveState); |
|
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
69 static int8_t check_Battery(SDiveState * pDiveState); |
|
478
58200d756365
Development option only: Show Pressure update for a short time in the custom field (as warning)
ideenmodellierer
parents:
272
diff
changeset
|
70 #ifdef ENABLE_BOTTLE_SENSOR |
|
58200d756365
Development option only: Show Pressure update for a short time in the custom field (as warning)
ideenmodellierer
parents:
272
diff
changeset
|
71 static int8_t check_pressureSensor(SDiveState * pDiveState); |
|
58200d756365
Development option only: Show Pressure update for a short time in the custom field (as warning)
ideenmodellierer
parents:
272
diff
changeset
|
72 #endif |
| 756 | 73 #ifdef ENABLE_CO2_SUPPORT |
| 74 static int8_t check_co2(SDiveState * pDiveState); | |
| 75 #endif | |
|
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
76 static int8_t check_helper_same_oxygen_and_helium_content(SGasLine * gas1, SGasLine * gas2); |
| 857 | 77 #ifdef HAVE_DEBUG_WARNINGS |
| 78 static int8_t check_debug(SDiveState * pDiveState); | |
| 79 #endif | |
| 952 | 80 static uint8_t buzzerOn = 0; /* current state of the buzzer */ |
| 857 | 81 |
| 996 | 82 static void handleBuzzer(int8_t warningActive); |
| 952 | 83 /* Exported functions --------------------------------------------------------*/ |
| 84 | |
| 85 void requestBuzzerActivation(uint8_t active) | |
| 86 { | |
| 87 buzzerRequestActive = active; | |
| 88 } | |
| 89 | |
| 996 | 90 uint8_t getBuzzerActivationRequest() |
| 91 { | |
| 92 return buzzerRequestActive; | |
| 93 } | |
| 94 | |
| 952 | 95 uint8_t getBuzzerActivationState() |
| 96 { | |
| 97 return buzzerOn; | |
| 98 } | |
| 99 | |
| 996 | 100 static void handleBuzzer(int8_t warningActive) |
| 952 | 101 { |
| 102 static uint32_t guiTimeoutCnt = 0; /* max delay till buzzer will be activated independend from gui request */ | |
| 103 static uint32_t stateTick = 0; /* activation tick of current state */ | |
| 104 static uint8_t lastWarningState = 0; /* the parameter value of the last call*/ | |
| 996 | 105 static uint8_t lastBuzzerRequest = 0; |
| 106 static uint8_t guiTrigger = 0; | |
| 952 | 107 |
| 108 uint32_t tick = HAL_GetTick(); | |
| 38 | 109 |
| 996 | 110 if(stateUsed->mode == MODE_SURFACE) |
| 952 | 111 { |
| 996 | 112 warningActive = 0; /* no warning buzzer in surface mode => overwrite value */ |
| 113 } | |
| 114 | |
| 115 /* There are two sources for buzzer activation: the warning detection and activation by gui => both need to be merged */ | |
| 116 if((buzzerRequestActive != REQUEST_BUZZER_OFF) && (lastBuzzerRequest == REQUEST_BUZZER_OFF)) | |
| 117 { | |
| 118 guiTrigger = 1; | |
| 119 } | |
| 120 if((warningActive) || (buzzerRequestActive != REQUEST_BUZZER_OFF)) | |
| 121 { | |
| 122 if((lastWarningState == 0) && (lastBuzzerRequest == REQUEST_BUZZER_OFF)) /* init structures */ | |
| 952 | 123 { |
| 124 guiTimeoutCnt = tick; | |
| 125 stateTick = tick; | |
| 126 } | |
| 127 if(buzzerOn) | |
| 128 { | |
| 129 if(time_elapsed_ms(stateTick, tick) > EXT_INTERFACE_BUZZER_STABLE_TIME_MS) /* buzzer has to be on for a certain time */ | |
| 130 { | |
| 996 | 131 if((buzzerRequestActive == REQUEST_BUZZER_OFF) |
| 132 || ((buzzerRequestActive == REQUEST_BUZZER_ONCE) && (time_elapsed_ms(stateTick, tick) > EXT_INTERFACE_BUZZER_PING_TIME_MS)) | |
| 133 || (time_elapsed_ms(stateTick, tick) > EXT_INTERFACE_BUZZER_ON_TIME_MS)) | |
| 952 | 134 { |
| 135 buzzerOn = 0; | |
| 136 stateTick = tick; | |
| 137 guiTimeoutCnt = tick; | |
| 996 | 138 buzzerRequestActive = REQUEST_BUZZER_OFF; |
| 952 | 139 } |
| 140 } | |
| 141 } | |
| 142 else | |
| 143 { | |
| 996 | 144 if((time_elapsed_ms(stateTick, tick) > EXT_INTERFACE_BUZZER_STABLE_TIME_MS) || ( guiTrigger)) /* buzzer has to be off for a certain time */ |
| 952 | 145 { |
| 996 | 146 if((warningActive) || (buzzerRequestActive != REQUEST_BUZZER_OFF)) |
| 952 | 147 { |
| 996 | 148 if(((stateUsed->mode != MODE_SURFACE) && (time_elapsed_ms(guiTimeoutCnt, tick)) > (EXT_INTERFACE_BUZZER_ON_TIME_MS + GUI_BUZZER_TIMEOUT_MS)) |
| 149 || ( guiTrigger)) | |
| 150 { | |
| 151 buzzerOn = 1; | |
| 152 stateTick = tick; | |
| 153 guiTrigger = 0; | |
| 154 if(buzzerRequestActive == REQUEST_BUZZER_ONCE) | |
| 155 { | |
| 156 buzzerRequestActive = REQUEST_BUZZER_OFF; | |
| 157 } | |
| 158 } | |
| 159 if((time_elapsed_ms(guiTimeoutCnt, tick)) > (EXT_INTERFACE_BUZZER_ON_TIME_MS + EXT_INTERFACE_BUZZER_STABLE_TIME_MS)) /* timeout request */ | |
| 160 { | |
| 161 buzzerRequestActive = REQUEST_BUZZER_OFF; | |
| 162 } | |
| 952 | 163 } |
| 164 } | |
| 165 } | |
| 166 } | |
| 167 else | |
| 168 { | |
| 169 buzzerOn = 0; | |
| 170 } | |
| 996 | 171 lastBuzzerRequest = buzzerRequestActive; |
| 952 | 172 lastWarningState = warningActive; |
| 173 } | |
| 38 | 174 |
| 996 | 175 void deactivateBuzzer() |
| 176 { | |
| 177 buzzerRequestActive = REQUEST_BUZZER_OFF; | |
| 178 buzzerOn = 0; | |
| 179 } | |
| 180 | |
| 38 | 181 void check_warning(void) |
| 182 { | |
|
272
74a8296a2318
cleanup: simplify stateUsed usage
Jan Mulder <jlmulder@xs4all.nl>
parents:
268
diff
changeset
|
183 check_warning2(stateUsedWrite); |
| 38 | 184 } |
| 185 | |
| 186 | |
| 187 void check_warning2(SDiveState * pDiveState) | |
| 188 { | |
| 189 pDiveState->warnings.numWarnings = 0; | |
| 190 | |
| 952 | 191 /* Warnings checked before the SetBuzzer call will activate the buzzer */ |
| 38 | 192 pDiveState->warnings.numWarnings += check_AscentRate(pDiveState); |
| 193 pDiveState->warnings.numWarnings += check_Deco(pDiveState); | |
| 194 pDiveState->warnings.numWarnings += check_ppO2(pDiveState); | |
| 195 pDiveState->warnings.numWarnings += check_O2_sensors(pDiveState); | |
| 952 | 196 pDiveState->warnings.numWarnings += check_fallback(pDiveState); |
| 197 #ifdef ENABLE_CO2_SUPPORT | |
| 198 pDiveState->warnings.numWarnings += check_co2(pDiveState); | |
| 199 #endif | |
| 200 | |
| 201 if(settingsGetPointer()->warningBuzzer) | |
| 202 { | |
| 996 | 203 handleBuzzer(pDiveState->warnings.numWarnings); |
| 952 | 204 } |
| 205 | |
| 206 /* Warnings checked after this line will not cause activation of the buzzer */ | |
| 207 pDiveState->warnings.numWarnings += check_aGF(pDiveState); | |
| 208 pDiveState->warnings.numWarnings += check_CNS(pDiveState); | |
| 38 | 209 pDiveState->warnings.numWarnings += check_BetterGas(pDiveState); |
| 210 pDiveState->warnings.numWarnings += check_BetterSetpoint(pDiveState); | |
| 211 pDiveState->warnings.numWarnings += check_Battery(pDiveState); | |
|
478
58200d756365
Development option only: Show Pressure update for a short time in the custom field (as warning)
ideenmodellierer
parents:
272
diff
changeset
|
212 #ifdef ENABLE_BOTTLE_SENSOR |
|
58200d756365
Development option only: Show Pressure update for a short time in the custom field (as warning)
ideenmodellierer
parents:
272
diff
changeset
|
213 pDiveState->warnings.numWarnings += check_pressureSensor(pDiveState); |
|
58200d756365
Development option only: Show Pressure update for a short time in the custom field (as warning)
ideenmodellierer
parents:
272
diff
changeset
|
214 #endif |
| 952 | 215 |
| 857 | 216 #ifdef HAVE_DEBUG_WARNINGS |
| 217 pDiveState->warnings.numWarnings += check_debug(pDiveState); | |
| 218 #endif | |
| 38 | 219 } |
| 220 | |
| 221 | |
| 222 void set_warning_fallback(void) | |
| 223 { | |
| 224 fallback = 1; | |
| 225 } | |
| 226 | |
| 227 | |
| 228 void clear_warning_fallback(void) | |
| 229 { | |
| 230 fallback = 0; | |
| 636 | 231 debounceFallbackTimeMS = 0; |
| 38 | 232 } |
| 233 | |
| 234 | |
| 235 uint8_t actualBetterGasId(void) | |
| 236 { | |
| 237 return betterGasId; | |
| 238 } | |
| 239 | |
| 240 | |
|
773
2c243233c999
Menu shortcut for bailout / return to circuit when diving in CCR mode (mikeller)
heinrichsweikamp
parents:
771
diff
changeset
|
241 uint8_t actualBetterBailoutGasId(void) |
|
2c243233c999
Menu shortcut for bailout / return to circuit when diving in CCR mode (mikeller)
heinrichsweikamp
parents:
771
diff
changeset
|
242 { |
|
2c243233c999
Menu shortcut for bailout / return to circuit when diving in CCR mode (mikeller)
heinrichsweikamp
parents:
771
diff
changeset
|
243 return betterBailoutGasId; |
|
2c243233c999
Menu shortcut for bailout / return to circuit when diving in CCR mode (mikeller)
heinrichsweikamp
parents:
771
diff
changeset
|
244 } |
|
2c243233c999
Menu shortcut for bailout / return to circuit when diving in CCR mode (mikeller)
heinrichsweikamp
parents:
771
diff
changeset
|
245 |
|
2c243233c999
Menu shortcut for bailout / return to circuit when diving in CCR mode (mikeller)
heinrichsweikamp
parents:
771
diff
changeset
|
246 |
| 38 | 247 uint8_t actualBetterSetpointId(void) |
| 248 { | |
| 249 return betterSetpointId; | |
| 250 } | |
| 251 | |
| 252 | |
| 253 uint8_t actualLeftMaxDepth(const SDiveState * pDiveState) | |
| 254 { | |
| 255 if(pDiveState->lifeData.depth_meter > (pDiveState->lifeData.max_depth_meter - 3.0f)) | |
| 256 return 0; | |
| 257 else | |
| 258 return 1; | |
| 259 } | |
| 260 | |
| 261 | |
| 262 /* Private functions ---------------------------------------------------------*/ | |
|
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
263 static int8_t check_fallback(SDiveState * pDiveState) |
| 38 | 264 { |
| 662 | 265 if(fallback && ((pDiveState->mode != MODE_DIVE) || (!isLoopMode(pDiveState->diveSettings.diveMode)))) |
| 38 | 266 fallback = 0; |
| 267 | |
| 268 pDiveState->warnings.fallback = fallback; | |
| 269 return pDiveState->warnings.fallback; | |
| 270 } | |
| 271 | |
| 272 | |
|
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
273 static int8_t check_ppO2(SDiveState * pDiveState) |
| 38 | 274 { |
| 952 | 275 if((pDiveState->mode != MODE_DIVE) || ((isLoopMode(pDiveState->diveSettings.diveMode) && (pDiveState->warnings.fallback)))) |
| 38 | 276 { |
| 277 pDiveState->warnings.ppO2Low = 0; | |
| 278 pDiveState->warnings.ppO2High = 0; | |
| 279 return 0; | |
| 280 } | |
| 281 | |
| 282 uint8_t localPPO2, testPPO2high; | |
| 283 | |
| 284 if(pDiveState->lifeData.ppO2 < 0) | |
| 285 localPPO2 = 0; | |
| 286 else | |
| 287 if(pDiveState->lifeData.ppO2 >= 2.5f) | |
| 288 localPPO2 = 255; | |
| 289 else | |
| 290 localPPO2 = (uint8_t)(pDiveState->lifeData.ppO2 * 100); | |
| 291 | |
| 292 if((localPPO2 + 1) <= settingsGetPointer()->ppO2_min) | |
| 293 pDiveState->warnings.ppO2Low = 1; | |
| 294 else | |
| 295 pDiveState->warnings.ppO2Low = 0; | |
| 296 | |
| 297 if(actualLeftMaxDepth(pDiveState)) | |
| 298 testPPO2high = settingsGetPointer()->ppO2_max_deco; | |
| 299 else | |
| 300 testPPO2high = settingsGetPointer()->ppO2_max_std; | |
| 301 | |
| 302 if(localPPO2 >= (testPPO2high + 1)) | |
| 303 pDiveState->warnings.ppO2High = 1; | |
| 304 else | |
| 305 pDiveState->warnings.ppO2High = 0; | |
| 306 | |
| 307 return pDiveState->warnings.ppO2Low + pDiveState->warnings.ppO2High; | |
| 308 } | |
| 309 | |
| 310 | |
|
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
311 static int8_t check_O2_sensors(SDiveState * pDiveState) |
| 38 | 312 { |
| 313 pDiveState->warnings.sensorLinkLost = 0; | |
| 314 pDiveState->warnings.sensorOutOfBounds[0] = 0; | |
| 315 pDiveState->warnings.sensorOutOfBounds[1] = 0; | |
| 316 pDiveState->warnings.sensorOutOfBounds[2] = 0; | |
| 317 | |
| 662 | 318 if(isLoopMode(pDiveState->diveSettings.diveMode) && (pDiveState->diveSettings.CCR_Mode == CCRMODE_Sensors)) |
| 952 | 319 { |
| 563 | 320 if(settingsGetPointer()->ppo2sensors_source == O2_SENSOR_SOURCE_OPTIC) |
| 321 { | |
| 322 { | |
| 323 if(!get_HUD_battery_voltage_V()) | |
| 324 pDiveState->warnings.sensorLinkLost = 1; | |
| 325 } | |
| 326 } | |
| 952 | 327 test_O2_sensor_values_outOfBounds(&pDiveState->warnings.sensorOutOfBounds[0], &pDiveState->warnings.sensorOutOfBounds[1], &pDiveState->warnings.sensorOutOfBounds[2]); |
| 328 } | |
| 38 | 329 return pDiveState->warnings.sensorLinkLost |
| 330 + pDiveState->warnings.sensorOutOfBounds[0] | |
| 331 + pDiveState->warnings.sensorOutOfBounds[1] | |
| 332 + pDiveState->warnings.sensorOutOfBounds[2]; | |
| 333 } | |
| 334 | |
| 335 | |
|
773
2c243233c999
Menu shortcut for bailout / return to circuit when diving in CCR mode (mikeller)
heinrichsweikamp
parents:
771
diff
changeset
|
336 static uint8_t getBetterGasId(bool getDiluent, uint8_t startingGasId, SDiveState *diveState) |
| 38 | 337 { |
|
773
2c243233c999
Menu shortcut for bailout / return to circuit when diving in CCR mode (mikeller)
heinrichsweikamp
parents:
771
diff
changeset
|
338 SDiveSettings diveSettings = diveState->diveSettings; |
| 831 | 339 SGasLine localGas; |
|
773
2c243233c999
Menu shortcut for bailout / return to circuit when diving in CCR mode (mikeller)
heinrichsweikamp
parents:
771
diff
changeset
|
340 uint8_t betterGasIdLocal = startingGasId; |
|
2c243233c999
Menu shortcut for bailout / return to circuit when diving in CCR mode (mikeller)
heinrichsweikamp
parents:
771
diff
changeset
|
341 uint8_t bestGasDepth = 255; |
| 831 | 342 uint8_t i; |
| 38 | 343 |
|
773
2c243233c999
Menu shortcut for bailout / return to circuit when diving in CCR mode (mikeller)
heinrichsweikamp
parents:
771
diff
changeset
|
344 uint8_t gasIdOffset; |
|
2c243233c999
Menu shortcut for bailout / return to circuit when diving in CCR mode (mikeller)
heinrichsweikamp
parents:
771
diff
changeset
|
345 if (getDiluent) { |
|
2c243233c999
Menu shortcut for bailout / return to circuit when diving in CCR mode (mikeller)
heinrichsweikamp
parents:
771
diff
changeset
|
346 gasIdOffset = NUM_OFFSET_DILUENT; |
|
2c243233c999
Menu shortcut for bailout / return to circuit when diving in CCR mode (mikeller)
heinrichsweikamp
parents:
771
diff
changeset
|
347 } else { |
|
2c243233c999
Menu shortcut for bailout / return to circuit when diving in CCR mode (mikeller)
heinrichsweikamp
parents:
771
diff
changeset
|
348 gasIdOffset = 0; |
|
2c243233c999
Menu shortcut for bailout / return to circuit when diving in CCR mode (mikeller)
heinrichsweikamp
parents:
771
diff
changeset
|
349 } |
| 38 | 350 |
| 351 /* life data is float, gas data is uint8 */ | |
|
773
2c243233c999
Menu shortcut for bailout / return to circuit when diving in CCR mode (mikeller)
heinrichsweikamp
parents:
771
diff
changeset
|
352 if (actualLeftMaxDepth(diveState)) { /* deco gases */ |
| 831 | 353 for (i=1+gasIdOffset; i<= 5+gasIdOffset; i++) { |
| 354 memcpy(&localGas,&diveSettings.gas[i],sizeof(SGasLine)); | |
| 355 if((localGas.note.ub.first) && (diveSettings.diveMode == DIVEMODE_PSCR)) /* handle first gas as if it would be a deco gas set to MOD */ | |
| 356 { | |
| 357 localGas.note.ub.active = 1; | |
| 358 localGas.note.ub.deco = 1; | |
| 359 localGas.depth_meter = calc_MOD(i); | |
| 360 } | |
| 361 if ((localGas.note.ub.active) | |
| 362 && (localGas.note.ub.deco) | |
| 363 && (localGas.depth_meter) | |
| 913 | 364 && (localGas.depth_meter >= (diveState->lifeData.depth_meter - 0.9f )) |
| 831 | 365 && (localGas.depth_meter <= bestGasDepth)) { |
|
773
2c243233c999
Menu shortcut for bailout / return to circuit when diving in CCR mode (mikeller)
heinrichsweikamp
parents:
771
diff
changeset
|
366 betterGasIdLocal = i; |
|
2c243233c999
Menu shortcut for bailout / return to circuit when diving in CCR mode (mikeller)
heinrichsweikamp
parents:
771
diff
changeset
|
367 bestGasDepth = diveSettings.gas[i].depth_meter; |
|
2c243233c999
Menu shortcut for bailout / return to circuit when diving in CCR mode (mikeller)
heinrichsweikamp
parents:
771
diff
changeset
|
368 } |
|
2c243233c999
Menu shortcut for bailout / return to circuit when diving in CCR mode (mikeller)
heinrichsweikamp
parents:
771
diff
changeset
|
369 } |
|
2c243233c999
Menu shortcut for bailout / return to circuit when diving in CCR mode (mikeller)
heinrichsweikamp
parents:
771
diff
changeset
|
370 } else { /* travel gases */ |
|
2c243233c999
Menu shortcut for bailout / return to circuit when diving in CCR mode (mikeller)
heinrichsweikamp
parents:
771
diff
changeset
|
371 bestGasDepth = 0; |
|
2c243233c999
Menu shortcut for bailout / return to circuit when diving in CCR mode (mikeller)
heinrichsweikamp
parents:
771
diff
changeset
|
372 //check for travalgas |
| 831 | 373 for (i = 1 + gasIdOffset; i <= 5 + gasIdOffset; i++) { |
|
773
2c243233c999
Menu shortcut for bailout / return to circuit when diving in CCR mode (mikeller)
heinrichsweikamp
parents:
771
diff
changeset
|
374 if ((diveSettings.gas[i].note.ub.active) |
|
2c243233c999
Menu shortcut for bailout / return to circuit when diving in CCR mode (mikeller)
heinrichsweikamp
parents:
771
diff
changeset
|
375 && (diveSettings.gas[i].note.ub.travel) |
|
2c243233c999
Menu shortcut for bailout / return to circuit when diving in CCR mode (mikeller)
heinrichsweikamp
parents:
771
diff
changeset
|
376 && (diveSettings.gas[i].depth_meter_travel) |
|
2c243233c999
Menu shortcut for bailout / return to circuit when diving in CCR mode (mikeller)
heinrichsweikamp
parents:
771
diff
changeset
|
377 && (diveSettings.gas[i].depth_meter_travel <= (diveState->lifeData.depth_meter + 0.01f )) |
|
2c243233c999
Menu shortcut for bailout / return to circuit when diving in CCR mode (mikeller)
heinrichsweikamp
parents:
771
diff
changeset
|
378 && (diveSettings.gas[i].depth_meter_travel >= bestGasDepth)) { |
|
2c243233c999
Menu shortcut for bailout / return to circuit when diving in CCR mode (mikeller)
heinrichsweikamp
parents:
771
diff
changeset
|
379 betterGasIdLocal = i; |
|
2c243233c999
Menu shortcut for bailout / return to circuit when diving in CCR mode (mikeller)
heinrichsweikamp
parents:
771
diff
changeset
|
380 bestGasDepth = diveSettings.gas[i].depth_meter; |
|
2c243233c999
Menu shortcut for bailout / return to circuit when diving in CCR mode (mikeller)
heinrichsweikamp
parents:
771
diff
changeset
|
381 } |
| 38 | 382 } |
| 383 } | |
| 831 | 384 if((!getDiluent) && (betterGasIdLocal > NUM_OFFSET_DILUENT)) /* an OC gas was requested but Id is pointing to a diluent => return first OC */ |
| 385 { | |
| 386 for (i = 1 ; i <= NUM_OFFSET_DILUENT; i++) | |
| 387 { | |
| 388 if(diveSettings.gas[i].note.ub.first) | |
| 389 { | |
| 390 betterGasIdLocal = i; | |
| 391 break; | |
| 392 } | |
| 393 } | |
| 394 } | |
| 395 | |
| 38 | 396 |
|
773
2c243233c999
Menu shortcut for bailout / return to circuit when diving in CCR mode (mikeller)
heinrichsweikamp
parents:
771
diff
changeset
|
397 return betterGasIdLocal; |
|
2c243233c999
Menu shortcut for bailout / return to circuit when diving in CCR mode (mikeller)
heinrichsweikamp
parents:
771
diff
changeset
|
398 } |
|
2c243233c999
Menu shortcut for bailout / return to circuit when diving in CCR mode (mikeller)
heinrichsweikamp
parents:
771
diff
changeset
|
399 |
|
2c243233c999
Menu shortcut for bailout / return to circuit when diving in CCR mode (mikeller)
heinrichsweikamp
parents:
771
diff
changeset
|
400 |
|
2c243233c999
Menu shortcut for bailout / return to circuit when diving in CCR mode (mikeller)
heinrichsweikamp
parents:
771
diff
changeset
|
401 static int8_t check_BetterGas(SDiveState *diveState) |
|
2c243233c999
Menu shortcut for bailout / return to circuit when diving in CCR mode (mikeller)
heinrichsweikamp
parents:
771
diff
changeset
|
402 { |
|
2c243233c999
Menu shortcut for bailout / return to circuit when diving in CCR mode (mikeller)
heinrichsweikamp
parents:
771
diff
changeset
|
403 diveState->warnings.betterGas = 0; |
|
2c243233c999
Menu shortcut for bailout / return to circuit when diving in CCR mode (mikeller)
heinrichsweikamp
parents:
771
diff
changeset
|
404 |
|
2c243233c999
Menu shortcut for bailout / return to circuit when diving in CCR mode (mikeller)
heinrichsweikamp
parents:
771
diff
changeset
|
405 if (stateUsed->mode != MODE_DIVE) { |
|
2c243233c999
Menu shortcut for bailout / return to circuit when diving in CCR mode (mikeller)
heinrichsweikamp
parents:
771
diff
changeset
|
406 betterGasId = 0; |
|
2c243233c999
Menu shortcut for bailout / return to circuit when diving in CCR mode (mikeller)
heinrichsweikamp
parents:
771
diff
changeset
|
407 |
|
2c243233c999
Menu shortcut for bailout / return to circuit when diving in CCR mode (mikeller)
heinrichsweikamp
parents:
771
diff
changeset
|
408 return 0; |
| 38 | 409 } |
|
773
2c243233c999
Menu shortcut for bailout / return to circuit when diving in CCR mode (mikeller)
heinrichsweikamp
parents:
771
diff
changeset
|
410 |
|
2c243233c999
Menu shortcut for bailout / return to circuit when diving in CCR mode (mikeller)
heinrichsweikamp
parents:
771
diff
changeset
|
411 SDiveSettings diveSettings = diveState->diveSettings; |
|
2c243233c999
Menu shortcut for bailout / return to circuit when diving in CCR mode (mikeller)
heinrichsweikamp
parents:
771
diff
changeset
|
412 SLifeData lifeData = diveState->lifeData; |
|
2c243233c999
Menu shortcut for bailout / return to circuit when diving in CCR mode (mikeller)
heinrichsweikamp
parents:
771
diff
changeset
|
413 |
|
2c243233c999
Menu shortcut for bailout / return to circuit when diving in CCR mode (mikeller)
heinrichsweikamp
parents:
771
diff
changeset
|
414 if (isLoopMode(diveSettings.diveMode)) { |
|
2c243233c999
Menu shortcut for bailout / return to circuit when diving in CCR mode (mikeller)
heinrichsweikamp
parents:
771
diff
changeset
|
415 betterGasId = getBetterGasId(true, lifeData.actualGas.GasIdInSettings, diveState); |
|
2c243233c999
Menu shortcut for bailout / return to circuit when diving in CCR mode (mikeller)
heinrichsweikamp
parents:
771
diff
changeset
|
416 betterBailoutGasId = getBetterGasId(false, lifeData.lastDiluent_GasIdInSettings, diveState); |
|
2c243233c999
Menu shortcut for bailout / return to circuit when diving in CCR mode (mikeller)
heinrichsweikamp
parents:
771
diff
changeset
|
417 } else { |
|
2c243233c999
Menu shortcut for bailout / return to circuit when diving in CCR mode (mikeller)
heinrichsweikamp
parents:
771
diff
changeset
|
418 betterGasId = getBetterGasId(false, lifeData.actualGas.GasIdInSettings, diveState); |
|
2c243233c999
Menu shortcut for bailout / return to circuit when diving in CCR mode (mikeller)
heinrichsweikamp
parents:
771
diff
changeset
|
419 } |
|
2c243233c999
Menu shortcut for bailout / return to circuit when diving in CCR mode (mikeller)
heinrichsweikamp
parents:
771
diff
changeset
|
420 |
|
2c243233c999
Menu shortcut for bailout / return to circuit when diving in CCR mode (mikeller)
heinrichsweikamp
parents:
771
diff
changeset
|
421 if (betterGasId != lifeData.actualGas.GasIdInSettings && !check_helper_same_oxygen_and_helium_content(&diveSettings.gas[betterGasId], &diveSettings.gas[lifeData.actualGas.GasIdInSettings])) { |
|
2c243233c999
Menu shortcut for bailout / return to circuit when diving in CCR mode (mikeller)
heinrichsweikamp
parents:
771
diff
changeset
|
422 diveState->warnings.betterGas = 1; |
|
2c243233c999
Menu shortcut for bailout / return to circuit when diving in CCR mode (mikeller)
heinrichsweikamp
parents:
771
diff
changeset
|
423 } |
|
2c243233c999
Menu shortcut for bailout / return to circuit when diving in CCR mode (mikeller)
heinrichsweikamp
parents:
771
diff
changeset
|
424 |
|
2c243233c999
Menu shortcut for bailout / return to circuit when diving in CCR mode (mikeller)
heinrichsweikamp
parents:
771
diff
changeset
|
425 return diveState->warnings.betterGas; |
| 38 | 426 } |
| 427 | |
|
771
29d9b5bc7946
Revised automatic setpoint change. The proposed approach is essentially the approach used by most controllers of eCCR ('upshift' on descent, 'downshift' on ascent), so that the OSTC4 when used as a backup computer for eCCR will make the changes at the same time as the eCCR itself.
heinrichsweikamp
parents:
756
diff
changeset
|
428 |
|
29d9b5bc7946
Revised automatic setpoint change. The proposed approach is essentially the approach used by most controllers of eCCR ('upshift' on descent, 'downshift' on ascent), so that the OSTC4 when used as a backup computer for eCCR will make the changes at the same time as the eCCR itself.
heinrichsweikamp
parents:
756
diff
changeset
|
429 uint8_t getSetpointLowId(void) |
| 38 | 430 { |
|
788
4abfb8a2a435
Define explicit setpoints for low / high / deco. Add an option to delay the switch to SPlow until all decompression has been cleared. (mikeller)
heinrichsweikamp
parents:
773
diff
changeset
|
431 SSettings *settings = settingsGetPointer(); |
|
4abfb8a2a435
Define explicit setpoints for low / high / deco. Add an option to delay the switch to SPlow until all decompression has been cleared. (mikeller)
heinrichsweikamp
parents:
773
diff
changeset
|
432 |
|
4abfb8a2a435
Define explicit setpoints for low / high / deco. Add an option to delay the switch to SPlow until all decompression has been cleared. (mikeller)
heinrichsweikamp
parents:
773
diff
changeset
|
433 if (settings->autoSetpoint) { |
|
4abfb8a2a435
Define explicit setpoints for low / high / deco. Add an option to delay the switch to SPlow until all decompression has been cleared. (mikeller)
heinrichsweikamp
parents:
773
diff
changeset
|
434 return SETPOINT_INDEX_AUTO_LOW; |
|
4abfb8a2a435
Define explicit setpoints for low / high / deco. Add an option to delay the switch to SPlow until all decompression has been cleared. (mikeller)
heinrichsweikamp
parents:
773
diff
changeset
|
435 } |
|
4abfb8a2a435
Define explicit setpoints for low / high / deco. Add an option to delay the switch to SPlow until all decompression has been cleared. (mikeller)
heinrichsweikamp
parents:
773
diff
changeset
|
436 |
|
771
29d9b5bc7946
Revised automatic setpoint change. The proposed approach is essentially the approach used by most controllers of eCCR ('upshift' on descent, 'downshift' on ascent), so that the OSTC4 when used as a backup computer for eCCR will make the changes at the same time as the eCCR itself.
heinrichsweikamp
parents:
756
diff
changeset
|
437 uint8_t setpointLowId = 0; |
|
29d9b5bc7946
Revised automatic setpoint change. The proposed approach is essentially the approach used by most controllers of eCCR ('upshift' on descent, 'downshift' on ascent), so that the OSTC4 when used as a backup computer for eCCR will make the changes at the same time as the eCCR itself.
heinrichsweikamp
parents:
756
diff
changeset
|
438 uint8_t setpointLowDepthM = UINT8_MAX; |
|
29d9b5bc7946
Revised automatic setpoint change. The proposed approach is essentially the approach used by most controllers of eCCR ('upshift' on descent, 'downshift' on ascent), so that the OSTC4 when used as a backup computer for eCCR will make the changes at the same time as the eCCR itself.
heinrichsweikamp
parents:
756
diff
changeset
|
439 for (unsigned i = 1; i <= NUM_GASES; i++) { |
|
29d9b5bc7946
Revised automatic setpoint change. The proposed approach is essentially the approach used by most controllers of eCCR ('upshift' on descent, 'downshift' on ascent), so that the OSTC4 when used as a backup computer for eCCR will make the changes at the same time as the eCCR itself.
heinrichsweikamp
parents:
756
diff
changeset
|
440 if (stateUsed->diveSettings.setpoint[i].depth_meter && stateUsed->diveSettings.setpoint[i].depth_meter < setpointLowDepthM) { |
|
29d9b5bc7946
Revised automatic setpoint change. The proposed approach is essentially the approach used by most controllers of eCCR ('upshift' on descent, 'downshift' on ascent), so that the OSTC4 when used as a backup computer for eCCR will make the changes at the same time as the eCCR itself.
heinrichsweikamp
parents:
756
diff
changeset
|
441 setpointLowId = i; |
|
29d9b5bc7946
Revised automatic setpoint change. The proposed approach is essentially the approach used by most controllers of eCCR ('upshift' on descent, 'downshift' on ascent), so that the OSTC4 when used as a backup computer for eCCR will make the changes at the same time as the eCCR itself.
heinrichsweikamp
parents:
756
diff
changeset
|
442 setpointLowDepthM = stateUsed->diveSettings.setpoint[i].depth_meter; |
|
29d9b5bc7946
Revised automatic setpoint change. The proposed approach is essentially the approach used by most controllers of eCCR ('upshift' on descent, 'downshift' on ascent), so that the OSTC4 when used as a backup computer for eCCR will make the changes at the same time as the eCCR itself.
heinrichsweikamp
parents:
756
diff
changeset
|
443 } |
|
29d9b5bc7946
Revised automatic setpoint change. The proposed approach is essentially the approach used by most controllers of eCCR ('upshift' on descent, 'downshift' on ascent), so that the OSTC4 when used as a backup computer for eCCR will make the changes at the same time as the eCCR itself.
heinrichsweikamp
parents:
756
diff
changeset
|
444 } |
|
29d9b5bc7946
Revised automatic setpoint change. The proposed approach is essentially the approach used by most controllers of eCCR ('upshift' on descent, 'downshift' on ascent), so that the OSTC4 when used as a backup computer for eCCR will make the changes at the same time as the eCCR itself.
heinrichsweikamp
parents:
756
diff
changeset
|
445 |
|
29d9b5bc7946
Revised automatic setpoint change. The proposed approach is essentially the approach used by most controllers of eCCR ('upshift' on descent, 'downshift' on ascent), so that the OSTC4 when used as a backup computer for eCCR will make the changes at the same time as the eCCR itself.
heinrichsweikamp
parents:
756
diff
changeset
|
446 return setpointLowId; |
|
29d9b5bc7946
Revised automatic setpoint change. The proposed approach is essentially the approach used by most controllers of eCCR ('upshift' on descent, 'downshift' on ascent), so that the OSTC4 when used as a backup computer for eCCR will make the changes at the same time as the eCCR itself.
heinrichsweikamp
parents:
756
diff
changeset
|
447 } |
|
29d9b5bc7946
Revised automatic setpoint change. The proposed approach is essentially the approach used by most controllers of eCCR ('upshift' on descent, 'downshift' on ascent), so that the OSTC4 when used as a backup computer for eCCR will make the changes at the same time as the eCCR itself.
heinrichsweikamp
parents:
756
diff
changeset
|
448 |
|
29d9b5bc7946
Revised automatic setpoint change. The proposed approach is essentially the approach used by most controllers of eCCR ('upshift' on descent, 'downshift' on ascent), so that the OSTC4 when used as a backup computer for eCCR will make the changes at the same time as the eCCR itself.
heinrichsweikamp
parents:
756
diff
changeset
|
449 |
|
29d9b5bc7946
Revised automatic setpoint change. The proposed approach is essentially the approach used by most controllers of eCCR ('upshift' on descent, 'downshift' on ascent), so that the OSTC4 when used as a backup computer for eCCR will make the changes at the same time as the eCCR itself.
heinrichsweikamp
parents:
756
diff
changeset
|
450 uint8_t getSetpointHighId(void) |
|
29d9b5bc7946
Revised automatic setpoint change. The proposed approach is essentially the approach used by most controllers of eCCR ('upshift' on descent, 'downshift' on ascent), so that the OSTC4 when used as a backup computer for eCCR will make the changes at the same time as the eCCR itself.
heinrichsweikamp
parents:
756
diff
changeset
|
451 { |
|
788
4abfb8a2a435
Define explicit setpoints for low / high / deco. Add an option to delay the switch to SPlow until all decompression has been cleared. (mikeller)
heinrichsweikamp
parents:
773
diff
changeset
|
452 SSettings *settings = settingsGetPointer(); |
|
4abfb8a2a435
Define explicit setpoints for low / high / deco. Add an option to delay the switch to SPlow until all decompression has been cleared. (mikeller)
heinrichsweikamp
parents:
773
diff
changeset
|
453 |
|
4abfb8a2a435
Define explicit setpoints for low / high / deco. Add an option to delay the switch to SPlow until all decompression has been cleared. (mikeller)
heinrichsweikamp
parents:
773
diff
changeset
|
454 if (settings->autoSetpoint) { |
|
4abfb8a2a435
Define explicit setpoints for low / high / deco. Add an option to delay the switch to SPlow until all decompression has been cleared. (mikeller)
heinrichsweikamp
parents:
773
diff
changeset
|
455 return SETPOINT_INDEX_AUTO_HIGH; |
|
4abfb8a2a435
Define explicit setpoints for low / high / deco. Add an option to delay the switch to SPlow until all decompression has been cleared. (mikeller)
heinrichsweikamp
parents:
773
diff
changeset
|
456 } |
|
4abfb8a2a435
Define explicit setpoints for low / high / deco. Add an option to delay the switch to SPlow until all decompression has been cleared. (mikeller)
heinrichsweikamp
parents:
773
diff
changeset
|
457 |
|
771
29d9b5bc7946
Revised automatic setpoint change. The proposed approach is essentially the approach used by most controllers of eCCR ('upshift' on descent, 'downshift' on ascent), so that the OSTC4 when used as a backup computer for eCCR will make the changes at the same time as the eCCR itself.
heinrichsweikamp
parents:
756
diff
changeset
|
458 uint8_t setpointHighId = 0; |
|
29d9b5bc7946
Revised automatic setpoint change. The proposed approach is essentially the approach used by most controllers of eCCR ('upshift' on descent, 'downshift' on ascent), so that the OSTC4 when used as a backup computer for eCCR will make the changes at the same time as the eCCR itself.
heinrichsweikamp
parents:
756
diff
changeset
|
459 uint8_t setpointHighDepthM = 0; |
|
29d9b5bc7946
Revised automatic setpoint change. The proposed approach is essentially the approach used by most controllers of eCCR ('upshift' on descent, 'downshift' on ascent), so that the OSTC4 when used as a backup computer for eCCR will make the changes at the same time as the eCCR itself.
heinrichsweikamp
parents:
756
diff
changeset
|
460 for (unsigned i = 1; i <= NUM_GASES; i++) { |
|
29d9b5bc7946
Revised automatic setpoint change. The proposed approach is essentially the approach used by most controllers of eCCR ('upshift' on descent, 'downshift' on ascent), so that the OSTC4 when used as a backup computer for eCCR will make the changes at the same time as the eCCR itself.
heinrichsweikamp
parents:
756
diff
changeset
|
461 if (stateUsed->diveSettings.setpoint[i].depth_meter && stateUsed->diveSettings.setpoint[i].depth_meter >= setpointHighDepthM) { |
|
29d9b5bc7946
Revised automatic setpoint change. The proposed approach is essentially the approach used by most controllers of eCCR ('upshift' on descent, 'downshift' on ascent), so that the OSTC4 when used as a backup computer for eCCR will make the changes at the same time as the eCCR itself.
heinrichsweikamp
parents:
756
diff
changeset
|
462 setpointHighId = i; |
|
29d9b5bc7946
Revised automatic setpoint change. The proposed approach is essentially the approach used by most controllers of eCCR ('upshift' on descent, 'downshift' on ascent), so that the OSTC4 when used as a backup computer for eCCR will make the changes at the same time as the eCCR itself.
heinrichsweikamp
parents:
756
diff
changeset
|
463 setpointHighDepthM = stateUsed->diveSettings.setpoint[i].depth_meter; |
|
29d9b5bc7946
Revised automatic setpoint change. The proposed approach is essentially the approach used by most controllers of eCCR ('upshift' on descent, 'downshift' on ascent), so that the OSTC4 when used as a backup computer for eCCR will make the changes at the same time as the eCCR itself.
heinrichsweikamp
parents:
756
diff
changeset
|
464 } |
|
29d9b5bc7946
Revised automatic setpoint change. The proposed approach is essentially the approach used by most controllers of eCCR ('upshift' on descent, 'downshift' on ascent), so that the OSTC4 when used as a backup computer for eCCR will make the changes at the same time as the eCCR itself.
heinrichsweikamp
parents:
756
diff
changeset
|
465 } |
|
29d9b5bc7946
Revised automatic setpoint change. The proposed approach is essentially the approach used by most controllers of eCCR ('upshift' on descent, 'downshift' on ascent), so that the OSTC4 when used as a backup computer for eCCR will make the changes at the same time as the eCCR itself.
heinrichsweikamp
parents:
756
diff
changeset
|
466 |
|
29d9b5bc7946
Revised automatic setpoint change. The proposed approach is essentially the approach used by most controllers of eCCR ('upshift' on descent, 'downshift' on ascent), so that the OSTC4 when used as a backup computer for eCCR will make the changes at the same time as the eCCR itself.
heinrichsweikamp
parents:
756
diff
changeset
|
467 return setpointHighId; |
|
29d9b5bc7946
Revised automatic setpoint change. The proposed approach is essentially the approach used by most controllers of eCCR ('upshift' on descent, 'downshift' on ascent), so that the OSTC4 when used as a backup computer for eCCR will make the changes at the same time as the eCCR itself.
heinrichsweikamp
parents:
756
diff
changeset
|
468 } |
| 38 | 469 |
| 662 | 470 |
|
788
4abfb8a2a435
Define explicit setpoints for low / high / deco. Add an option to delay the switch to SPlow until all decompression has been cleared. (mikeller)
heinrichsweikamp
parents:
773
diff
changeset
|
471 uint8_t getSetpointDecoId(void) |
|
4abfb8a2a435
Define explicit setpoints for low / high / deco. Add an option to delay the switch to SPlow until all decompression has been cleared. (mikeller)
heinrichsweikamp
parents:
773
diff
changeset
|
472 { |
|
4abfb8a2a435
Define explicit setpoints for low / high / deco. Add an option to delay the switch to SPlow until all decompression has been cleared. (mikeller)
heinrichsweikamp
parents:
773
diff
changeset
|
473 SSettings *settings = settingsGetPointer(); |
|
4abfb8a2a435
Define explicit setpoints for low / high / deco. Add an option to delay the switch to SPlow until all decompression has been cleared. (mikeller)
heinrichsweikamp
parents:
773
diff
changeset
|
474 |
|
4abfb8a2a435
Define explicit setpoints for low / high / deco. Add an option to delay the switch to SPlow until all decompression has been cleared. (mikeller)
heinrichsweikamp
parents:
773
diff
changeset
|
475 if (settings->autoSetpoint && stateUsed->diveSettings.setpoint[SETPOINT_INDEX_AUTO_DECO].note.ub.active) { |
|
4abfb8a2a435
Define explicit setpoints for low / high / deco. Add an option to delay the switch to SPlow until all decompression has been cleared. (mikeller)
heinrichsweikamp
parents:
773
diff
changeset
|
476 return SETPOINT_INDEX_AUTO_DECO; |
|
4abfb8a2a435
Define explicit setpoints for low / high / deco. Add an option to delay the switch to SPlow until all decompression has been cleared. (mikeller)
heinrichsweikamp
parents:
773
diff
changeset
|
477 } |
|
4abfb8a2a435
Define explicit setpoints for low / high / deco. Add an option to delay the switch to SPlow until all decompression has been cleared. (mikeller)
heinrichsweikamp
parents:
773
diff
changeset
|
478 |
|
4abfb8a2a435
Define explicit setpoints for low / high / deco. Add an option to delay the switch to SPlow until all decompression has been cleared. (mikeller)
heinrichsweikamp
parents:
773
diff
changeset
|
479 return 0; |
|
4abfb8a2a435
Define explicit setpoints for low / high / deco. Add an option to delay the switch to SPlow until all decompression has been cleared. (mikeller)
heinrichsweikamp
parents:
773
diff
changeset
|
480 } |
|
4abfb8a2a435
Define explicit setpoints for low / high / deco. Add an option to delay the switch to SPlow until all decompression has been cleared. (mikeller)
heinrichsweikamp
parents:
773
diff
changeset
|
481 |
|
4abfb8a2a435
Define explicit setpoints for low / high / deco. Add an option to delay the switch to SPlow until all decompression has been cleared. (mikeller)
heinrichsweikamp
parents:
773
diff
changeset
|
482 |
|
771
29d9b5bc7946
Revised automatic setpoint change. The proposed approach is essentially the approach used by most controllers of eCCR ('upshift' on descent, 'downshift' on ascent), so that the OSTC4 when used as a backup computer for eCCR will make the changes at the same time as the eCCR itself.
heinrichsweikamp
parents:
756
diff
changeset
|
483 /* check for better travel!!! setpoint hw 151210 |
|
29d9b5bc7946
Revised automatic setpoint change. The proposed approach is essentially the approach used by most controllers of eCCR ('upshift' on descent, 'downshift' on ascent), so that the OSTC4 when used as a backup computer for eCCR will make the changes at the same time as the eCCR itself.
heinrichsweikamp
parents:
756
diff
changeset
|
484 */ |
|
29d9b5bc7946
Revised automatic setpoint change. The proposed approach is essentially the approach used by most controllers of eCCR ('upshift' on descent, 'downshift' on ascent), so that the OSTC4 when used as a backup computer for eCCR will make the changes at the same time as the eCCR itself.
heinrichsweikamp
parents:
756
diff
changeset
|
485 static int8_t check_BetterSetpoint(SDiveState *diveState) |
|
29d9b5bc7946
Revised automatic setpoint change. The proposed approach is essentially the approach used by most controllers of eCCR ('upshift' on descent, 'downshift' on ascent), so that the OSTC4 when used as a backup computer for eCCR will make the changes at the same time as the eCCR itself.
heinrichsweikamp
parents:
756
diff
changeset
|
486 { |
|
29d9b5bc7946
Revised automatic setpoint change. The proposed approach is essentially the approach used by most controllers of eCCR ('upshift' on descent, 'downshift' on ascent), so that the OSTC4 when used as a backup computer for eCCR will make the changes at the same time as the eCCR itself.
heinrichsweikamp
parents:
756
diff
changeset
|
487 diveState->warnings.betterSetpoint = 0; |
|
29d9b5bc7946
Revised automatic setpoint change. The proposed approach is essentially the approach used by most controllers of eCCR ('upshift' on descent, 'downshift' on ascent), so that the OSTC4 when used as a backup computer for eCCR will make the changes at the same time as the eCCR itself.
heinrichsweikamp
parents:
756
diff
changeset
|
488 |
|
29d9b5bc7946
Revised automatic setpoint change. The proposed approach is essentially the approach used by most controllers of eCCR ('upshift' on descent, 'downshift' on ascent), so that the OSTC4 when used as a backup computer for eCCR will make the changes at the same time as the eCCR itself.
heinrichsweikamp
parents:
756
diff
changeset
|
489 if (stateUsed->mode != MODE_DIVE) { |
|
29d9b5bc7946
Revised automatic setpoint change. The proposed approach is essentially the approach used by most controllers of eCCR ('upshift' on descent, 'downshift' on ascent), so that the OSTC4 when used as a backup computer for eCCR will make the changes at the same time as the eCCR itself.
heinrichsweikamp
parents:
756
diff
changeset
|
490 betterSetpointId = 1; |
|
29d9b5bc7946
Revised automatic setpoint change. The proposed approach is essentially the approach used by most controllers of eCCR ('upshift' on descent, 'downshift' on ascent), so that the OSTC4 when used as a backup computer for eCCR will make the changes at the same time as the eCCR itself.
heinrichsweikamp
parents:
756
diff
changeset
|
491 |
|
29d9b5bc7946
Revised automatic setpoint change. The proposed approach is essentially the approach used by most controllers of eCCR ('upshift' on descent, 'downshift' on ascent), so that the OSTC4 when used as a backup computer for eCCR will make the changes at the same time as the eCCR itself.
heinrichsweikamp
parents:
756
diff
changeset
|
492 return 0; |
|
29d9b5bc7946
Revised automatic setpoint change. The proposed approach is essentially the approach used by most controllers of eCCR ('upshift' on descent, 'downshift' on ascent), so that the OSTC4 when used as a backup computer for eCCR will make the changes at the same time as the eCCR itself.
heinrichsweikamp
parents:
756
diff
changeset
|
493 } |
|
29d9b5bc7946
Revised automatic setpoint change. The proposed approach is essentially the approach used by most controllers of eCCR ('upshift' on descent, 'downshift' on ascent), so that the OSTC4 when used as a backup computer for eCCR will make the changes at the same time as the eCCR itself.
heinrichsweikamp
parents:
756
diff
changeset
|
494 |
|
29d9b5bc7946
Revised automatic setpoint change. The proposed approach is essentially the approach used by most controllers of eCCR ('upshift' on descent, 'downshift' on ascent), so that the OSTC4 when used as a backup computer for eCCR will make the changes at the same time as the eCCR itself.
heinrichsweikamp
parents:
756
diff
changeset
|
495 SSettings *settings = settingsGetPointer(); |
|
29d9b5bc7946
Revised automatic setpoint change. The proposed approach is essentially the approach used by most controllers of eCCR ('upshift' on descent, 'downshift' on ascent), so that the OSTC4 when used as a backup computer for eCCR will make the changes at the same time as the eCCR itself.
heinrichsweikamp
parents:
756
diff
changeset
|
496 |
|
29d9b5bc7946
Revised automatic setpoint change. The proposed approach is essentially the approach used by most controllers of eCCR ('upshift' on descent, 'downshift' on ascent), so that the OSTC4 when used as a backup computer for eCCR will make the changes at the same time as the eCCR itself.
heinrichsweikamp
parents:
756
diff
changeset
|
497 float currentDepthM = diveState->lifeData.depth_meter; |
|
788
4abfb8a2a435
Define explicit setpoints for low / high / deco. Add an option to delay the switch to SPlow until all decompression has been cleared. (mikeller)
heinrichsweikamp
parents:
773
diff
changeset
|
498 float lastChangeDepthM = diveState->lifeData.lastSetpointChangeDepthM; |
|
4abfb8a2a435
Define explicit setpoints for low / high / deco. Add an option to delay the switch to SPlow until all decompression has been cleared. (mikeller)
heinrichsweikamp
parents:
773
diff
changeset
|
499 if (settings->dive_mode == DIVEMODE_CCR && lastChangeDepthM != currentDepthM) { |
|
771
29d9b5bc7946
Revised automatic setpoint change. The proposed approach is essentially the approach used by most controllers of eCCR ('upshift' on descent, 'downshift' on ascent), so that the OSTC4 when used as a backup computer for eCCR will make the changes at the same time as the eCCR itself.
heinrichsweikamp
parents:
756
diff
changeset
|
500 bool descending = currentDepthM > lastChangeDepthM; |
|
29d9b5bc7946
Revised automatic setpoint change. The proposed approach is essentially the approach used by most controllers of eCCR ('upshift' on descent, 'downshift' on ascent), so that the OSTC4 when used as a backup computer for eCCR will make the changes at the same time as the eCCR itself.
heinrichsweikamp
parents:
756
diff
changeset
|
501 uint8_t betterSetpointIdLocal = 0; |
|
29d9b5bc7946
Revised automatic setpoint change. The proposed approach is essentially the approach used by most controllers of eCCR ('upshift' on descent, 'downshift' on ascent), so that the OSTC4 when used as a backup computer for eCCR will make the changes at the same time as the eCCR itself.
heinrichsweikamp
parents:
756
diff
changeset
|
502 |
|
788
4abfb8a2a435
Define explicit setpoints for low / high / deco. Add an option to delay the switch to SPlow until all decompression has been cleared. (mikeller)
heinrichsweikamp
parents:
773
diff
changeset
|
503 if (settings->autoSetpoint) { |
|
4abfb8a2a435
Define explicit setpoints for low / high / deco. Add an option to delay the switch to SPlow until all decompression has been cleared. (mikeller)
heinrichsweikamp
parents:
773
diff
changeset
|
504 bool decoSetpointEnabled = diveState->diveSettings.setpoint[SETPOINT_INDEX_AUTO_DECO].note.ub.active; |
|
4abfb8a2a435
Define explicit setpoints for low / high / deco. Add an option to delay the switch to SPlow until all decompression has been cleared. (mikeller)
heinrichsweikamp
parents:
773
diff
changeset
|
505 const SDecoinfo *decoInfo = getDecoInfo(); |
|
4abfb8a2a435
Define explicit setpoints for low / high / deco. Add an option to delay the switch to SPlow until all decompression has been cleared. (mikeller)
heinrichsweikamp
parents:
773
diff
changeset
|
506 uint8_t nextDecoStopDepthM; |
|
4abfb8a2a435
Define explicit setpoints for low / high / deco. Add an option to delay the switch to SPlow until all decompression has been cleared. (mikeller)
heinrichsweikamp
parents:
773
diff
changeset
|
507 uint16_t nextDecoStopTimeRemainingS; |
|
4abfb8a2a435
Define explicit setpoints for low / high / deco. Add an option to delay the switch to SPlow until all decompression has been cleared. (mikeller)
heinrichsweikamp
parents:
773
diff
changeset
|
508 tHome_findNextStop(decoInfo->output_stop_length_seconds, &nextDecoStopDepthM, &nextDecoStopTimeRemainingS); |
|
4abfb8a2a435
Define explicit setpoints for low / high / deco. Add an option to delay the switch to SPlow until all decompression has been cleared. (mikeller)
heinrichsweikamp
parents:
773
diff
changeset
|
509 |
|
4abfb8a2a435
Define explicit setpoints for low / high / deco. Add an option to delay the switch to SPlow until all decompression has been cleared. (mikeller)
heinrichsweikamp
parents:
773
diff
changeset
|
510 if (decoSetpointEnabled && nextDecoStopDepthM && currentDepthM < nextDecoStopDepthM + SETPOINT_DECO_START_RANGE_M && !diveState->lifeData.setpointDecoActivated) { |
|
4abfb8a2a435
Define explicit setpoints for low / high / deco. Add an option to delay the switch to SPlow until all decompression has been cleared. (mikeller)
heinrichsweikamp
parents:
773
diff
changeset
|
511 betterSetpointIdLocal = SETPOINT_INDEX_AUTO_DECO; |
|
4abfb8a2a435
Define explicit setpoints for low / high / deco. Add an option to delay the switch to SPlow until all decompression has been cleared. (mikeller)
heinrichsweikamp
parents:
773
diff
changeset
|
512 diveState->lifeData.setpointDecoActivated = true; |
|
771
29d9b5bc7946
Revised automatic setpoint change. The proposed approach is essentially the approach used by most controllers of eCCR ('upshift' on descent, 'downshift' on ascent), so that the OSTC4 when used as a backup computer for eCCR will make the changes at the same time as the eCCR itself.
heinrichsweikamp
parents:
756
diff
changeset
|
513 } |
|
29d9b5bc7946
Revised automatic setpoint change. The proposed approach is essentially the approach used by most controllers of eCCR ('upshift' on descent, 'downshift' on ascent), so that the OSTC4 when used as a backup computer for eCCR will make the changes at the same time as the eCCR itself.
heinrichsweikamp
parents:
756
diff
changeset
|
514 |
|
788
4abfb8a2a435
Define explicit setpoints for low / high / deco. Add an option to delay the switch to SPlow until all decompression has been cleared. (mikeller)
heinrichsweikamp
parents:
773
diff
changeset
|
515 if (descending) { |
|
4abfb8a2a435
Define explicit setpoints for low / high / deco. Add an option to delay the switch to SPlow until all decompression has been cleared. (mikeller)
heinrichsweikamp
parents:
773
diff
changeset
|
516 uint8_t switchDepthHighM = diveState->diveSettings.setpoint[SETPOINT_INDEX_AUTO_HIGH].depth_meter; |
|
4abfb8a2a435
Define explicit setpoints for low / high / deco. Add an option to delay the switch to SPlow until all decompression has been cleared. (mikeller)
heinrichsweikamp
parents:
773
diff
changeset
|
517 |
|
4abfb8a2a435
Define explicit setpoints for low / high / deco. Add an option to delay the switch to SPlow until all decompression has been cleared. (mikeller)
heinrichsweikamp
parents:
773
diff
changeset
|
518 if (lastChangeDepthM < switchDepthHighM && switchDepthHighM < currentDepthM && !diveState->lifeData.setpointDecoActivated) { |
|
4abfb8a2a435
Define explicit setpoints for low / high / deco. Add an option to delay the switch to SPlow until all decompression has been cleared. (mikeller)
heinrichsweikamp
parents:
773
diff
changeset
|
519 betterSetpointIdLocal = SETPOINT_INDEX_AUTO_HIGH; |
|
4abfb8a2a435
Define explicit setpoints for low / high / deco. Add an option to delay the switch to SPlow until all decompression has been cleared. (mikeller)
heinrichsweikamp
parents:
773
diff
changeset
|
520 } |
|
4abfb8a2a435
Define explicit setpoints for low / high / deco. Add an option to delay the switch to SPlow until all decompression has been cleared. (mikeller)
heinrichsweikamp
parents:
773
diff
changeset
|
521 } else { |
|
4abfb8a2a435
Define explicit setpoints for low / high / deco. Add an option to delay the switch to SPlow until all decompression has been cleared. (mikeller)
heinrichsweikamp
parents:
773
diff
changeset
|
522 uint8_t switchDepthLowM = diveState->diveSettings.setpoint[SETPOINT_INDEX_AUTO_LOW].depth_meter; |
|
4abfb8a2a435
Define explicit setpoints for low / high / deco. Add an option to delay the switch to SPlow until all decompression has been cleared. (mikeller)
heinrichsweikamp
parents:
773
diff
changeset
|
523 |
|
4abfb8a2a435
Define explicit setpoints for low / high / deco. Add an option to delay the switch to SPlow until all decompression has been cleared. (mikeller)
heinrichsweikamp
parents:
773
diff
changeset
|
524 if (lastChangeDepthM > SWITCH_DEPTH_LOW_MINIMUM_M && SWITCH_DEPTH_LOW_MINIMUM_M > currentDepthM) { |
|
4abfb8a2a435
Define explicit setpoints for low / high / deco. Add an option to delay the switch to SPlow until all decompression has been cleared. (mikeller)
heinrichsweikamp
parents:
773
diff
changeset
|
525 // Avoid draining the oxygen supply by surfacing with a setpoint >= 1.0 |
|
4abfb8a2a435
Define explicit setpoints for low / high / deco. Add an option to delay the switch to SPlow until all decompression has been cleared. (mikeller)
heinrichsweikamp
parents:
773
diff
changeset
|
526 betterSetpointIdLocal = SETPOINT_INDEX_AUTO_LOW; |
|
4abfb8a2a435
Define explicit setpoints for low / high / deco. Add an option to delay the switch to SPlow until all decompression has been cleared. (mikeller)
heinrichsweikamp
parents:
773
diff
changeset
|
527 diveState->lifeData.setpointLowDelayed = false; |
|
4abfb8a2a435
Define explicit setpoints for low / high / deco. Add an option to delay the switch to SPlow until all decompression has been cleared. (mikeller)
heinrichsweikamp
parents:
773
diff
changeset
|
528 } else if (lastChangeDepthM > switchDepthLowM && switchDepthLowM > currentDepthM) { |
|
4abfb8a2a435
Define explicit setpoints for low / high / deco. Add an option to delay the switch to SPlow until all decompression has been cleared. (mikeller)
heinrichsweikamp
parents:
773
diff
changeset
|
529 if (nextDecoStopDepthM && settings->delaySetpointLow) { |
|
4abfb8a2a435
Define explicit setpoints for low / high / deco. Add an option to delay the switch to SPlow until all decompression has been cleared. (mikeller)
heinrichsweikamp
parents:
773
diff
changeset
|
530 diveState->lifeData.setpointLowDelayed = true; |
|
4abfb8a2a435
Define explicit setpoints for low / high / deco. Add an option to delay the switch to SPlow until all decompression has been cleared. (mikeller)
heinrichsweikamp
parents:
773
diff
changeset
|
531 } else { |
|
4abfb8a2a435
Define explicit setpoints for low / high / deco. Add an option to delay the switch to SPlow until all decompression has been cleared. (mikeller)
heinrichsweikamp
parents:
773
diff
changeset
|
532 betterSetpointIdLocal = SETPOINT_INDEX_AUTO_LOW; |
|
4abfb8a2a435
Define explicit setpoints for low / high / deco. Add an option to delay the switch to SPlow until all decompression has been cleared. (mikeller)
heinrichsweikamp
parents:
773
diff
changeset
|
533 } |
|
4abfb8a2a435
Define explicit setpoints for low / high / deco. Add an option to delay the switch to SPlow until all decompression has been cleared. (mikeller)
heinrichsweikamp
parents:
773
diff
changeset
|
534 } |
|
4abfb8a2a435
Define explicit setpoints for low / high / deco. Add an option to delay the switch to SPlow until all decompression has been cleared. (mikeller)
heinrichsweikamp
parents:
773
diff
changeset
|
535 } |
|
4abfb8a2a435
Define explicit setpoints for low / high / deco. Add an option to delay the switch to SPlow until all decompression has been cleared. (mikeller)
heinrichsweikamp
parents:
773
diff
changeset
|
536 |
|
4abfb8a2a435
Define explicit setpoints for low / high / deco. Add an option to delay the switch to SPlow until all decompression has been cleared. (mikeller)
heinrichsweikamp
parents:
773
diff
changeset
|
537 if (!nextDecoStopDepthM) { |
|
4abfb8a2a435
Define explicit setpoints for low / high / deco. Add an option to delay the switch to SPlow until all decompression has been cleared. (mikeller)
heinrichsweikamp
parents:
773
diff
changeset
|
538 // Update the state when the decompression obligation ends |
|
4abfb8a2a435
Define explicit setpoints for low / high / deco. Add an option to delay the switch to SPlow until all decompression has been cleared. (mikeller)
heinrichsweikamp
parents:
773
diff
changeset
|
539 diveState->lifeData.setpointDecoActivated = false; |
|
4abfb8a2a435
Define explicit setpoints for low / high / deco. Add an option to delay the switch to SPlow until all decompression has been cleared. (mikeller)
heinrichsweikamp
parents:
773
diff
changeset
|
540 |
|
4abfb8a2a435
Define explicit setpoints for low / high / deco. Add an option to delay the switch to SPlow until all decompression has been cleared. (mikeller)
heinrichsweikamp
parents:
773
diff
changeset
|
541 if (diveState->lifeData.setpointLowDelayed) { |
|
4abfb8a2a435
Define explicit setpoints for low / high / deco. Add an option to delay the switch to SPlow until all decompression has been cleared. (mikeller)
heinrichsweikamp
parents:
773
diff
changeset
|
542 betterSetpointIdLocal = SETPOINT_INDEX_AUTO_LOW; |
|
4abfb8a2a435
Define explicit setpoints for low / high / deco. Add an option to delay the switch to SPlow until all decompression has been cleared. (mikeller)
heinrichsweikamp
parents:
773
diff
changeset
|
543 diveState->lifeData.setpointLowDelayed = false; |
|
4abfb8a2a435
Define explicit setpoints for low / high / deco. Add an option to delay the switch to SPlow until all decompression has been cleared. (mikeller)
heinrichsweikamp
parents:
773
diff
changeset
|
544 } |
|
4abfb8a2a435
Define explicit setpoints for low / high / deco. Add an option to delay the switch to SPlow until all decompression has been cleared. (mikeller)
heinrichsweikamp
parents:
773
diff
changeset
|
545 } |
|
4abfb8a2a435
Define explicit setpoints for low / high / deco. Add an option to delay the switch to SPlow until all decompression has been cleared. (mikeller)
heinrichsweikamp
parents:
773
diff
changeset
|
546 } else { |
|
4abfb8a2a435
Define explicit setpoints for low / high / deco. Add an option to delay the switch to SPlow until all decompression has been cleared. (mikeller)
heinrichsweikamp
parents:
773
diff
changeset
|
547 uint8_t setpointLowId = getSetpointLowId(); |
|
4abfb8a2a435
Define explicit setpoints for low / high / deco. Add an option to delay the switch to SPlow until all decompression has been cleared. (mikeller)
heinrichsweikamp
parents:
773
diff
changeset
|
548 uint8_t setpointHighId = getSetpointHighId(); |
|
4abfb8a2a435
Define explicit setpoints for low / high / deco. Add an option to delay the switch to SPlow until all decompression has been cleared. (mikeller)
heinrichsweikamp
parents:
773
diff
changeset
|
549 uint8_t betterSetpointSwitchDepthM = descending ? 0 : UINT8_MAX; |
|
4abfb8a2a435
Define explicit setpoints for low / high / deco. Add an option to delay the switch to SPlow until all decompression has been cleared. (mikeller)
heinrichsweikamp
parents:
773
diff
changeset
|
550 |
|
4abfb8a2a435
Define explicit setpoints for low / high / deco. Add an option to delay the switch to SPlow until all decompression has been cleared. (mikeller)
heinrichsweikamp
parents:
773
diff
changeset
|
551 for (unsigned i = 1; i <= NUM_GASES; i++) { |
|
4abfb8a2a435
Define explicit setpoints for low / high / deco. Add an option to delay the switch to SPlow until all decompression has been cleared. (mikeller)
heinrichsweikamp
parents:
773
diff
changeset
|
552 uint8_t switchDepthM = diveState->diveSettings.setpoint[i].depth_meter; |
|
4abfb8a2a435
Define explicit setpoints for low / high / deco. Add an option to delay the switch to SPlow until all decompression has been cleared. (mikeller)
heinrichsweikamp
parents:
773
diff
changeset
|
553 if (!switchDepthM || (descending && i == setpointLowId) || (!descending && i == setpointHighId)) { |
|
4abfb8a2a435
Define explicit setpoints for low / high / deco. Add an option to delay the switch to SPlow until all decompression has been cleared. (mikeller)
heinrichsweikamp
parents:
773
diff
changeset
|
554 continue; |
|
4abfb8a2a435
Define explicit setpoints for low / high / deco. Add an option to delay the switch to SPlow until all decompression has been cleared. (mikeller)
heinrichsweikamp
parents:
773
diff
changeset
|
555 } |
|
4abfb8a2a435
Define explicit setpoints for low / high / deco. Add an option to delay the switch to SPlow until all decompression has been cleared. (mikeller)
heinrichsweikamp
parents:
773
diff
changeset
|
556 |
|
4abfb8a2a435
Define explicit setpoints for low / high / deco. Add an option to delay the switch to SPlow until all decompression has been cleared. (mikeller)
heinrichsweikamp
parents:
773
diff
changeset
|
557 if ((descending && lastChangeDepthM < switchDepthM && switchDepthM < currentDepthM && switchDepthM > betterSetpointSwitchDepthM) |
|
4abfb8a2a435
Define explicit setpoints for low / high / deco. Add an option to delay the switch to SPlow until all decompression has been cleared. (mikeller)
heinrichsweikamp
parents:
773
diff
changeset
|
558 || (!descending && lastChangeDepthM > switchDepthM && switchDepthM > currentDepthM && switchDepthM <= betterSetpointSwitchDepthM)) { |
|
4abfb8a2a435
Define explicit setpoints for low / high / deco. Add an option to delay the switch to SPlow until all decompression has been cleared. (mikeller)
heinrichsweikamp
parents:
773
diff
changeset
|
559 betterSetpointIdLocal = i; |
|
4abfb8a2a435
Define explicit setpoints for low / high / deco. Add an option to delay the switch to SPlow until all decompression has been cleared. (mikeller)
heinrichsweikamp
parents:
773
diff
changeset
|
560 betterSetpointSwitchDepthM = switchDepthM; |
|
4abfb8a2a435
Define explicit setpoints for low / high / deco. Add an option to delay the switch to SPlow until all decompression has been cleared. (mikeller)
heinrichsweikamp
parents:
773
diff
changeset
|
561 } |
|
771
29d9b5bc7946
Revised automatic setpoint change. The proposed approach is essentially the approach used by most controllers of eCCR ('upshift' on descent, 'downshift' on ascent), so that the OSTC4 when used as a backup computer for eCCR will make the changes at the same time as the eCCR itself.
heinrichsweikamp
parents:
756
diff
changeset
|
562 } |
|
29d9b5bc7946
Revised automatic setpoint change. The proposed approach is essentially the approach used by most controllers of eCCR ('upshift' on descent, 'downshift' on ascent), so that the OSTC4 when used as a backup computer for eCCR will make the changes at the same time as the eCCR itself.
heinrichsweikamp
parents:
756
diff
changeset
|
563 } |
|
29d9b5bc7946
Revised automatic setpoint change. The proposed approach is essentially the approach used by most controllers of eCCR ('upshift' on descent, 'downshift' on ascent), so that the OSTC4 when used as a backup computer for eCCR will make the changes at the same time as the eCCR itself.
heinrichsweikamp
parents:
756
diff
changeset
|
564 |
|
29d9b5bc7946
Revised automatic setpoint change. The proposed approach is essentially the approach used by most controllers of eCCR ('upshift' on descent, 'downshift' on ascent), so that the OSTC4 when used as a backup computer for eCCR will make the changes at the same time as the eCCR itself.
heinrichsweikamp
parents:
756
diff
changeset
|
565 if (betterSetpointIdLocal) { |
|
29d9b5bc7946
Revised automatic setpoint change. The proposed approach is essentially the approach used by most controllers of eCCR ('upshift' on descent, 'downshift' on ascent), so that the OSTC4 when used as a backup computer for eCCR will make the changes at the same time as the eCCR itself.
heinrichsweikamp
parents:
756
diff
changeset
|
566 betterSetpointId = betterSetpointIdLocal; |
|
29d9b5bc7946
Revised automatic setpoint change. The proposed approach is essentially the approach used by most controllers of eCCR ('upshift' on descent, 'downshift' on ascent), so that the OSTC4 when used as a backup computer for eCCR will make the changes at the same time as the eCCR itself.
heinrichsweikamp
parents:
756
diff
changeset
|
567 if (diveState->diveSettings.diveMode == DIVEMODE_CCR && diveState->diveSettings.setpoint[betterSetpointIdLocal].setpoint_cbar != diveState->lifeData.actualGas.setPoint_cbar) { |
|
29d9b5bc7946
Revised automatic setpoint change. The proposed approach is essentially the approach used by most controllers of eCCR ('upshift' on descent, 'downshift' on ascent), so that the OSTC4 when used as a backup computer for eCCR will make the changes at the same time as the eCCR itself.
heinrichsweikamp
parents:
756
diff
changeset
|
568 diveState->warnings.betterSetpoint = 1; |
|
29d9b5bc7946
Revised automatic setpoint change. The proposed approach is essentially the approach used by most controllers of eCCR ('upshift' on descent, 'downshift' on ascent), so that the OSTC4 when used as a backup computer for eCCR will make the changes at the same time as the eCCR itself.
heinrichsweikamp
parents:
756
diff
changeset
|
569 } |
|
29d9b5bc7946
Revised automatic setpoint change. The proposed approach is essentially the approach used by most controllers of eCCR ('upshift' on descent, 'downshift' on ascent), so that the OSTC4 when used as a backup computer for eCCR will make the changes at the same time as the eCCR itself.
heinrichsweikamp
parents:
756
diff
changeset
|
570 } |
|
29d9b5bc7946
Revised automatic setpoint change. The proposed approach is essentially the approach used by most controllers of eCCR ('upshift' on descent, 'downshift' on ascent), so that the OSTC4 when used as a backup computer for eCCR will make the changes at the same time as the eCCR itself.
heinrichsweikamp
parents:
756
diff
changeset
|
571 } |
|
29d9b5bc7946
Revised automatic setpoint change. The proposed approach is essentially the approach used by most controllers of eCCR ('upshift' on descent, 'downshift' on ascent), so that the OSTC4 when used as a backup computer for eCCR will make the changes at the same time as the eCCR itself.
heinrichsweikamp
parents:
756
diff
changeset
|
572 |
|
29d9b5bc7946
Revised automatic setpoint change. The proposed approach is essentially the approach used by most controllers of eCCR ('upshift' on descent, 'downshift' on ascent), so that the OSTC4 when used as a backup computer for eCCR will make the changes at the same time as the eCCR itself.
heinrichsweikamp
parents:
756
diff
changeset
|
573 return diveState->warnings.betterSetpoint; |
| 38 | 574 } |
| 575 | |
| 576 | |
| 577 /* hw 151030 | |
| 578 */ | |
|
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
579 static int8_t check_helper_same_oxygen_and_helium_content(SGasLine * gas1, SGasLine * gas2) |
| 38 | 580 { |
| 581 if(gas1->helium_percentage != gas2->helium_percentage) | |
| 582 return 0; | |
| 583 else | |
| 584 if(gas1->oxygen_percentage != gas2->oxygen_percentage) | |
| 585 return 0; | |
| 586 else | |
| 587 return 1; | |
| 588 } | |
| 589 | |
| 590 | |
|
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
591 static int8_t check_CNS(SDiveState * pDiveState) |
| 38 | 592 { |
| 593 if(stateUsed->mode != MODE_DIVE) | |
| 594 { | |
| 595 pDiveState->warnings.cnsHigh = 0; | |
| 596 return 0; | |
| 597 } | |
| 598 | |
| 599 if(pDiveState->lifeData.cns >= (float)(settingsGetPointer()->CNS_max)) | |
| 600 pDiveState->warnings.cnsHigh = 1; | |
| 601 else | |
| 602 pDiveState->warnings.cnsHigh = 0; | |
| 603 return pDiveState->warnings.cnsHigh; | |
| 604 } | |
| 605 | |
| 606 | |
|
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
607 static int8_t check_Battery(SDiveState * pDiveState) |
| 38 | 608 { |
|
671
b456be1e152d
Support of unknown charging counter values:
Ideenmodellierer
parents:
662
diff
changeset
|
609 if((pDiveState->lifeData.battery_charge > 0) && (pDiveState->lifeData.battery_charge < 10)) |
| 38 | 610 pDiveState->warnings.lowBattery = 1; |
| 611 else | |
| 612 pDiveState->warnings.lowBattery = 0; | |
| 613 | |
| 614 return pDiveState->warnings.lowBattery; | |
| 615 } | |
| 616 | |
| 617 | |
|
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
618 static int8_t check_Deco(SDiveState * pDiveState) |
| 38 | 619 { |
| 620 if(stateUsed->mode != MODE_DIVE) | |
| 621 { | |
| 622 pDiveState->warnings.decoMissed = 0; | |
| 623 return 0; | |
| 624 } | |
| 625 | |
| 626 uint8_t depthNext = decom_get_actual_deco_stop(pDiveState); | |
| 627 | |
| 628 if(!depthNext) | |
| 629 pDiveState->warnings.decoMissed = 0; | |
| 630 else | |
| 631 if(pDiveState->lifeData.depth_meter + 0.1f < (float)depthNext) | |
| 632 pDiveState->warnings.decoMissed = 1; | |
| 633 else | |
| 634 pDiveState->warnings.decoMissed = 0; | |
| 635 | |
| 636 return pDiveState->warnings.decoMissed; | |
| 637 } | |
| 638 | |
| 639 | |
|
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
640 static int8_t check_AscentRate(SDiveState * pDiveState) |
| 38 | 641 { |
| 642 if(stateUsed->mode != MODE_DIVE) | |
| 643 { | |
| 644 pDiveState->warnings.ascentRateHigh = 0; | |
| 645 return 0; | |
| 646 } | |
| 647 | |
| 648 float warnAscentRateFloat; | |
| 649 | |
| 650 warnAscentRateFloat = (float)(settingsGetPointer()->ascent_MeterPerMinute_max); | |
| 651 | |
| 652 if(pDiveState->lifeData.ascent_rate_meter_per_min >= warnAscentRateFloat) | |
| 653 pDiveState->warnings.ascentRateHigh = 1; | |
| 654 else | |
| 655 pDiveState->warnings.ascentRateHigh = 0; | |
| 656 return pDiveState->warnings.ascentRateHigh; | |
| 657 } | |
| 658 | |
| 659 | |
|
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
660 static int8_t check_aGF(SDiveState * pDiveState) |
| 38 | 661 { |
| 662 if(stateUsed->mode != MODE_DIVE) | |
| 663 { | |
| 664 pDiveState->warnings.aGf = 0; | |
| 665 return 0; | |
| 666 } | |
| 667 | |
| 668 pDiveState->warnings.aGf = 0; | |
| 669 if(pDiveState->diveSettings.deco_type.ub.standard == GF_MODE) | |
| 670 { | |
| 671 if((pDiveState->diveSettings.gf_high != settingsGetPointer()->GF_high) || (pDiveState->diveSettings.gf_low != settingsGetPointer()->GF_low)) | |
| 672 pDiveState->warnings.aGf = 1; | |
| 673 } | |
| 674 return pDiveState->warnings.aGf; | |
| 675 } | |
| 676 | |
|
478
58200d756365
Development option only: Show Pressure update for a short time in the custom field (as warning)
ideenmodellierer
parents:
272
diff
changeset
|
677 #ifdef ENABLE_BOTTLE_SENSOR |
|
58200d756365
Development option only: Show Pressure update for a short time in the custom field (as warning)
ideenmodellierer
parents:
272
diff
changeset
|
678 static int8_t check_pressureSensor(SDiveState * pDiveState) |
|
58200d756365
Development option only: Show Pressure update for a short time in the custom field (as warning)
ideenmodellierer
parents:
272
diff
changeset
|
679 { |
|
58200d756365
Development option only: Show Pressure update for a short time in the custom field (as warning)
ideenmodellierer
parents:
272
diff
changeset
|
680 int8_t ret = 0; |
|
58200d756365
Development option only: Show Pressure update for a short time in the custom field (as warning)
ideenmodellierer
parents:
272
diff
changeset
|
681 if(pDiveState->lifeData.bottle_bar_age_MilliSeconds[pDiveState->lifeData.actualGas.GasIdInSettings] < 50) /* we received a new value */ |
|
58200d756365
Development option only: Show Pressure update for a short time in the custom field (as warning)
ideenmodellierer
parents:
272
diff
changeset
|
682 { |
|
58200d756365
Development option only: Show Pressure update for a short time in the custom field (as warning)
ideenmodellierer
parents:
272
diff
changeset
|
683 pDiveState->warnings.newPressure = stateUsed->lifeData.bottle_bar[stateUsed->lifeData.actualGas.GasIdInSettings]; |
|
58200d756365
Development option only: Show Pressure update for a short time in the custom field (as warning)
ideenmodellierer
parents:
272
diff
changeset
|
684 ret = 1; |
|
58200d756365
Development option only: Show Pressure update for a short time in the custom field (as warning)
ideenmodellierer
parents:
272
diff
changeset
|
685 } |
|
58200d756365
Development option only: Show Pressure update for a short time in the custom field (as warning)
ideenmodellierer
parents:
272
diff
changeset
|
686 else |
|
58200d756365
Development option only: Show Pressure update for a short time in the custom field (as warning)
ideenmodellierer
parents:
272
diff
changeset
|
687 { |
|
58200d756365
Development option only: Show Pressure update for a short time in the custom field (as warning)
ideenmodellierer
parents:
272
diff
changeset
|
688 pDiveState->warnings.newPressure = 0; |
|
58200d756365
Development option only: Show Pressure update for a short time in the custom field (as warning)
ideenmodellierer
parents:
272
diff
changeset
|
689 } |
|
58200d756365
Development option only: Show Pressure update for a short time in the custom field (as warning)
ideenmodellierer
parents:
272
diff
changeset
|
690 return ret; |
|
58200d756365
Development option only: Show Pressure update for a short time in the custom field (as warning)
ideenmodellierer
parents:
272
diff
changeset
|
691 } |
|
58200d756365
Development option only: Show Pressure update for a short time in the custom field (as warning)
ideenmodellierer
parents:
272
diff
changeset
|
692 #endif |
| 636 | 693 |
| 756 | 694 #ifdef ENABLE_CO2_SUPPORT |
| 695 static int8_t check_co2(SDiveState * pDiveState) | |
| 696 { | |
| 831 | 697 if((pDiveState->mode != MODE_DIVE) || (settingsGetPointer()->co2_sensor_active == 0)) |
| 756 | 698 { |
| 699 pDiveState->warnings.co2High = 0; | |
| 700 } | |
| 701 else | |
| 702 { | |
| 703 if(pDiveState->lifeData.CO2_data.CO2_ppm > CO2_ALARM_LEVEL_PPM) | |
| 704 { | |
| 705 pDiveState->warnings.co2High = 1; | |
| 706 } | |
| 707 else | |
| 708 { | |
| 709 pDiveState->warnings.co2High = 0; | |
| 710 } | |
| 711 } | |
| 712 return pDiveState->warnings.co2High; | |
| 713 } | |
| 714 #endif | |
| 715 | |
| 857 | 716 #ifdef HAVE_DEBUG_WARNINGS |
| 717 static int8_t check_debug(SDiveState * pDiveState) | |
| 718 { | |
| 719 uint8_t index = 0; | |
| 720 | |
| 721 pDiveState->warnings.debug = 0; | |
| 722 | |
| 723 if((settingsGetPointer()->ppo2sensors_source == O2_SENSOR_SOURCE_DIGITAL) || (settingsGetPointer()->ppo2sensors_source == O2_SENSOR_SOURCE_ANADIG)) | |
| 724 { | |
| 725 for(index=0; index<3; index++) | |
| 726 { | |
| 727 if(((pDiveState->lifeData.extIf_sensor_map[index] == SENSOR_DIGO2M) && (((SSensorDataDiveO2*)(stateUsed->lifeData.extIf_sensor_data[index]))->status & DVO2_FATAL_ERROR))) | |
| 728 { | |
| 729 pDiveState->warnings.debug = 1; | |
| 730 } | |
| 731 } | |
| 732 } | |
| 733 return pDiveState->warnings.debug; | |
| 734 } | |
| 735 #endif | |
| 736 | |
| 636 | 737 uint8_t debounce_warning_fallback(uint16_t debounceStepms) |
| 738 { | |
| 739 uint8_t retVal = 0; | |
| 740 | |
| 741 debounceFallbackTimeMS += debounceStepms; | |
| 742 if(debounceFallbackTimeMS > DEBOUNCE_FALLBACK_TIME_MS) | |
| 743 { | |
| 744 debounceFallbackTimeMS = DEBOUNCE_FALLBACK_TIME_MS; | |
| 745 retVal = 1; | |
| 746 } | |
| 747 return retVal; | |
| 748 } | |
| 749 void reset_debounce_warning_fallback() | |
| 750 { | |
| 751 debounceFallbackTimeMS = 0; | |
| 752 } | |
| 38 | 753 /************************ (C) COPYRIGHT heinrichs weikamp *****END OF FILE****/ |
| 754 |
