Mercurial > public > ostc4
annotate Discovery/Src/check_warning.c @ 785:3c0b16473af4
Change support from Pyroscience -> DiveO2 sensors
author | heinrichsweikamp |
---|---|
date | Wed, 31 May 2023 08:44:07 +0200 |
parents | 2c243233c999 |
children | 4abfb8a2a435 |
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" | |
42 | |
636 | 43 |
44 #define DEBOUNCE_FALLBACK_TIME_MS (5000u) /* set warning after 5 seconds of pending error condition */ | |
45 | |
756 | 46 |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
47 /* Private variables with access ----------------------------------------------*/ |
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
48 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
|
49 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
|
50 static uint8_t betterSetpointId = 1; |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
51 static int8_t fallback = 0; |
636 | 52 static uint16_t debounceFallbackTimeMS = 0; |
38 | 53 |
54 /* Private function prototypes -----------------------------------------------*/ | |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
55 static int8_t check_fallback(SDiveState * pDiveState); |
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
56 static int8_t check_ppO2(SDiveState * pDiveState); |
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
57 static int8_t check_O2_sensors(SDiveState * pDiveState); |
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
58 static int8_t check_CNS(SDiveState * pDiveState); |
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
59 static int8_t check_Deco(SDiveState * pDiveState); |
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
60 static int8_t check_AscentRate(SDiveState * pDiveState); |
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
61 static int8_t check_aGF(SDiveState * pDiveState); |
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
62 static int8_t check_BetterGas(SDiveState * pDiveState); |
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
63 static int8_t check_BetterSetpoint(SDiveState * pDiveState); |
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
64 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
|
65 #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
|
66 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
|
67 #endif |
756 | 68 #ifdef ENABLE_CO2_SUPPORT |
69 static int8_t check_co2(SDiveState * pDiveState); | |
70 #endif | |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
71 static int8_t check_helper_same_oxygen_and_helium_content(SGasLine * gas1, SGasLine * gas2); |
38 | 72 |
73 /* Exported functions --------------------------------------------------------*/ | |
74 | |
75 void check_warning(void) | |
76 { | |
272
74a8296a2318
cleanup: simplify stateUsed usage
Jan Mulder <jlmulder@xs4all.nl>
parents:
268
diff
changeset
|
77 check_warning2(stateUsedWrite); |
38 | 78 } |
79 | |
80 | |
81 void check_warning2(SDiveState * pDiveState) | |
82 { | |
83 pDiveState->warnings.numWarnings = 0; | |
84 | |
85 pDiveState->warnings.numWarnings += check_aGF(pDiveState); | |
86 pDiveState->warnings.numWarnings += check_AscentRate(pDiveState); | |
87 pDiveState->warnings.numWarnings += check_CNS(pDiveState); | |
88 pDiveState->warnings.numWarnings += check_Deco(pDiveState); | |
89 pDiveState->warnings.numWarnings += check_ppO2(pDiveState); | |
90 pDiveState->warnings.numWarnings += check_O2_sensors(pDiveState); | |
91 pDiveState->warnings.numWarnings += check_BetterGas(pDiveState); | |
92 pDiveState->warnings.numWarnings += check_BetterSetpoint(pDiveState); | |
93 pDiveState->warnings.numWarnings += check_Battery(pDiveState); | |
94 pDiveState->warnings.numWarnings += check_fallback(pDiveState); | |
478
58200d756365
Development option only: Show Pressure update for a short time in the custom field (as warning)
ideenmodellierer
parents:
272
diff
changeset
|
95 #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
|
96 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
|
97 #endif |
756 | 98 #ifdef ENABLE_CO2_SUPPORT |
99 pDiveState->warnings.numWarnings += check_co2(pDiveState); | |
100 #endif | |
38 | 101 } |
102 | |
103 | |
104 void set_warning_fallback(void) | |
105 { | |
106 fallback = 1; | |
107 } | |
108 | |
109 | |
110 void clear_warning_fallback(void) | |
111 { | |
112 fallback = 0; | |
636 | 113 debounceFallbackTimeMS = 0; |
38 | 114 } |
115 | |
116 | |
117 uint8_t actualBetterGasId(void) | |
118 { | |
119 return betterGasId; | |
120 } | |
121 | |
122 | |
773
2c243233c999
Menu shortcut for bailout / return to circuit when diving in CCR mode (mikeller)
heinrichsweikamp
parents:
771
diff
changeset
|
123 uint8_t actualBetterBailoutGasId(void) |
2c243233c999
Menu shortcut for bailout / return to circuit when diving in CCR mode (mikeller)
heinrichsweikamp
parents:
771
diff
changeset
|
124 { |
2c243233c999
Menu shortcut for bailout / return to circuit when diving in CCR mode (mikeller)
heinrichsweikamp
parents:
771
diff
changeset
|
125 return betterBailoutGasId; |
2c243233c999
Menu shortcut for bailout / return to circuit when diving in CCR mode (mikeller)
heinrichsweikamp
parents:
771
diff
changeset
|
126 } |
2c243233c999
Menu shortcut for bailout / return to circuit when diving in CCR mode (mikeller)
heinrichsweikamp
parents:
771
diff
changeset
|
127 |
2c243233c999
Menu shortcut for bailout / return to circuit when diving in CCR mode (mikeller)
heinrichsweikamp
parents:
771
diff
changeset
|
128 |
38 | 129 uint8_t actualBetterSetpointId(void) |
130 { | |
131 return betterSetpointId; | |
132 } | |
133 | |
134 | |
135 uint8_t actualLeftMaxDepth(const SDiveState * pDiveState) | |
136 { | |
137 if(pDiveState->lifeData.depth_meter > (pDiveState->lifeData.max_depth_meter - 3.0f)) | |
138 return 0; | |
139 else | |
140 return 1; | |
141 } | |
142 | |
143 | |
144 /* Private functions ---------------------------------------------------------*/ | |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
145 static int8_t check_fallback(SDiveState * pDiveState) |
38 | 146 { |
662 | 147 if(fallback && ((pDiveState->mode != MODE_DIVE) || (!isLoopMode(pDiveState->diveSettings.diveMode)))) |
38 | 148 fallback = 0; |
149 | |
150 pDiveState->warnings.fallback = fallback; | |
151 return pDiveState->warnings.fallback; | |
152 } | |
153 | |
154 | |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
155 static int8_t check_ppO2(SDiveState * pDiveState) |
38 | 156 { |
582
64bf41faab83
Show Fallback if no valid sensor value is available:
Ideenmodellierer
parents:
563
diff
changeset
|
157 if((pDiveState->mode != MODE_DIVE) || (pDiveState->warnings.fallback)) |
38 | 158 { |
159 pDiveState->warnings.ppO2Low = 0; | |
160 pDiveState->warnings.ppO2High = 0; | |
161 return 0; | |
162 } | |
163 | |
164 uint8_t localPPO2, testPPO2high; | |
165 | |
166 if(pDiveState->lifeData.ppO2 < 0) | |
167 localPPO2 = 0; | |
168 else | |
169 if(pDiveState->lifeData.ppO2 >= 2.5f) | |
170 localPPO2 = 255; | |
171 else | |
172 localPPO2 = (uint8_t)(pDiveState->lifeData.ppO2 * 100); | |
173 | |
174 if((localPPO2 + 1) <= settingsGetPointer()->ppO2_min) | |
175 pDiveState->warnings.ppO2Low = 1; | |
176 else | |
177 pDiveState->warnings.ppO2Low = 0; | |
178 | |
179 if(actualLeftMaxDepth(pDiveState)) | |
180 testPPO2high = settingsGetPointer()->ppO2_max_deco; | |
181 else | |
182 testPPO2high = settingsGetPointer()->ppO2_max_std; | |
183 | |
184 if(localPPO2 >= (testPPO2high + 1)) | |
185 pDiveState->warnings.ppO2High = 1; | |
186 else | |
187 pDiveState->warnings.ppO2High = 0; | |
188 | |
189 return pDiveState->warnings.ppO2Low + pDiveState->warnings.ppO2High; | |
190 } | |
191 | |
192 | |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
193 static int8_t check_O2_sensors(SDiveState * pDiveState) |
38 | 194 { |
195 pDiveState->warnings.sensorLinkLost = 0; | |
196 pDiveState->warnings.sensorOutOfBounds[0] = 0; | |
197 pDiveState->warnings.sensorOutOfBounds[1] = 0; | |
198 pDiveState->warnings.sensorOutOfBounds[2] = 0; | |
199 | |
662 | 200 if(isLoopMode(pDiveState->diveSettings.diveMode) && (pDiveState->diveSettings.CCR_Mode == CCRMODE_Sensors)) |
563 | 201 |
202 if(settingsGetPointer()->ppo2sensors_source == O2_SENSOR_SOURCE_OPTIC) | |
203 { | |
204 { | |
205 if(!get_HUD_battery_voltage_V()) | |
206 pDiveState->warnings.sensorLinkLost = 1; | |
207 } | |
208 } | |
634 | 209 test_O2_sensor_values_outOfBounds(&pDiveState->warnings.sensorOutOfBounds[0], &pDiveState->warnings.sensorOutOfBounds[1], &pDiveState->warnings.sensorOutOfBounds[2]); |
38 | 210 return pDiveState->warnings.sensorLinkLost |
211 + pDiveState->warnings.sensorOutOfBounds[0] | |
212 + pDiveState->warnings.sensorOutOfBounds[1] | |
213 + pDiveState->warnings.sensorOutOfBounds[2]; | |
214 } | |
215 | |
216 | |
773
2c243233c999
Menu shortcut for bailout / return to circuit when diving in CCR mode (mikeller)
heinrichsweikamp
parents:
771
diff
changeset
|
217 static uint8_t getBetterGasId(bool getDiluent, uint8_t startingGasId, SDiveState *diveState) |
38 | 218 { |
773
2c243233c999
Menu shortcut for bailout / return to circuit when diving in CCR mode (mikeller)
heinrichsweikamp
parents:
771
diff
changeset
|
219 SDiveSettings diveSettings = diveState->diveSettings; |
38 | 220 |
773
2c243233c999
Menu shortcut for bailout / return to circuit when diving in CCR mode (mikeller)
heinrichsweikamp
parents:
771
diff
changeset
|
221 uint8_t betterGasIdLocal = startingGasId; |
2c243233c999
Menu shortcut for bailout / return to circuit when diving in CCR mode (mikeller)
heinrichsweikamp
parents:
771
diff
changeset
|
222 uint8_t bestGasDepth = 255; |
38 | 223 |
773
2c243233c999
Menu shortcut for bailout / return to circuit when diving in CCR mode (mikeller)
heinrichsweikamp
parents:
771
diff
changeset
|
224 uint8_t gasIdOffset; |
2c243233c999
Menu shortcut for bailout / return to circuit when diving in CCR mode (mikeller)
heinrichsweikamp
parents:
771
diff
changeset
|
225 if (getDiluent) { |
2c243233c999
Menu shortcut for bailout / return to circuit when diving in CCR mode (mikeller)
heinrichsweikamp
parents:
771
diff
changeset
|
226 gasIdOffset = NUM_OFFSET_DILUENT; |
2c243233c999
Menu shortcut for bailout / return to circuit when diving in CCR mode (mikeller)
heinrichsweikamp
parents:
771
diff
changeset
|
227 } else { |
2c243233c999
Menu shortcut for bailout / return to circuit when diving in CCR mode (mikeller)
heinrichsweikamp
parents:
771
diff
changeset
|
228 gasIdOffset = 0; |
2c243233c999
Menu shortcut for bailout / return to circuit when diving in CCR mode (mikeller)
heinrichsweikamp
parents:
771
diff
changeset
|
229 } |
38 | 230 |
231 /* 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
|
232 if (actualLeftMaxDepth(diveState)) { /* deco gases */ |
2c243233c999
Menu shortcut for bailout / return to circuit when diving in CCR mode (mikeller)
heinrichsweikamp
parents:
771
diff
changeset
|
233 for (int i=1+gasIdOffset; i<= 5+gasIdOffset; i++) { |
2c243233c999
Menu shortcut for bailout / return to circuit when diving in CCR mode (mikeller)
heinrichsweikamp
parents:
771
diff
changeset
|
234 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
|
235 && (diveSettings.gas[i].note.ub.deco) |
2c243233c999
Menu shortcut for bailout / return to circuit when diving in CCR mode (mikeller)
heinrichsweikamp
parents:
771
diff
changeset
|
236 && (diveSettings.gas[i].depth_meter) |
2c243233c999
Menu shortcut for bailout / return to circuit when diving in CCR mode (mikeller)
heinrichsweikamp
parents:
771
diff
changeset
|
237 && (diveSettings.gas[i].depth_meter >= (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
|
238 && (diveSettings.gas[i].depth_meter <= bestGasDepth)) { |
2c243233c999
Menu shortcut for bailout / return to circuit when diving in CCR mode (mikeller)
heinrichsweikamp
parents:
771
diff
changeset
|
239 betterGasIdLocal = i; |
2c243233c999
Menu shortcut for bailout / return to circuit when diving in CCR mode (mikeller)
heinrichsweikamp
parents:
771
diff
changeset
|
240 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
|
241 } |
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 } else { /* travel gases */ |
2c243233c999
Menu shortcut for bailout / return to circuit when diving in CCR mode (mikeller)
heinrichsweikamp
parents:
771
diff
changeset
|
244 bestGasDepth = 0; |
2c243233c999
Menu shortcut for bailout / return to circuit when diving in CCR mode (mikeller)
heinrichsweikamp
parents:
771
diff
changeset
|
245 //check for travalgas |
2c243233c999
Menu shortcut for bailout / return to circuit when diving in CCR mode (mikeller)
heinrichsweikamp
parents:
771
diff
changeset
|
246 for (int i = 1 + gasIdOffset; i <= 5 + gasIdOffset; i++) { |
2c243233c999
Menu shortcut for bailout / return to circuit when diving in CCR mode (mikeller)
heinrichsweikamp
parents:
771
diff
changeset
|
247 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
|
248 && (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
|
249 && (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
|
250 && (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
|
251 && (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
|
252 betterGasIdLocal = i; |
2c243233c999
Menu shortcut for bailout / return to circuit when diving in CCR mode (mikeller)
heinrichsweikamp
parents:
771
diff
changeset
|
253 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
|
254 } |
38 | 255 } |
256 } | |
257 | |
773
2c243233c999
Menu shortcut for bailout / return to circuit when diving in CCR mode (mikeller)
heinrichsweikamp
parents:
771
diff
changeset
|
258 return betterGasIdLocal; |
2c243233c999
Menu shortcut for bailout / return to circuit when diving in CCR mode (mikeller)
heinrichsweikamp
parents:
771
diff
changeset
|
259 } |
2c243233c999
Menu shortcut for bailout / return to circuit when diving in CCR mode (mikeller)
heinrichsweikamp
parents:
771
diff
changeset
|
260 |
2c243233c999
Menu shortcut for bailout / return to circuit when diving in CCR mode (mikeller)
heinrichsweikamp
parents:
771
diff
changeset
|
261 |
2c243233c999
Menu shortcut for bailout / return to circuit when diving in CCR mode (mikeller)
heinrichsweikamp
parents:
771
diff
changeset
|
262 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
|
263 { |
2c243233c999
Menu shortcut for bailout / return to circuit when diving in CCR mode (mikeller)
heinrichsweikamp
parents:
771
diff
changeset
|
264 diveState->warnings.betterGas = 0; |
2c243233c999
Menu shortcut for bailout / return to circuit when diving in CCR mode (mikeller)
heinrichsweikamp
parents:
771
diff
changeset
|
265 |
2c243233c999
Menu shortcut for bailout / return to circuit when diving in CCR mode (mikeller)
heinrichsweikamp
parents:
771
diff
changeset
|
266 if (stateUsed->mode != MODE_DIVE) { |
2c243233c999
Menu shortcut for bailout / return to circuit when diving in CCR mode (mikeller)
heinrichsweikamp
parents:
771
diff
changeset
|
267 betterGasId = 0; |
2c243233c999
Menu shortcut for bailout / return to circuit when diving in CCR mode (mikeller)
heinrichsweikamp
parents:
771
diff
changeset
|
268 |
2c243233c999
Menu shortcut for bailout / return to circuit when diving in CCR mode (mikeller)
heinrichsweikamp
parents:
771
diff
changeset
|
269 return 0; |
38 | 270 } |
773
2c243233c999
Menu shortcut for bailout / return to circuit when diving in CCR mode (mikeller)
heinrichsweikamp
parents:
771
diff
changeset
|
271 |
2c243233c999
Menu shortcut for bailout / return to circuit when diving in CCR mode (mikeller)
heinrichsweikamp
parents:
771
diff
changeset
|
272 SDiveSettings diveSettings = diveState->diveSettings; |
2c243233c999
Menu shortcut for bailout / return to circuit when diving in CCR mode (mikeller)
heinrichsweikamp
parents:
771
diff
changeset
|
273 SLifeData lifeData = diveState->lifeData; |
2c243233c999
Menu shortcut for bailout / return to circuit when diving in CCR mode (mikeller)
heinrichsweikamp
parents:
771
diff
changeset
|
274 |
2c243233c999
Menu shortcut for bailout / return to circuit when diving in CCR mode (mikeller)
heinrichsweikamp
parents:
771
diff
changeset
|
275 if (isLoopMode(diveSettings.diveMode)) { |
2c243233c999
Menu shortcut for bailout / return to circuit when diving in CCR mode (mikeller)
heinrichsweikamp
parents:
771
diff
changeset
|
276 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
|
277 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
|
278 } else { |
2c243233c999
Menu shortcut for bailout / return to circuit when diving in CCR mode (mikeller)
heinrichsweikamp
parents:
771
diff
changeset
|
279 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
|
280 } |
2c243233c999
Menu shortcut for bailout / return to circuit when diving in CCR mode (mikeller)
heinrichsweikamp
parents:
771
diff
changeset
|
281 |
2c243233c999
Menu shortcut for bailout / return to circuit when diving in CCR mode (mikeller)
heinrichsweikamp
parents:
771
diff
changeset
|
282 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
|
283 diveState->warnings.betterGas = 1; |
2c243233c999
Menu shortcut for bailout / return to circuit when diving in CCR mode (mikeller)
heinrichsweikamp
parents:
771
diff
changeset
|
284 } |
2c243233c999
Menu shortcut for bailout / return to circuit when diving in CCR mode (mikeller)
heinrichsweikamp
parents:
771
diff
changeset
|
285 |
2c243233c999
Menu shortcut for bailout / return to circuit when diving in CCR mode (mikeller)
heinrichsweikamp
parents:
771
diff
changeset
|
286 return diveState->warnings.betterGas; |
38 | 287 } |
288 | |
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
|
289 |
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
|
290 uint8_t getSetpointLowId(void) |
38 | 291 { |
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
|
292 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
|
293 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
|
294 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
|
295 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
|
296 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
|
297 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
|
298 } |
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
|
299 } |
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
|
300 |
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
|
301 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
|
302 } |
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
|
303 |
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
|
304 |
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
|
305 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
|
306 { |
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
|
307 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
|
308 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
|
309 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
|
310 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
|
311 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
|
312 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
|
313 } |
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
|
314 } |
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
|
315 |
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
|
316 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
|
317 } |
38 | 318 |
662 | 319 |
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
|
320 /* 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
|
321 */ |
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
|
322 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
|
323 { |
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
|
324 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
|
325 |
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
|
326 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
|
327 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
|
328 |
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
|
329 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
|
330 } |
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
|
331 |
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
|
332 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
|
333 |
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
|
334 float currentDepthM = diveState->lifeData.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
|
335 if (settings->dive_mode == DIVEMODE_CCR && diveState->lifeData.lastSetpointChangeDepthM != currentDepthM) { |
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
|
336 float lastChangeDepthM = diveState->lifeData.lastSetpointChangeDepthM; |
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
|
337 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
|
338 uint8_t setpointLowId = getSetpointLowId(); |
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
|
339 uint8_t setpointHighId = getSetpointHighId(); |
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
|
340 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
|
341 uint8_t betterSetpointSwitchDepthM = descending ? 0 : 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
|
342 |
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
|
343 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
|
344 uint8_t switchDepthM = diveState->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
|
345 if (!switchDepthM || (descending && i == setpointLowId) || (!descending && i == 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
|
346 continue; |
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
|
347 } |
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
|
348 |
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
|
349 if ((descending && lastChangeDepthM < switchDepthM && switchDepthM < currentDepthM && switchDepthM > betterSetpointSwitchDepthM) |
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
|
350 || (!descending && lastChangeDepthM > switchDepthM && switchDepthM > currentDepthM && switchDepthM <= betterSetpointSwitchDepthM)) { |
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
|
351 betterSetpointIdLocal = 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
|
352 betterSetpointSwitchDepthM = switchDepthM; |
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
|
353 } |
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
|
354 } |
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
|
355 |
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
|
356 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
|
357 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
|
358 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
|
359 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
|
360 } |
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
|
361 } |
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
|
362 } |
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
|
363 |
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
|
364 return diveState->warnings.betterSetpoint; |
38 | 365 } |
366 | |
367 | |
368 /* hw 151030 | |
369 */ | |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
370 static int8_t check_helper_same_oxygen_and_helium_content(SGasLine * gas1, SGasLine * gas2) |
38 | 371 { |
372 if(gas1->helium_percentage != gas2->helium_percentage) | |
373 return 0; | |
374 else | |
375 if(gas1->oxygen_percentage != gas2->oxygen_percentage) | |
376 return 0; | |
377 else | |
378 return 1; | |
379 } | |
380 | |
381 | |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
382 static int8_t check_CNS(SDiveState * pDiveState) |
38 | 383 { |
384 if(stateUsed->mode != MODE_DIVE) | |
385 { | |
386 pDiveState->warnings.cnsHigh = 0; | |
387 return 0; | |
388 } | |
389 | |
390 if(pDiveState->lifeData.cns >= (float)(settingsGetPointer()->CNS_max)) | |
391 pDiveState->warnings.cnsHigh = 1; | |
392 else | |
393 pDiveState->warnings.cnsHigh = 0; | |
394 return pDiveState->warnings.cnsHigh; | |
395 } | |
396 | |
397 | |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
398 static int8_t check_Battery(SDiveState * pDiveState) |
38 | 399 { |
671
b456be1e152d
Support of unknown charging counter values:
Ideenmodellierer
parents:
662
diff
changeset
|
400 if((pDiveState->lifeData.battery_charge > 0) && (pDiveState->lifeData.battery_charge < 10)) |
38 | 401 pDiveState->warnings.lowBattery = 1; |
402 else | |
403 pDiveState->warnings.lowBattery = 0; | |
404 | |
405 return pDiveState->warnings.lowBattery; | |
406 } | |
407 | |
408 | |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
409 static int8_t check_Deco(SDiveState * pDiveState) |
38 | 410 { |
411 if(stateUsed->mode != MODE_DIVE) | |
412 { | |
413 pDiveState->warnings.decoMissed = 0; | |
414 return 0; | |
415 } | |
416 | |
417 uint8_t depthNext = decom_get_actual_deco_stop(pDiveState); | |
418 | |
419 if(!depthNext) | |
420 pDiveState->warnings.decoMissed = 0; | |
421 else | |
422 if(pDiveState->lifeData.depth_meter + 0.1f < (float)depthNext) | |
423 pDiveState->warnings.decoMissed = 1; | |
424 else | |
425 pDiveState->warnings.decoMissed = 0; | |
426 | |
427 return pDiveState->warnings.decoMissed; | |
428 } | |
429 | |
430 | |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
431 static int8_t check_AscentRate(SDiveState * pDiveState) |
38 | 432 { |
433 if(stateUsed->mode != MODE_DIVE) | |
434 { | |
435 pDiveState->warnings.ascentRateHigh = 0; | |
436 return 0; | |
437 } | |
438 | |
439 float warnAscentRateFloat; | |
440 | |
441 warnAscentRateFloat = (float)(settingsGetPointer()->ascent_MeterPerMinute_max); | |
442 | |
443 if(pDiveState->lifeData.ascent_rate_meter_per_min >= warnAscentRateFloat) | |
444 pDiveState->warnings.ascentRateHigh = 1; | |
445 else | |
446 pDiveState->warnings.ascentRateHigh = 0; | |
447 return pDiveState->warnings.ascentRateHigh; | |
448 } | |
449 | |
450 | |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
451 static int8_t check_aGF(SDiveState * pDiveState) |
38 | 452 { |
453 if(stateUsed->mode != MODE_DIVE) | |
454 { | |
455 pDiveState->warnings.aGf = 0; | |
456 return 0; | |
457 } | |
458 | |
459 pDiveState->warnings.aGf = 0; | |
460 if(pDiveState->diveSettings.deco_type.ub.standard == GF_MODE) | |
461 { | |
462 if((pDiveState->diveSettings.gf_high != settingsGetPointer()->GF_high) || (pDiveState->diveSettings.gf_low != settingsGetPointer()->GF_low)) | |
463 pDiveState->warnings.aGf = 1; | |
464 } | |
465 return pDiveState->warnings.aGf; | |
466 } | |
467 | |
478
58200d756365
Development option only: Show Pressure update for a short time in the custom field (as warning)
ideenmodellierer
parents:
272
diff
changeset
|
468 #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
|
469 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
|
470 { |
58200d756365
Development option only: Show Pressure update for a short time in the custom field (as warning)
ideenmodellierer
parents:
272
diff
changeset
|
471 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
|
472 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
|
473 { |
58200d756365
Development option only: Show Pressure update for a short time in the custom field (as warning)
ideenmodellierer
parents:
272
diff
changeset
|
474 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
|
475 ret = 1; |
58200d756365
Development option only: Show Pressure update for a short time in the custom field (as warning)
ideenmodellierer
parents:
272
diff
changeset
|
476 } |
58200d756365
Development option only: Show Pressure update for a short time in the custom field (as warning)
ideenmodellierer
parents:
272
diff
changeset
|
477 else |
58200d756365
Development option only: Show Pressure update for a short time in the custom field (as warning)
ideenmodellierer
parents:
272
diff
changeset
|
478 { |
58200d756365
Development option only: Show Pressure update for a short time in the custom field (as warning)
ideenmodellierer
parents:
272
diff
changeset
|
479 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
|
480 } |
58200d756365
Development option only: Show Pressure update for a short time in the custom field (as warning)
ideenmodellierer
parents:
272
diff
changeset
|
481 return ret; |
58200d756365
Development option only: Show Pressure update for a short time in the custom field (as warning)
ideenmodellierer
parents:
272
diff
changeset
|
482 } |
58200d756365
Development option only: Show Pressure update for a short time in the custom field (as warning)
ideenmodellierer
parents:
272
diff
changeset
|
483 #endif |
636 | 484 |
756 | 485 #ifdef ENABLE_CO2_SUPPORT |
486 static int8_t check_co2(SDiveState * pDiveState) | |
487 { | |
488 if(pDiveState->mode != MODE_DIVE) | |
489 { | |
490 pDiveState->warnings.co2High = 0; | |
491 } | |
492 else | |
493 { | |
494 if(pDiveState->lifeData.CO2_data.CO2_ppm > CO2_ALARM_LEVEL_PPM) | |
495 { | |
496 pDiveState->warnings.co2High = 1; | |
497 } | |
498 else | |
499 { | |
500 pDiveState->warnings.co2High = 0; | |
501 } | |
502 } | |
503 return pDiveState->warnings.co2High; | |
504 } | |
505 #endif | |
506 | |
636 | 507 uint8_t debounce_warning_fallback(uint16_t debounceStepms) |
508 { | |
509 uint8_t retVal = 0; | |
510 | |
511 debounceFallbackTimeMS += debounceStepms; | |
512 if(debounceFallbackTimeMS > DEBOUNCE_FALLBACK_TIME_MS) | |
513 { | |
514 debounceFallbackTimeMS = DEBOUNCE_FALLBACK_TIME_MS; | |
515 retVal = 1; | |
516 } | |
517 return retVal; | |
518 } | |
519 void reset_debounce_warning_fallback() | |
520 { | |
521 debounceFallbackTimeMS = 0; | |
522 } | |
38 | 523 /************************ (C) COPYRIGHT heinrichs weikamp *****END OF FILE****/ |
524 |