Mercurial > public > ostc4
annotate Discovery/Src/data_central.c @ 864:fa431d42b5fb
Fix incorrect logging of bailout to Open Circuit when using the best gas.
This happened because the starting gas used for 'best gas' calculation
was a diluent - in most cases not a problem as the same gas is also
used as a bailout gas. Now use the 'first' open circuit gas configured as the
starting point.
Also fixes the problem of a custom bailout gas not being logged as such,
and consequently not being shown as bailout in the on-device log.
author | heinrichsweikamp |
---|---|
date | Mon, 22 Jul 2024 16:38:36 +0200 |
parents | dd7ce655db26 |
children | e373e90a48db |
rev | line source |
---|---|
38 | 1 /** |
2 ****************************************************************************** | |
3 * @copyright heinrichs weikamp | |
4 * @file data_central.c | |
5 * @author heinrichs weikamp gmbh | |
6 * @date 10-November-2014 | |
7 * @version V1.0.2 | |
8 * @since 10-Nov-2014 | |
9 * @brief All the data EXCEPT | |
10 * - settings (settings.c) | |
11 * feste Werte, die nur an der Oberfl�che ge�ndert werden | |
12 * - dataIn and dataOut (data_exchange.h and data_exchange_main.c) | |
13 * Austausch mit Small CPU | |
14 * @bug | |
15 * @warning | |
16 @verbatim | |
17 ============================================================================== | |
18 ##### SDiveState Real and Sim ##### | |
19 ============================================================================== | |
20 [..] SDiveSettings | |
21 copy of parts of Settings that are necessary during the dive | |
22 and could be modified during the dive without post dive changes. | |
23 | |
24 [..] SLifeData | |
25 written in DataEX_copy_to_LifeData(); | |
26 block 1 "lifedata" set by SmallCPU in stateReal | |
27 block 2 "actualGas" set by main CPU from user input and send to Small CPU | |
28 block 3 "calculated data" set by main CPU based on "lifedata" | |
29 | |
30 [..] SVpm | |
31 | |
32 [..] SEvents | |
33 | |
34 [..] SDecoinfo | |
35 | |
36 [..] mode | |
37 set by SmallCPU in stateReal, can be surface, dive, ... | |
38 | |
39 [..] data_old__lost_connection_to_slave | |
40 set by DataEX_copy_to_LifeData(); | |
41 | |
42 ============================================================================== | |
43 ##### SDiveState Deco ##### | |
44 ============================================================================== | |
45 [..] kjbkldafj�lasdfjasdf | |
46 | |
47 ============================================================================== | |
48 ##### decoLock ##### | |
49 ============================================================================== | |
50 [..] The handler that synchronizes the data between IRQ copy and main deco loop | |
51 | |
52 | |
53 @endverbatim | |
54 ****************************************************************************** | |
55 * @attention | |
56 * | |
57 * <h2><center>© COPYRIGHT(c) 2015 heinrichs weikamp</center></h2> | |
58 * | |
59 ****************************************************************************** | |
60 */ | |
61 | |
62 /* Includes ------------------------------------------------------------------*/ | |
63 #include <string.h> | |
539
d784f281833a
Added inertia simulation for compass heading:
Ideenmodellierer
parents:
310
diff
changeset
|
64 #include <math.h> |
38 | 65 #include "data_central.h" |
66 #include "calc_crush.h" | |
67 #include "decom.h" | |
68 #include "stm32f4xx_hal.h" | |
69 #include "settings.h" | |
70 #include "data_exchange_main.h" | |
71 #include "ostc.h" // for button adjust on hw testboard 1 | |
72 #include "tCCR.h" | |
73 #include "crcmodel.h" | |
662 | 74 #include "configuration.h" |
38 | 75 |
225
2bb1db22b5f5
cleanup: random set of cleanups
Jan Mulder <jlmulder@xs4all.nl>
parents:
149
diff
changeset
|
76 static SDiveState stateReal = { 0 }; |
38 | 77 SDiveState stateSim = { 0 }; |
78 SDiveState stateDeco = { 0 }; | |
79 | |
300
5ca177d2df5d
cleanup: remove commented/unused code, make static
Jan Mulder <jlmulder@xs4all.nl>
parents:
281
diff
changeset
|
80 static SDevice stateDevice = |
38 | 81 { |
82 /* max is 0x7FFFFFFF, min is 0x80000000 but also defined in stdint.h :-) */ | |
83 | |
84 /* count, use 0 */ | |
85 .batteryChargeCompleteCycles.value_int32 = 0, | |
86 .batteryChargeCycles.value_int32 = 0, | |
87 .diveCycles.value_int32 = 0, | |
88 .hoursOfOperation.value_int32 = 0, | |
89 | |
90 /* max values, use min. */ | |
91 .temperatureMaximum.value_int32 = INT32_MIN, | |
92 .depthMaximum.value_int32 = INT32_MIN, | |
93 | |
94 /* min values, use max. */ | |
95 .temperatureMinimum.value_int32 = INT32_MAX, | |
96 .voltageMinimum.value_int32 = INT32_MAX, | |
97 }; | |
98 | |
300
5ca177d2df5d
cleanup: remove commented/unused code, make static
Jan Mulder <jlmulder@xs4all.nl>
parents:
281
diff
changeset
|
99 static SVpmRepetitiveData stateVPM = |
38 | 100 { |
101 .repetitive_variables_not_valid = 1, | |
102 .is_data_from_RTE_CPU = 0, | |
103 }; | |
104 | |
271
1303747b5ba2
cleanup: also write gas and setpoint changes in simulator mode
Jan Mulder <jlmulder@xs4all.nl>
parents:
270
diff
changeset
|
105 const SDiveState *stateUsed = &stateReal; |
1303747b5ba2
cleanup: also write gas and setpoint changes in simulator mode
Jan Mulder <jlmulder@xs4all.nl>
parents:
270
diff
changeset
|
106 SDiveState *stateUsedWrite = &stateReal; |
38 | 107 |
539
d784f281833a
Added inertia simulation for compass heading:
Ideenmodellierer
parents:
310
diff
changeset
|
108 |
d784f281833a
Added inertia simulation for compass heading:
Ideenmodellierer
parents:
310
diff
changeset
|
109 #define COMPASS_FRACTION (4.0f) /* delay till value changes to new actual */ |
d784f281833a
Added inertia simulation for compass heading:
Ideenmodellierer
parents:
310
diff
changeset
|
110 |
d784f281833a
Added inertia simulation for compass heading:
Ideenmodellierer
parents:
310
diff
changeset
|
111 static float compass_compensated = 0; |
d784f281833a
Added inertia simulation for compass heading:
Ideenmodellierer
parents:
310
diff
changeset
|
112 |
38 | 113 void set_stateUsedToReal(void) |
114 { | |
271
1303747b5ba2
cleanup: also write gas and setpoint changes in simulator mode
Jan Mulder <jlmulder@xs4all.nl>
parents:
270
diff
changeset
|
115 stateUsed = stateUsedWrite = &stateReal; |
38 | 116 } |
117 | |
118 void set_stateUsedToSim(void) | |
119 { | |
271
1303747b5ba2
cleanup: also write gas and setpoint changes in simulator mode
Jan Mulder <jlmulder@xs4all.nl>
parents:
270
diff
changeset
|
120 stateUsed = stateUsedWrite = &stateSim; |
38 | 121 } |
122 | |
123 _Bool is_stateUsedSetToSim(void) | |
124 { | |
225
2bb1db22b5f5
cleanup: random set of cleanups
Jan Mulder <jlmulder@xs4all.nl>
parents:
149
diff
changeset
|
125 return stateUsed == &stateSim; |
38 | 126 } |
127 | |
128 const SDiveState * stateRealGetPointer(void) | |
129 { | |
130 return &stateReal; | |
131 } | |
132 | |
133 SDiveState * stateRealGetPointerWrite(void) | |
134 { | |
135 return &stateReal; | |
136 } | |
137 | |
138 | |
139 const SDiveState * stateSimGetPointer(void) | |
140 { | |
141 return &stateSim; | |
142 } | |
143 | |
144 | |
145 SDiveState * stateSimGetPointerWrite(void) | |
146 { | |
147 return &stateSim; | |
148 } | |
149 | |
150 | |
151 const SDevice * stateDeviceGetPointer(void) | |
152 { | |
153 return &stateDevice; | |
154 } | |
155 | |
156 | |
157 SDevice * stateDeviceGetPointerWrite(void) | |
158 { | |
159 return &stateDevice; | |
160 } | |
161 | |
162 | |
163 const SVpmRepetitiveData * stateVpmRepetitiveDataGetPointer(void) | |
164 { | |
165 return &stateVPM; | |
166 } | |
167 | |
168 | |
169 SVpmRepetitiveData * stateVpmRepetitiveDataGetPointerWrite(void) | |
170 { | |
171 return &stateVPM; | |
172 } | |
173 | |
174 | |
175 uint32_t time_elapsed_ms(uint32_t ticksstart,uint32_t ticksnow) | |
176 { | |
177 if(ticksstart <= ticksnow) | |
178 return ticksnow - ticksstart; | |
179 else | |
180 return 0xFFFFFFFF - ticksstart + ticksnow; | |
181 } | |
182 | |
183 | |
184 uint8_t decoLock = DECO_CALC_undefined; | |
300
5ca177d2df5d
cleanup: remove commented/unused code, make static
Jan Mulder <jlmulder@xs4all.nl>
parents:
281
diff
changeset
|
185 |
5ca177d2df5d
cleanup: remove commented/unused code, make static
Jan Mulder <jlmulder@xs4all.nl>
parents:
281
diff
changeset
|
186 static int descent_rate_meter_per_min = 20; |
5ca177d2df5d
cleanup: remove commented/unused code, make static
Jan Mulder <jlmulder@xs4all.nl>
parents:
281
diff
changeset
|
187 static int max_depth = 70; |
5ca177d2df5d
cleanup: remove commented/unused code, make static
Jan Mulder <jlmulder@xs4all.nl>
parents:
281
diff
changeset
|
188 static int bottom_time = 10; |
38 | 189 |
190 _Bool vpm_crush(SDiveState* pDiveState); | |
191 void setSimulationValues(int _ascent_rate_meter_per_min, int _descent_rate_meter_per_min, int _max_depth, int _bottom_time ) | |
192 { | |
193 descent_rate_meter_per_min = _descent_rate_meter_per_min; | |
194 max_depth = _max_depth; | |
195 bottom_time = _bottom_time; | |
196 } | |
197 | |
198 int current_second(void) { | |
199 | |
200 return HAL_GetTick() / 1000; | |
201 } | |
202 | |
203 #define OXY_ONE_SIXTIETH_PART 0.0166667f | |
204 | |
205 uint8_t calc_MOD(uint8_t gasId) | |
206 { | |
207 int16_t oxygen, maxppO2, result; | |
208 SSettings *pSettings; | |
209 | |
210 pSettings = settingsGetPointer(); | |
211 | |
212 oxygen = (int16_t)(pSettings->gas[gasId].oxygen_percentage); | |
213 | |
214 if(pSettings->gas[gasId].note.ub.deco > 0) | |
215 maxppO2 =(int16_t)(pSettings->ppO2_max_deco); | |
216 else | |
217 maxppO2 =(int16_t)(pSettings->ppO2_max_std); | |
218 | |
219 result = 10 * maxppO2; | |
220 result /= oxygen; | |
221 result -= 10; | |
222 | |
223 if(result < 0) | |
224 return 0; | |
225 | |
226 if(result > 255) | |
227 return 255; | |
228 | |
229 return result; | |
230 } | |
231 | |
232 float get_ambiant_pressure_simulation(long dive_time_seconds, float surface_pressure_bar ) | |
233 { | |
234 static | |
235 long descent_time; | |
236 float depth_meter; | |
237 | |
238 descent_time = 60 * max_depth / descent_rate_meter_per_min; | |
239 | |
240 if(dive_time_seconds <= descent_time) | |
241 { | |
242 depth_meter = ((float)(dive_time_seconds * descent_rate_meter_per_min)) / 60; | |
243 return surface_pressure_bar + depth_meter / 10; | |
244 } | |
245 //else if(dive_time_seconds <= (descent_time + bottom_time * 60)) | |
246 return surface_pressure_bar + max_depth / 10; | |
247 | |
248 | |
249 | |
250 } | |
251 | |
252 void UpdateLifeDataTest(SDiveState * pDiveState) | |
253 { | |
254 static int last_second = -1; | |
255 int now = current_second(); | |
256 if(last_second == now) | |
257 return; | |
258 last_second = now; | |
259 | |
260 pDiveState->lifeData.dive_time_seconds += 1; | |
261 pDiveState->lifeData.pressure_ambient_bar = get_ambiant_pressure_simulation(pDiveState->lifeData.dive_time_seconds,pDiveState->lifeData.pressure_surface_bar); | |
262 | |
263 pDiveState->lifeData.depth_meter = (pDiveState->lifeData.pressure_ambient_bar - pDiveState->lifeData.pressure_surface_bar) * 10.0f; | |
264 if(pDiveState->lifeData.max_depth_meter < pDiveState->lifeData.depth_meter) | |
265 pDiveState->lifeData.max_depth_meter = pDiveState->lifeData.depth_meter; | |
266 decom_tissues_exposure(1, &pDiveState->lifeData); | |
267 pDiveState->lifeData.ppO2 = decom_calc_ppO2( pDiveState->lifeData.pressure_ambient_bar, &pDiveState->lifeData.actualGas); | |
268 decom_oxygen_calculate_cns(& pDiveState->lifeData.cns, pDiveState->lifeData.ppO2); | |
269 | |
270 vpm_crush(pDiveState); | |
271 } | |
272 | |
273 | |
274 _Bool vpm_crush(SDiveState* pDiveState) | |
275 { | |
276 int i = 0; | |
277 static float starting_ambient_pressure = 0; | |
278 static float ending_ambient_pressure = 0; | |
279 static float time_calc_begin = -1; | |
280 static float initial_helium_pressure[16]; | |
281 static float initial_nitrogen_pressure[16]; | |
282 ending_ambient_pressure = pDiveState->lifeData.pressure_ambient_bar * 10; | |
283 | |
284 if((pDiveState->lifeData.dive_time_seconds <= 4) || (starting_ambient_pressure >= ending_ambient_pressure)) | |
285 { | |
286 time_calc_begin = pDiveState->lifeData.dive_time_seconds; | |
287 starting_ambient_pressure = pDiveState->lifeData.pressure_ambient_bar * 10; | |
288 for( i = 0; i < 16; i++) | |
289 { | |
290 initial_helium_pressure[i] = pDiveState->lifeData.tissue_helium_bar[i] * 10; | |
291 initial_nitrogen_pressure[i] = pDiveState->lifeData.tissue_nitrogen_bar[i] * 10; | |
292 } | |
293 return false; | |
294 } | |
295 if(pDiveState->lifeData.dive_time_seconds - time_calc_begin >= 4) | |
296 { | |
297 if(ending_ambient_pressure > starting_ambient_pressure + 0.5f) | |
298 { | |
299 float rate = (ending_ambient_pressure - starting_ambient_pressure) * 60 / 4; | |
300 calc_crushing_pressure(&pDiveState->lifeData, &pDiveState->vpm, initial_helium_pressure, initial_nitrogen_pressure, starting_ambient_pressure, rate); | |
301 | |
302 time_calc_begin = pDiveState->lifeData.dive_time_seconds; | |
303 starting_ambient_pressure = pDiveState->lifeData.pressure_ambient_bar * 10; | |
304 for( i = 0; i < 16; i++) | |
305 { | |
306 initial_helium_pressure[i] = pDiveState->lifeData.tissue_helium_bar[i] * 10; | |
307 initial_nitrogen_pressure[i] = pDiveState->lifeData.tissue_nitrogen_bar[i] * 10; | |
308 } | |
309 | |
310 return true; | |
311 } | |
312 | |
313 } | |
314 return false; | |
315 }; | |
316 | |
317 | |
318 void createDiveSettings(void) | |
319 { | |
662 | 320 int i; |
38 | 321 SSettings* pSettings = settingsGetPointer(); |
322 | |
323 stateReal.diveSettings.compassHeading = pSettings->compassBearing; | |
324 stateReal.diveSettings.ascentRate_meterperminute = 10; | |
325 | |
326 stateReal.diveSettings.diveMode = pSettings->dive_mode; | |
327 stateReal.diveSettings.CCR_Mode = pSettings->CCR_Mode; | |
662 | 328 if((stateReal.diveSettings.diveMode == DIVEMODE_PSCR) && (stateReal.diveSettings.CCR_Mode == CCRMODE_FixedSetpoint)) |
329 { | |
330 /* TODO: update selection of sensor used on/off (currently sensor/fixpoint). As PSCR has no fixed setpoint change to simulated ppo2 if sensors are not active */ | |
331 stateReal.diveSettings.CCR_Mode = CCRMODE_Simulation; | |
332 } | |
333 | |
334 if(isLoopMode(stateReal.diveSettings.diveMode)) | |
38 | 335 stateReal.diveSettings.ccrOption = 1; |
336 else | |
337 stateReal.diveSettings.ccrOption = 0; | |
338 memcpy(stateReal.diveSettings.gas, pSettings->gas,sizeof(pSettings->gas)); | |
339 memcpy(stateReal.diveSettings.setpoint, pSettings->setpoint,sizeof(pSettings->setpoint)); | |
683
6f5a18bb25be
Bugfix: Set actual gas after basic dive settings were created:
Ideenmodellierer
parents:
682
diff
changeset
|
340 |
6f5a18bb25be
Bugfix: Set actual gas after basic dive settings were created:
Ideenmodellierer
parents:
682
diff
changeset
|
341 setActualGasFirst(&stateReal.lifeData); |
6f5a18bb25be
Bugfix: Set actual gas after basic dive settings were created:
Ideenmodellierer
parents:
682
diff
changeset
|
342 |
38 | 343 stateReal.diveSettings.gf_high = pSettings->GF_high; |
344 stateReal.diveSettings.gf_low = pSettings->GF_low; | |
345 stateReal.diveSettings.input_next_stop_increment_depth_bar = ((float)pSettings->stop_increment_depth_meter) / 10.0f; | |
346 stateReal.diveSettings.last_stop_depth_bar = ((float)pSettings->last_stop_depth_meter) / 10.0f; | |
347 stateReal.diveSettings.vpm_conservatism = pSettings->VPM_conservatism.ub.standard; | |
348 stateReal.diveSettings.deco_type.uw = pSettings->deco_type.uw; | |
349 stateReal.diveSettings.fallbackOption = pSettings->fallbackToFixedSetpoint; | |
350 stateReal.diveSettings.ppo2sensors_deactivated = pSettings->ppo2sensors_deactivated; | |
351 stateReal.diveSettings.future_TTS_minutes = pSettings->future_TTS; | |
352 | |
662 | 353 stateReal.diveSettings.pscr_lung_ratio = pSettings->pscr_lung_ratio; |
354 stateReal.diveSettings.pscr_o2_drop = pSettings->pscr_o2_drop; | |
355 | |
356 if(stateReal.diveSettings.diveMode == DIVEMODE_PSCR) | |
357 { | |
358 for(i=0; i<5; i++) | |
359 { | |
360 stateReal.diveSettings.decogaslist[i].pscr_factor = 1.0 / stateReal.diveSettings.pscr_lung_ratio * stateReal.diveSettings.pscr_o2_drop; | |
361 } | |
362 } | |
363 | |
38 | 364 decom_CreateGasChangeList(&stateReal.diveSettings, &stateReal.lifeData); // decogaslist |
365 stateReal.diveSettings.internal__pressure_first_stop_ambient_bar_as_upper_limit_for_gf_low_otherwise_zero = 0; | |
366 | |
367 /* for safety */ | |
368 stateReal.diveSettings.input_second_to_last_stop_depth_bar = stateReal.diveSettings.last_stop_depth_bar + stateReal.diveSettings.input_next_stop_increment_depth_bar; | |
369 /* and the proper calc */ | |
662 | 370 for(i = 1; i <10; i++) |
38 | 371 { |
372 if(stateReal.diveSettings.input_next_stop_increment_depth_bar * i > stateReal.diveSettings.last_stop_depth_bar) | |
373 { | |
374 stateReal.diveSettings.input_second_to_last_stop_depth_bar = stateReal.diveSettings.input_next_stop_increment_depth_bar * i; | |
375 break; | |
376 } | |
377 } | |
378 } | |
379 | |
380 | |
381 void copyDiveSettingsToSim(void) | |
382 { | |
383 memcpy(&stateSim, &stateReal, sizeof(stateReal)); | |
384 } | |
385 | |
386 | |
387 void copyVpmRepetetiveDataToSim(void) | |
388 { | |
389 SDiveState * pSimData = stateSimGetPointerWrite(); | |
390 const SVpmRepetitiveData * pVpmData = stateVpmRepetitiveDataGetPointer(); | |
391 | |
392 if(pVpmData->is_data_from_RTE_CPU) | |
393 { | |
394 for(int i=0; i<16;i++) | |
395 { | |
396 pSimData->vpm.adjusted_critical_radius_he[i] = pVpmData->adjusted_critical_radius_he[i]; | |
397 pSimData->vpm.adjusted_critical_radius_n2[i] = pVpmData->adjusted_critical_radius_n2[i]; | |
398 | |
399 pSimData->vpm.adjusted_crushing_pressure_he[i] = pVpmData->adjusted_crushing_pressure_he[i]; | |
400 pSimData->vpm.adjusted_crushing_pressure_n2[i] = pVpmData->adjusted_crushing_pressure_n2[i]; | |
401 | |
402 pSimData->vpm.initial_allowable_gradient_he[i] = pVpmData->initial_allowable_gradient_he[i]; | |
403 pSimData->vpm.initial_allowable_gradient_n2[i] = pVpmData->initial_allowable_gradient_n2[i]; | |
404 | |
405 pSimData->vpm.max_actual_gradient[i] = pVpmData->max_actual_gradient[i]; | |
406 } | |
407 pSimData->vpm.repetitive_variables_not_valid = pVpmData->repetitive_variables_not_valid; | |
408 } | |
409 } | |
410 | |
411 | |
412 void updateSetpointStateUsed(void) | |
413 { | |
682 | 414 if(!isLoopMode(stateUsed->diveSettings.diveMode)) |
38 | 415 { |
271
1303747b5ba2
cleanup: also write gas and setpoint changes in simulator mode
Jan Mulder <jlmulder@xs4all.nl>
parents:
270
diff
changeset
|
416 stateUsedWrite->lifeData.actualGas.setPoint_cbar = 0; |
1303747b5ba2
cleanup: also write gas and setpoint changes in simulator mode
Jan Mulder <jlmulder@xs4all.nl>
parents:
270
diff
changeset
|
417 stateUsedWrite->lifeData.ppO2 = decom_calc_ppO2(stateUsed->lifeData.pressure_ambient_bar, &stateUsed->lifeData.actualGas); |
38 | 418 } |
419 else | |
420 { | |
421 if(stateUsed->diveSettings.CCR_Mode == CCRMODE_Sensors) | |
422 { | |
271
1303747b5ba2
cleanup: also write gas and setpoint changes in simulator mode
Jan Mulder <jlmulder@xs4all.nl>
parents:
270
diff
changeset
|
423 stateUsedWrite->lifeData.actualGas.setPoint_cbar = get_ppO2SensorWeightedResult_cbar(); |
38 | 424 } |
662 | 425 #ifdef ENABLE_PSCR_MODE |
426 if(stateUsed->diveSettings.diveMode == DIVEMODE_PSCR) /* calculate a ppO2 value based on assumptions ( transfered approach from hwos code) */ | |
427 { | |
428 stateUsedWrite->lifeData.ppo2Simulated_bar = decom_calc_SimppO2_O2based(stateUsed->lifeData.pressure_ambient_bar, stateReal.diveSettings.gas[stateUsed->lifeData.actualGas.GasIdInSettings].oxygen_percentage, stateUsed->lifeData.actualGas.pscr_factor); | |
429 if(stateUsed->diveSettings.CCR_Mode == CCRMODE_Simulation) | |
430 { | |
431 stateUsedWrite->lifeData.actualGas.setPoint_cbar = stateUsedWrite->lifeData.ppo2Simulated_bar * 100; | |
432 } | |
433 } | |
434 #endif | |
435 /* limit calculated value to the physically possible if needed */ | |
38 | 436 if((stateUsed->lifeData.pressure_ambient_bar * 100) < stateUsed->lifeData.actualGas.setPoint_cbar) |
271
1303747b5ba2
cleanup: also write gas and setpoint changes in simulator mode
Jan Mulder <jlmulder@xs4all.nl>
parents:
270
diff
changeset
|
437 stateUsedWrite->lifeData.ppO2 = stateUsed->lifeData.pressure_ambient_bar; |
38 | 438 else |
271
1303747b5ba2
cleanup: also write gas and setpoint changes in simulator mode
Jan Mulder <jlmulder@xs4all.nl>
parents:
270
diff
changeset
|
439 stateUsedWrite->lifeData.ppO2 = ((float)stateUsed->lifeData.actualGas.setPoint_cbar) / 100; |
38 | 440 } |
441 } | |
442 | |
443 void setActualGasFirst(SLifeData *lifeData) | |
444 { | |
445 SSettings* pSettings = settingsGetPointer(); | |
446 uint8_t start = 0; | |
447 uint8_t gasId = 0; | |
448 uint8_t setpoint_cbar = 0; | |
449 | |
662 | 450 if(isLoopMode(pSettings->dive_mode)) |
38 | 451 { |
452 setpoint_cbar = pSettings->setpoint[1].setpoint_cbar; | |
453 start = NUM_OFFSET_DILUENT+1; | |
454 } | |
455 else | |
456 { | |
457 setpoint_cbar = 0; | |
458 start = 1; | |
459 } | |
460 | |
461 gasId = start; | |
462 for(int i=start;i<=NUM_GASES+start;i++) | |
463 { | |
464 if(pSettings->gas[i].note.ub.first) | |
465 { | |
466 gasId = i; | |
467 break; | |
468 } | |
469 } | |
470 setActualGas(lifeData, gasId, setpoint_cbar); | |
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:
776
diff
changeset
|
471 |
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:
776
diff
changeset
|
472 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:
776
diff
changeset
|
473 lifeData->setpointLowDelayed = false; |
38 | 474 } |
475 | |
476 void setActualGasAir(SLifeData *lifeData) | |
477 { | |
478 uint8_t nitrogen; | |
479 nitrogen = 79; | |
480 lifeData->actualGas.GasIdInSettings = 0; | |
481 lifeData->actualGas.nitrogen_percentage = nitrogen; | |
482 lifeData->actualGas.helium_percentage =0; | |
483 lifeData->actualGas.setPoint_cbar = 0; | |
484 lifeData->actualGas.change_during_ascent_depth_meter_otherwise_zero = 0; | |
662 | 485 lifeData->actualGas.AppliedDiveMode = stateUsed->diveSettings.diveMode; |
38 | 486 } |
487 | |
488 | |
489 void setActualGas(SLifeData *lifeData, uint8_t gasId, uint8_t setpoint_cbar) | |
490 { | |
491 SSettings* pSettings = settingsGetPointer(); | |
492 uint8_t nitrogen; | |
493 | |
494 nitrogen = 100; | |
495 nitrogen -= pSettings->gas[gasId].oxygen_percentage; | |
496 nitrogen -= pSettings->gas[gasId].helium_percentage; | |
497 | |
498 lifeData->actualGas.GasIdInSettings = gasId; | |
499 lifeData->actualGas.nitrogen_percentage = nitrogen; | |
500 lifeData->actualGas.helium_percentage = pSettings->gas[gasId].helium_percentage; | |
501 lifeData->actualGas.setPoint_cbar = setpoint_cbar; | |
502 lifeData->actualGas.change_during_ascent_depth_meter_otherwise_zero = 0; | |
682 | 503 lifeData->actualGas.AppliedDiveMode = stateUsed->diveSettings.diveMode; |
662 | 504 lifeData->actualGas.pscr_factor = 1.0 / pSettings->pscr_lung_ratio * pSettings->pscr_o2_drop; |
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:
736
diff
changeset
|
505 if (isLoopMode(pSettings->dive_mode) && gasId > NUM_OFFSET_DILUENT) { |
38 | 506 lifeData->lastDiluent_GasIdInSettings = gasId; |
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:
736
diff
changeset
|
507 lifeData->lastSetpointChangeDepthM = 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:
736
diff
changeset
|
508 } |
38 | 509 } |
510 | |
511 | |
512 void setActualGas_DM(SLifeData *lifeData, uint8_t gasId, uint8_t setpoint_cbar) | |
513 { | |
514 if(stateUsed->diveSettings.ccrOption && gasId < 6) | |
515 { | |
516 if(lifeData->actualGas.GasIdInSettings != gasId) | |
517 { | |
518 SSettings* pSettings = settingsGetPointer(); | |
271
1303747b5ba2
cleanup: also write gas and setpoint changes in simulator mode
Jan Mulder <jlmulder@xs4all.nl>
parents:
270
diff
changeset
|
519 stateUsedWrite->events.bailout = 1; |
1303747b5ba2
cleanup: also write gas and setpoint changes in simulator mode
Jan Mulder <jlmulder@xs4all.nl>
parents:
270
diff
changeset
|
520 stateUsedWrite->events.info_bailoutO2 = pSettings->gas[gasId].oxygen_percentage; |
1303747b5ba2
cleanup: also write gas and setpoint changes in simulator mode
Jan Mulder <jlmulder@xs4all.nl>
parents:
270
diff
changeset
|
521 stateUsedWrite->events.info_bailoutHe = pSettings->gas[gasId].helium_percentage; |
38 | 522 } |
523 } | |
524 else | |
525 { | |
526 if(lifeData->actualGas.GasIdInSettings != gasId) | |
527 { | |
271
1303747b5ba2
cleanup: also write gas and setpoint changes in simulator mode
Jan Mulder <jlmulder@xs4all.nl>
parents:
270
diff
changeset
|
528 stateUsedWrite->events.gasChange = 1; |
1303747b5ba2
cleanup: also write gas and setpoint changes in simulator mode
Jan Mulder <jlmulder@xs4all.nl>
parents:
270
diff
changeset
|
529 stateUsedWrite->events.info_GasChange = gasId; |
38 | 530 } |
531 if( lifeData->actualGas.setPoint_cbar != setpoint_cbar) | |
532 { | |
533 // setPoint_cbar = 255 -> change to sensor mode | |
271
1303747b5ba2
cleanup: also write gas and setpoint changes in simulator mode
Jan Mulder <jlmulder@xs4all.nl>
parents:
270
diff
changeset
|
534 stateUsedWrite->events.setpointChange = 1; |
1303747b5ba2
cleanup: also write gas and setpoint changes in simulator mode
Jan Mulder <jlmulder@xs4all.nl>
parents:
270
diff
changeset
|
535 stateUsedWrite->events.info_SetpointChange = setpoint_cbar; |
38 | 536 } |
537 } | |
538 setActualGas(lifeData, gasId, setpoint_cbar); | |
539 } | |
540 | |
541 void setActualGas_ExtraGas(SLifeData *lifeData, uint8_t oxygen, uint8_t helium, uint8_t setpoint_cbar) | |
542 { | |
543 uint8_t nitrogen; | |
544 | |
545 nitrogen = 100; | |
546 nitrogen -= oxygen; | |
547 nitrogen -= helium; | |
548 | |
736
8a2337c7af52
Fixed logbook download after switch from CCR to extra (OC) gas if the extra gas
heinrichsweikamp
parents:
683
diff
changeset
|
549 |
864
fa431d42b5fb
Fix incorrect logging of bailout to Open Circuit when using the best gas.
heinrichsweikamp
parents:
805
diff
changeset
|
550 if ((lifeData->actualGas.nitrogen_percentage != nitrogen) || (lifeData->actualGas.helium_percentage != helium) || lifeData->actualGas.AppliedDiveMode != DIVEMODE_OC) |
38 | 551 { |
864
fa431d42b5fb
Fix incorrect logging of bailout to Open Circuit when using the best gas.
heinrichsweikamp
parents:
805
diff
changeset
|
552 if (stateUsed->diveSettings.ccrOption) { |
fa431d42b5fb
Fix incorrect logging of bailout to Open Circuit when using the best gas.
heinrichsweikamp
parents:
805
diff
changeset
|
553 stateUsedWrite->events.bailout = 1; |
fa431d42b5fb
Fix incorrect logging of bailout to Open Circuit when using the best gas.
heinrichsweikamp
parents:
805
diff
changeset
|
554 stateUsedWrite->events.info_bailoutHe = helium; |
fa431d42b5fb
Fix incorrect logging of bailout to Open Circuit when using the best gas.
heinrichsweikamp
parents:
805
diff
changeset
|
555 stateUsedWrite->events.info_bailoutO2 = oxygen; |
fa431d42b5fb
Fix incorrect logging of bailout to Open Circuit when using the best gas.
heinrichsweikamp
parents:
805
diff
changeset
|
556 } else { |
fa431d42b5fb
Fix incorrect logging of bailout to Open Circuit when using the best gas.
heinrichsweikamp
parents:
805
diff
changeset
|
557 stateUsedWrite->events.manualGasSet = 1; |
fa431d42b5fb
Fix incorrect logging of bailout to Open Circuit when using the best gas.
heinrichsweikamp
parents:
805
diff
changeset
|
558 stateUsedWrite->events.info_manualGasSetHe = helium; |
fa431d42b5fb
Fix incorrect logging of bailout to Open Circuit when using the best gas.
heinrichsweikamp
parents:
805
diff
changeset
|
559 stateUsedWrite->events.info_manualGasSetO2 = oxygen; |
fa431d42b5fb
Fix incorrect logging of bailout to Open Circuit when using the best gas.
heinrichsweikamp
parents:
805
diff
changeset
|
560 } |
38 | 561 } |
864
fa431d42b5fb
Fix incorrect logging of bailout to Open Circuit when using the best gas.
heinrichsweikamp
parents:
805
diff
changeset
|
562 |
38 | 563 if( lifeData->actualGas.setPoint_cbar != setpoint_cbar) |
564 { | |
271
1303747b5ba2
cleanup: also write gas and setpoint changes in simulator mode
Jan Mulder <jlmulder@xs4all.nl>
parents:
270
diff
changeset
|
565 stateUsedWrite->events.setpointChange = 1; |
1303747b5ba2
cleanup: also write gas and setpoint changes in simulator mode
Jan Mulder <jlmulder@xs4all.nl>
parents:
270
diff
changeset
|
566 stateUsedWrite->events.info_SetpointChange = setpoint_cbar; |
38 | 567 } |
568 lifeData->actualGas.GasIdInSettings = 0; | |
569 lifeData->actualGas.nitrogen_percentage = nitrogen; | |
570 lifeData->actualGas.helium_percentage = helium; | |
571 lifeData->actualGas.setPoint_cbar = setpoint_cbar; | |
572 lifeData->actualGas.change_during_ascent_depth_meter_otherwise_zero = 0; | |
662 | 573 lifeData->actualGas.AppliedDiveMode = stateUsed->diveSettings.diveMode; |
38 | 574 } |
575 | |
576 void setButtonResponsiveness(uint8_t *ButtonSensitivyList) | |
577 { | |
578 SDataReceiveFromMaster *pDataOut = dataOutGetPointer(); | |
579 | |
580 for(int i=0; i<4; i++) | |
581 { | |
582 pDataOut->data.buttonResponsiveness[i] = settingsHelperButtonSens_translate_percentage_to_hwOS_values(ButtonSensitivyList[i]); | |
583 } | |
584 pDataOut->setButtonSensitivityNow = 1; | |
585 } | |
586 | |
587 | |
588 void setDate(RTC_DateTypeDef Sdate) | |
589 { | |
590 SDataReceiveFromMaster *pDataOut = dataOutGetPointer(); | |
591 | |
592 pDataOut->data.newDate = Sdate; | |
593 pDataOut->setDateNow = 1; | |
594 } | |
595 | |
596 | |
597 void setTime(RTC_TimeTypeDef Stime) | |
598 { | |
599 SDataReceiveFromMaster *pDataOut = dataOutGetPointer(); | |
600 | |
601 pDataOut->data.newTime = Stime; | |
602 pDataOut->setTimeNow = 1; | |
603 } | |
604 | |
605 | |
606 void setBatteryPercentage(uint8_t newChargePercentage) | |
607 { | |
608 SDataReceiveFromMaster *pDataOut = dataOutGetPointer(); | |
609 | |
610 pDataOut->data.newBatteryGaugePercentageFloat = settingsGetPointer()->lastKnownBatteryPercentage; | |
611 pDataOut->setBatteryGaugeNow = 1; | |
612 } | |
613 | |
614 | |
615 void calibrateCompass(void) | |
616 { | |
617 SDataReceiveFromMaster *pDataOut = dataOutGetPointer(); | |
618 pDataOut->calibrateCompassNow = 1; | |
619 } | |
620 | |
621 | |
622 void clearDeco(void) | |
623 { | |
624 SDataReceiveFromMaster *pDataOut = dataOutGetPointer(); | |
625 pDataOut->clearDecoNow = 1; | |
626 | |
627 stateRealGetPointerWrite()->cnsHigh_at_the_end_of_dive = 0; | |
628 stateRealGetPointerWrite()->decoMissed_at_the_end_of_dive = 0; | |
629 } | |
630 | |
631 | |
300
5ca177d2df5d
cleanup: remove commented/unused code, make static
Jan Mulder <jlmulder@xs4all.nl>
parents:
281
diff
changeset
|
632 static int32_t helper_days_from_civil(int32_t y, uint32_t m, uint32_t d) |
38 | 633 { |
634 y += 2000; | |
635 y -= m <= 2; | |
636 int32_t era = (y >= 0 ? y : y-399) / 400; | |
637 uint32_t yoe = (uint32_t)(y - era * 400); // [0, 399] | |
638 uint32_t doy = (153*(m + (m > 2 ? -3 : 9)) + 2)/5 + d-1; // [0, 365] | |
639 uint32_t doe = yoe * 365 + yoe/4 - yoe/100 + doy; // [0, 146096] | |
640 return era * 146097 + (int32_t)(doe) - 719468; | |
641 } | |
642 | |
643 | |
300
5ca177d2df5d
cleanup: remove commented/unused code, make static
Jan Mulder <jlmulder@xs4all.nl>
parents:
281
diff
changeset
|
644 static uint8_t helper_weekday_from_days(int32_t z) |
38 | 645 { |
646 return (uint8_t)(z >= -4 ? (z+4) % 7 : (z+5) % 7 + 6); | |
647 } | |
648 | |
649 | |
650 void setWeekday(RTC_DateTypeDef *sDate) | |
651 { | |
652 uint8_t day; | |
653 // [0, 6] -> [Sun, Sat] | |
654 day = helper_weekday_from_days(helper_days_from_civil(sDate->Year, sDate->Month, sDate->Date)); | |
655 // [1, 7] -> [Mon, Sun] | |
656 if(day == 0) | |
657 day = 7; | |
658 sDate->WeekDay = day; | |
659 } | |
660 | |
661 | |
662 void translateDate(uint32_t datetmpreg, RTC_DateTypeDef *sDate) | |
663 { | |
664 datetmpreg = (uint32_t)(datetmpreg & RTC_DR_RESERVED_MASK); | |
665 | |
666 /* Fill the structure fields with the read parameters */ | |
667 sDate->Year = (uint8_t)((datetmpreg & (RTC_DR_YT | RTC_DR_YU)) >> 16); | |
668 sDate->Month = (uint8_t)((datetmpreg & (RTC_DR_MT | RTC_DR_MU)) >> 8); | |
669 sDate->Date = (uint8_t)(datetmpreg & (RTC_DR_DT | RTC_DR_DU)); | |
670 sDate->WeekDay = (uint8_t)((datetmpreg & (RTC_DR_WDU)) >> 13); | |
671 | |
672 /* Convert the date structure parameters to Binary format */ | |
673 sDate->Year = (uint8_t)RTC_Bcd2ToByte(sDate->Year); | |
674 sDate->Month = (uint8_t)RTC_Bcd2ToByte(sDate->Month); | |
675 sDate->Date = (uint8_t)RTC_Bcd2ToByte(sDate->Date); | |
676 } | |
677 | |
678 void translateTime(uint32_t tmpreg, RTC_TimeTypeDef *sTime) | |
679 { | |
680 tmpreg = (uint32_t)(tmpreg & RTC_TR_RESERVED_MASK); | |
681 | |
682 /* Fill the structure fields with the read parameters */ | |
683 sTime->Hours = (uint8_t)((tmpreg & (RTC_TR_HT | RTC_TR_HU)) >> 16); | |
684 sTime->Minutes = (uint8_t)((tmpreg & (RTC_TR_MNT | RTC_TR_MNU)) >>8); | |
685 sTime->Seconds = (uint8_t)(tmpreg & (RTC_TR_ST | RTC_TR_SU)); | |
686 sTime->TimeFormat = (uint8_t)((tmpreg & (RTC_TR_PM)) >> 16); | |
687 | |
688 /* Convert the time structure parameters to Binary format */ | |
689 sTime->Hours = (uint8_t)RTC_Bcd2ToByte(sTime->Hours); | |
690 sTime->Minutes = (uint8_t)RTC_Bcd2ToByte(sTime->Minutes); | |
691 sTime->Seconds = (uint8_t)RTC_Bcd2ToByte(sTime->Seconds); | |
692 sTime->SubSeconds = 0; | |
693 } | |
694 | |
270
2e58a4094770
feature, debug: make simulator write a logbook entry
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
695 void resetEvents(const SDiveState *pStateUsed) |
38 | 696 { |
270
2e58a4094770
feature, debug: make simulator write a logbook entry
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
697 memset((void *)&pStateUsed->events, 0, sizeof(SEvents)); |
38 | 698 } |
699 | |
700 | |
701 uint32_t CRC_CalcBlockCRC_moreThan768000(uint32_t *buffer1, uint32_t *buffer2, uint32_t words) | |
702 { | |
703 cm_t crc_model; | |
704 uint32_t word_to_do; | |
705 uint8_t byte_to_do; | |
706 int i; | |
707 | |
708 // Values for the STM32F generator. | |
709 | |
710 crc_model.cm_width = 32; // 32-bit CRC | |
711 crc_model.cm_poly = 0x04C11DB7; // CRC-32 polynomial | |
712 crc_model.cm_init = 0xFFFFFFFF; // CRC initialized to 1's | |
713 crc_model.cm_refin = FALSE; // CRC calculated MSB first | |
714 crc_model.cm_refot = FALSE; // Final result is not bit-reversed | |
715 crc_model.cm_xorot = 0x00000000; // Final result XOR'ed with this | |
716 | |
717 cm_ini(&crc_model); | |
718 | |
719 while (words--) | |
720 { | |
721 // The STM32F10x hardware does 32-bit words at a time!!! | |
722 if(words > (768000/4)) | |
723 word_to_do = *buffer2++; | |
724 else | |
725 word_to_do = *buffer1++; | |
726 | |
727 // Do all bytes in the 32-bit word. | |
728 | |
729 for (i = 0; i < sizeof(word_to_do); i++) | |
730 { | |
731 // We calculate a *byte* at a time. If the CRC is MSB first we | |
732 // do the next MS byte and vica-versa. | |
733 | |
734 if (crc_model.cm_refin == FALSE) | |
735 { | |
736 // MSB first. Do the next MS byte. | |
737 | |
738 byte_to_do = (uint8_t) ((word_to_do & 0xFF000000) >> 24); | |
739 word_to_do <<= 8; | |
740 } | |
741 else | |
742 { | |
743 // LSB first. Do the next LS byte. | |
744 | |
745 byte_to_do = (uint8_t) (word_to_do & 0x000000FF); | |
746 word_to_do >>= 8; | |
747 } | |
748 | |
749 cm_nxt(&crc_model, byte_to_do); | |
750 } | |
751 } | |
752 | |
753 // Return the final result. | |
754 | |
755 return (cm_crc(&crc_model)); | |
756 } | |
757 | |
758 | |
759 uint32_t CRC_CalcBlockCRC(uint32_t *buffer, uint32_t words) | |
760 { | |
761 cm_t crc_model; | |
762 uint32_t word_to_do; | |
763 uint8_t byte_to_do; | |
764 int i; | |
765 | |
766 // Values for the STM32F generator. | |
767 | |
768 crc_model.cm_width = 32; // 32-bit CRC | |
769 crc_model.cm_poly = 0x04C11DB7; // CRC-32 polynomial | |
770 crc_model.cm_init = 0xFFFFFFFF; // CRC initialized to 1's | |
771 crc_model.cm_refin = FALSE; // CRC calculated MSB first | |
772 crc_model.cm_refot = FALSE; // Final result is not bit-reversed | |
773 crc_model.cm_xorot = 0x00000000; // Final result XOR'ed with this | |
774 | |
775 cm_ini(&crc_model); | |
776 | |
777 while (words--) | |
778 { | |
779 // The STM32F10x hardware does 32-bit words at a time!!! | |
780 | |
781 word_to_do = *buffer++; | |
782 | |
783 // Do all bytes in the 32-bit word. | |
784 | |
785 for (i = 0; i < sizeof(word_to_do); i++) | |
786 { | |
787 // We calculate a *byte* at a time. If the CRC is MSB first we | |
788 // do the next MS byte and vica-versa. | |
789 | |
790 if (crc_model.cm_refin == FALSE) | |
791 { | |
792 // MSB first. Do the next MS byte. | |
793 | |
794 byte_to_do = (uint8_t) ((word_to_do & 0xFF000000) >> 24); | |
795 word_to_do <<= 8; | |
796 } | |
797 else | |
798 { | |
799 // LSB first. Do the next LS byte. | |
800 | |
801 byte_to_do = (uint8_t) (word_to_do & 0x000000FF); | |
802 word_to_do >>= 8; | |
803 } | |
804 | |
805 cm_nxt(&crc_model, byte_to_do); | |
806 } | |
807 } | |
808 | |
809 // Return the final result. | |
810 | |
811 return (cm_crc(&crc_model)); | |
812 } | |
813 | |
302
eba8d1eb5bef
bugfix, cleanup: keep both is_ambient_pressure_close_to_surface in sync
Jan Mulder <jlmulder@xs4all.nl>
parents:
300
diff
changeset
|
814 // This code is also in RTE. Keep it in sync when editing |
38 | 815 _Bool is_ambient_pressure_close_to_surface(SLifeData *lifeData) |
816 { | |
310
95928ef3986f
Make dive mode detection more advanced
Jan Mulder <jlmulder@xs4all.nl>
parents:
302
diff
changeset
|
817 if (lifeData->pressure_ambient_bar > 1.16) |
95928ef3986f
Make dive mode detection more advanced
Jan Mulder <jlmulder@xs4all.nl>
parents:
302
diff
changeset
|
818 return false; |
95928ef3986f
Make dive mode detection more advanced
Jan Mulder <jlmulder@xs4all.nl>
parents:
302
diff
changeset
|
819 else if(lifeData->pressure_ambient_bar < (lifeData->pressure_surface_bar + 0.1f)) |
38 | 820 return true; |
821 else | |
822 return false; | |
823 } | |
539
d784f281833a
Added inertia simulation for compass heading:
Ideenmodellierer
parents:
310
diff
changeset
|
824 |
d784f281833a
Added inertia simulation for compass heading:
Ideenmodellierer
parents:
310
diff
changeset
|
825 void compass_Inertia(float newHeading) |
d784f281833a
Added inertia simulation for compass heading:
Ideenmodellierer
parents:
310
diff
changeset
|
826 { |
d784f281833a
Added inertia simulation for compass heading:
Ideenmodellierer
parents:
310
diff
changeset
|
827 float newTarget = newHeading; |
d784f281833a
Added inertia simulation for compass heading:
Ideenmodellierer
parents:
310
diff
changeset
|
828 |
d784f281833a
Added inertia simulation for compass heading:
Ideenmodellierer
parents:
310
diff
changeset
|
829 if(settingsGetPointer()->compassInertia == 0) |
d784f281833a
Added inertia simulation for compass heading:
Ideenmodellierer
parents:
310
diff
changeset
|
830 { |
d784f281833a
Added inertia simulation for compass heading:
Ideenmodellierer
parents:
310
diff
changeset
|
831 compass_compensated = newHeading; |
d784f281833a
Added inertia simulation for compass heading:
Ideenmodellierer
parents:
310
diff
changeset
|
832 } |
d784f281833a
Added inertia simulation for compass heading:
Ideenmodellierer
parents:
310
diff
changeset
|
833 else |
d784f281833a
Added inertia simulation for compass heading:
Ideenmodellierer
parents:
310
diff
changeset
|
834 { |
d784f281833a
Added inertia simulation for compass heading:
Ideenmodellierer
parents:
310
diff
changeset
|
835 if((compass_compensated > 270.0) && (newHeading < 90.0)) /* transition passing 0 clockwise */ |
d784f281833a
Added inertia simulation for compass heading:
Ideenmodellierer
parents:
310
diff
changeset
|
836 { |
d784f281833a
Added inertia simulation for compass heading:
Ideenmodellierer
parents:
310
diff
changeset
|
837 newTarget = newHeading + 360.0; |
d784f281833a
Added inertia simulation for compass heading:
Ideenmodellierer
parents:
310
diff
changeset
|
838 } |
d784f281833a
Added inertia simulation for compass heading:
Ideenmodellierer
parents:
310
diff
changeset
|
839 |
d784f281833a
Added inertia simulation for compass heading:
Ideenmodellierer
parents:
310
diff
changeset
|
840 if((compass_compensated < 90.0) && (newHeading > 270.0)) /* transition passing 0 counter clockwise */ |
d784f281833a
Added inertia simulation for compass heading:
Ideenmodellierer
parents:
310
diff
changeset
|
841 { |
d784f281833a
Added inertia simulation for compass heading:
Ideenmodellierer
parents:
310
diff
changeset
|
842 newTarget = newHeading - 360.0; |
d784f281833a
Added inertia simulation for compass heading:
Ideenmodellierer
parents:
310
diff
changeset
|
843 } |
d784f281833a
Added inertia simulation for compass heading:
Ideenmodellierer
parents:
310
diff
changeset
|
844 |
d784f281833a
Added inertia simulation for compass heading:
Ideenmodellierer
parents:
310
diff
changeset
|
845 compass_compensated = compass_compensated + ((newTarget - compass_compensated) / (COMPASS_FRACTION * (settingsGetPointer()->compassInertia))); |
d784f281833a
Added inertia simulation for compass heading:
Ideenmodellierer
parents:
310
diff
changeset
|
846 if(compass_compensated < 0.0) |
d784f281833a
Added inertia simulation for compass heading:
Ideenmodellierer
parents:
310
diff
changeset
|
847 { |
d784f281833a
Added inertia simulation for compass heading:
Ideenmodellierer
parents:
310
diff
changeset
|
848 compass_compensated += 360.0; |
d784f281833a
Added inertia simulation for compass heading:
Ideenmodellierer
parents:
310
diff
changeset
|
849 } |
d784f281833a
Added inertia simulation for compass heading:
Ideenmodellierer
parents:
310
diff
changeset
|
850 if(compass_compensated >= 360.0) |
d784f281833a
Added inertia simulation for compass heading:
Ideenmodellierer
parents:
310
diff
changeset
|
851 { |
d784f281833a
Added inertia simulation for compass heading:
Ideenmodellierer
parents:
310
diff
changeset
|
852 compass_compensated -= 360.0; |
d784f281833a
Added inertia simulation for compass heading:
Ideenmodellierer
parents:
310
diff
changeset
|
853 } |
d784f281833a
Added inertia simulation for compass heading:
Ideenmodellierer
parents:
310
diff
changeset
|
854 } |
d784f281833a
Added inertia simulation for compass heading:
Ideenmodellierer
parents:
310
diff
changeset
|
855 } |
d784f281833a
Added inertia simulation for compass heading:
Ideenmodellierer
parents:
310
diff
changeset
|
856 |
d784f281833a
Added inertia simulation for compass heading:
Ideenmodellierer
parents:
310
diff
changeset
|
857 float compass_getCompensated() |
d784f281833a
Added inertia simulation for compass heading:
Ideenmodellierer
parents:
310
diff
changeset
|
858 { |
d784f281833a
Added inertia simulation for compass heading:
Ideenmodellierer
parents:
310
diff
changeset
|
859 return compass_compensated; |
d784f281833a
Added inertia simulation for compass heading:
Ideenmodellierer
parents:
310
diff
changeset
|
860 } |
d784f281833a
Added inertia simulation for compass heading:
Ideenmodellierer
parents:
310
diff
changeset
|
861 |
662 | 862 uint8_t isLoopMode(uint8_t Mode) |
863 { | |
864 uint8_t retVal = 0; | |
865 if((Mode == DIVEMODE_CCR) || (Mode == DIVEMODE_PSCR)) | |
866 { | |
867 retVal = 1; | |
868 } | |
869 return retVal; | |
870 } | |
774
6169309d6eb9
more menu items for the compass menu: Delete bearing, and reset to land based bearing. I have also re-enabled the real time bearing display in the menu - makes it easier to set the correct bearing. (mikeller)
heinrichsweikamp
parents:
771
diff
changeset
|
871 |
776
45b8f3c2acce
Add support for a configurable compass declination in a range of -99 to 99 degrees.
heinrichsweikamp
parents:
774
diff
changeset
|
872 |
45b8f3c2acce
Add support for a configurable compass declination in a range of -99 to 99 degrees.
heinrichsweikamp
parents:
774
diff
changeset
|
873 bool isCompassCalibrated(void) |
45b8f3c2acce
Add support for a configurable compass declination in a range of -99 to 99 degrees.
heinrichsweikamp
parents:
774
diff
changeset
|
874 { |
45b8f3c2acce
Add support for a configurable compass declination in a range of -99 to 99 degrees.
heinrichsweikamp
parents:
774
diff
changeset
|
875 return stateUsed->lifeData.compass_heading != -1; |
45b8f3c2acce
Add support for a configurable compass declination in a range of -99 to 99 degrees.
heinrichsweikamp
parents:
774
diff
changeset
|
876 } |
45b8f3c2acce
Add support for a configurable compass declination in a range of -99 to 99 degrees.
heinrichsweikamp
parents:
774
diff
changeset
|
877 |
45b8f3c2acce
Add support for a configurable compass declination in a range of -99 to 99 degrees.
heinrichsweikamp
parents:
774
diff
changeset
|
878 |
774
6169309d6eb9
more menu items for the compass menu: Delete bearing, and reset to land based bearing. I have also re-enabled the real time bearing display in the menu - makes it easier to set the correct bearing. (mikeller)
heinrichsweikamp
parents:
771
diff
changeset
|
879 void setCompassHeading(uint16_t heading) |
6169309d6eb9
more menu items for the compass menu: Delete bearing, and reset to land based bearing. I have also re-enabled the real time bearing display in the menu - makes it easier to set the correct bearing. (mikeller)
heinrichsweikamp
parents:
771
diff
changeset
|
880 { |
6169309d6eb9
more menu items for the compass menu: Delete bearing, and reset to land based bearing. I have also re-enabled the real time bearing display in the menu - makes it easier to set the correct bearing. (mikeller)
heinrichsweikamp
parents:
771
diff
changeset
|
881 |
6169309d6eb9
more menu items for the compass menu: Delete bearing, and reset to land based bearing. I have also re-enabled the real time bearing display in the menu - makes it easier to set the correct bearing. (mikeller)
heinrichsweikamp
parents:
771
diff
changeset
|
882 // if heading == 0 set compassHeading to 360, because compassHeading == 0 means 'off' |
6169309d6eb9
more menu items for the compass menu: Delete bearing, and reset to land based bearing. I have also re-enabled the real time bearing display in the menu - makes it easier to set the correct bearing. (mikeller)
heinrichsweikamp
parents:
771
diff
changeset
|
883 |
6169309d6eb9
more menu items for the compass menu: Delete bearing, and reset to land based bearing. I have also re-enabled the real time bearing display in the menu - makes it easier to set the correct bearing. (mikeller)
heinrichsweikamp
parents:
771
diff
changeset
|
884 stateUsedWrite->diveSettings.compassHeading = ((heading - 360) % 360) + 360; |
6169309d6eb9
more menu items for the compass menu: Delete bearing, and reset to land based bearing. I have also re-enabled the real time bearing display in the menu - makes it easier to set the correct bearing. (mikeller)
heinrichsweikamp
parents:
771
diff
changeset
|
885 } |
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:
776
diff
changeset
|
886 |
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:
776
diff
changeset
|
887 |
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:
776
diff
changeset
|
888 const SDecoinfo *getDecoInfo(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:
776
diff
changeset
|
889 { |
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:
776
diff
changeset
|
890 const SDecoinfo *decoInfo; |
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:
776
diff
changeset
|
891 if (stateUsed->diveSettings.deco_type.ub.standard == GF_MODE) { |
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:
776
diff
changeset
|
892 decoInfo = &stateUsed->decolistBuehlmann; |
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:
776
diff
changeset
|
893 } 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:
776
diff
changeset
|
894 decoInfo = &stateUsed->decolistVPM; |
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:
776
diff
changeset
|
895 } |
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:
776
diff
changeset
|
896 |
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:
776
diff
changeset
|
897 return decoInfo; |
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:
776
diff
changeset
|
898 } |
805
dd7ce655db26
Adds a simple countdown timer, available as a custom view in surface and dive mode.
heinrichsweikamp
parents:
788
diff
changeset
|
899 |
dd7ce655db26
Adds a simple countdown timer, available as a custom view in surface and dive mode.
heinrichsweikamp
parents:
788
diff
changeset
|
900 |
dd7ce655db26
Adds a simple countdown timer, available as a custom view in surface and dive mode.
heinrichsweikamp
parents:
788
diff
changeset
|
901 void disableTimer(void) |
dd7ce655db26
Adds a simple countdown timer, available as a custom view in surface and dive mode.
heinrichsweikamp
parents:
788
diff
changeset
|
902 { |
dd7ce655db26
Adds a simple countdown timer, available as a custom view in surface and dive mode.
heinrichsweikamp
parents:
788
diff
changeset
|
903 stateUsedWrite->timerState = TIMER_STATE_OFF; |
dd7ce655db26
Adds a simple countdown timer, available as a custom view in surface and dive mode.
heinrichsweikamp
parents:
788
diff
changeset
|
904 } |