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