Mercurial > public > ostc4
annotate Discovery/Src/data_central.c @ 950:922ee3d7d2f3 Evo_2_23 tip
Increase brightness for inactive gases to improve readability in the OSTC 5.
author | heinrichsweikamp |
---|---|
date | Thu, 26 Dec 2024 12:03:08 +0100 |
parents | c6b858f2e025 |
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; | |
902 | 350 stateReal.diveSettings.vpm_tableMode = pSettings->VPM_conservatism.ub.alternative; |
38 | 351 stateReal.diveSettings.deco_type.uw = pSettings->deco_type.uw; |
352 stateReal.diveSettings.fallbackOption = pSettings->fallbackToFixedSetpoint; | |
353 stateReal.diveSettings.ppo2sensors_deactivated = pSettings->ppo2sensors_deactivated; | |
354 stateReal.diveSettings.future_TTS_minutes = pSettings->future_TTS; | |
355 | |
662 | 356 stateReal.diveSettings.pscr_lung_ratio = pSettings->pscr_lung_ratio; |
357 stateReal.diveSettings.pscr_o2_drop = pSettings->pscr_o2_drop; | |
358 | |
359 if(stateReal.diveSettings.diveMode == DIVEMODE_PSCR) | |
360 { | |
361 for(i=0; i<5; i++) | |
362 { | |
363 stateReal.diveSettings.decogaslist[i].pscr_factor = 1.0 / stateReal.diveSettings.pscr_lung_ratio * stateReal.diveSettings.pscr_o2_drop; | |
364 } | |
365 } | |
366 | |
38 | 367 decom_CreateGasChangeList(&stateReal.diveSettings, &stateReal.lifeData); // decogaslist |
368 stateReal.diveSettings.internal__pressure_first_stop_ambient_bar_as_upper_limit_for_gf_low_otherwise_zero = 0; | |
369 | |
370 /* for safety */ | |
371 stateReal.diveSettings.input_second_to_last_stop_depth_bar = stateReal.diveSettings.last_stop_depth_bar + stateReal.diveSettings.input_next_stop_increment_depth_bar; | |
372 /* and the proper calc */ | |
662 | 373 for(i = 1; i <10; i++) |
38 | 374 { |
375 if(stateReal.diveSettings.input_next_stop_increment_depth_bar * i > stateReal.diveSettings.last_stop_depth_bar) | |
376 { | |
377 stateReal.diveSettings.input_second_to_last_stop_depth_bar = stateReal.diveSettings.input_next_stop_increment_depth_bar * i; | |
378 break; | |
379 } | |
380 } | |
834
2a8af51ab04d
Added event based display changes for big font view:
Ideenmodellierer
parents:
805
diff
changeset
|
381 /* generate Bitfield of active T3 views */ |
2a8af51ab04d
Added event based display changes for big font view:
Ideenmodellierer
parents:
805
diff
changeset
|
382 stateReal.diveSettings.activeAFViews = 0; |
2a8af51ab04d
Added event based display changes for big font view:
Ideenmodellierer
parents:
805
diff
changeset
|
383 if(t3_customview_disabled(CVIEW_T3_Navigation) == 0) |
2a8af51ab04d
Added event based display changes for big font view:
Ideenmodellierer
parents:
805
diff
changeset
|
384 { |
2a8af51ab04d
Added event based display changes for big font view:
Ideenmodellierer
parents:
805
diff
changeset
|
385 stateReal.diveSettings.activeAFViews |= (1 << CVIEW_T3_Navigation); |
2a8af51ab04d
Added event based display changes for big font view:
Ideenmodellierer
parents:
805
diff
changeset
|
386 } |
838 | 387 if(t3_customview_disabled(CVIEW_T3_GasList) == 0) |
388 { | |
389 stateReal.diveSettings.activeAFViews |= (1 << CVIEW_T3_GasList); | |
390 } | |
841 | 391 if(t3_customview_disabled(CVIEW_T3_DecoTTS) == 0) |
392 { | |
393 stateReal.diveSettings.activeAFViews |= (1 << CVIEW_T3_DecoTTS); | |
394 } | |
38 | 395 } |
396 | |
397 | |
398 void copyDiveSettingsToSim(void) | |
399 { | |
400 memcpy(&stateSim, &stateReal, sizeof(stateReal)); | |
401 } | |
402 | |
403 | |
404 void copyVpmRepetetiveDataToSim(void) | |
405 { | |
406 SDiveState * pSimData = stateSimGetPointerWrite(); | |
407 const SVpmRepetitiveData * pVpmData = stateVpmRepetitiveDataGetPointer(); | |
408 | |
409 if(pVpmData->is_data_from_RTE_CPU) | |
410 { | |
411 for(int i=0; i<16;i++) | |
412 { | |
413 pSimData->vpm.adjusted_critical_radius_he[i] = pVpmData->adjusted_critical_radius_he[i]; | |
414 pSimData->vpm.adjusted_critical_radius_n2[i] = pVpmData->adjusted_critical_radius_n2[i]; | |
415 | |
416 pSimData->vpm.adjusted_crushing_pressure_he[i] = pVpmData->adjusted_crushing_pressure_he[i]; | |
417 pSimData->vpm.adjusted_crushing_pressure_n2[i] = pVpmData->adjusted_crushing_pressure_n2[i]; | |
418 | |
419 pSimData->vpm.initial_allowable_gradient_he[i] = pVpmData->initial_allowable_gradient_he[i]; | |
420 pSimData->vpm.initial_allowable_gradient_n2[i] = pVpmData->initial_allowable_gradient_n2[i]; | |
421 | |
422 pSimData->vpm.max_actual_gradient[i] = pVpmData->max_actual_gradient[i]; | |
423 } | |
424 pSimData->vpm.repetitive_variables_not_valid = pVpmData->repetitive_variables_not_valid; | |
425 } | |
426 } | |
427 | |
428 | |
429 void updateSetpointStateUsed(void) | |
430 { | |
682 | 431 if(!isLoopMode(stateUsed->diveSettings.diveMode)) |
38 | 432 { |
271
1303747b5ba2
cleanup: also write gas and setpoint changes in simulator mode
Jan Mulder <jlmulder@xs4all.nl>
parents:
270
diff
changeset
|
433 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
|
434 stateUsedWrite->lifeData.ppO2 = decom_calc_ppO2(stateUsed->lifeData.pressure_ambient_bar, &stateUsed->lifeData.actualGas); |
38 | 435 } |
436 else | |
437 { | |
438 if(stateUsed->diveSettings.CCR_Mode == CCRMODE_Sensors) | |
439 { | |
271
1303747b5ba2
cleanup: also write gas and setpoint changes in simulator mode
Jan Mulder <jlmulder@xs4all.nl>
parents:
270
diff
changeset
|
440 stateUsedWrite->lifeData.actualGas.setPoint_cbar = get_ppO2SensorWeightedResult_cbar(); |
38 | 441 } |
662 | 442 #ifdef ENABLE_PSCR_MODE |
443 if(stateUsed->diveSettings.diveMode == DIVEMODE_PSCR) /* calculate a ppO2 value based on assumptions ( transfered approach from hwos code) */ | |
444 { | |
445 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); | |
446 if(stateUsed->diveSettings.CCR_Mode == CCRMODE_Simulation) | |
447 { | |
448 stateUsedWrite->lifeData.actualGas.setPoint_cbar = stateUsedWrite->lifeData.ppo2Simulated_bar * 100; | |
449 } | |
450 } | |
451 #endif | |
452 /* limit calculated value to the physically possible if needed */ | |
38 | 453 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
|
454 stateUsedWrite->lifeData.ppO2 = stateUsed->lifeData.pressure_ambient_bar; |
38 | 455 else |
271
1303747b5ba2
cleanup: also write gas and setpoint changes in simulator mode
Jan Mulder <jlmulder@xs4all.nl>
parents:
270
diff
changeset
|
456 stateUsedWrite->lifeData.ppO2 = ((float)stateUsed->lifeData.actualGas.setPoint_cbar) / 100; |
38 | 457 } |
458 } | |
459 | |
460 void setActualGasFirst(SLifeData *lifeData) | |
461 { | |
462 SSettings* pSettings = settingsGetPointer(); | |
463 uint8_t start = 0; | |
464 uint8_t gasId = 0; | |
465 uint8_t setpoint_cbar = 0; | |
466 | |
662 | 467 if(isLoopMode(pSettings->dive_mode)) |
38 | 468 { |
469 setpoint_cbar = pSettings->setpoint[1].setpoint_cbar; | |
470 start = NUM_OFFSET_DILUENT+1; | |
471 } | |
472 else | |
473 { | |
474 setpoint_cbar = 0; | |
475 start = 1; | |
476 } | |
477 | |
478 gasId = start; | |
479 for(int i=start;i<=NUM_GASES+start;i++) | |
480 { | |
481 if(pSettings->gas[i].note.ub.first) | |
482 { | |
483 gasId = i; | |
484 break; | |
485 } | |
486 } | |
487 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
|
488 |
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->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
|
490 lifeData->setpointLowDelayed = false; |
38 | 491 } |
492 | |
493 void setActualGasAir(SLifeData *lifeData) | |
494 { | |
495 uint8_t nitrogen; | |
496 nitrogen = 79; | |
497 lifeData->actualGas.GasIdInSettings = 0; | |
498 lifeData->actualGas.nitrogen_percentage = nitrogen; | |
499 lifeData->actualGas.helium_percentage =0; | |
500 lifeData->actualGas.setPoint_cbar = 0; | |
501 lifeData->actualGas.change_during_ascent_depth_meter_otherwise_zero = 0; | |
662 | 502 lifeData->actualGas.AppliedDiveMode = stateUsed->diveSettings.diveMode; |
38 | 503 } |
504 | |
505 | |
506 void setActualGas(SLifeData *lifeData, uint8_t gasId, uint8_t setpoint_cbar) | |
507 { | |
508 SSettings* pSettings = settingsGetPointer(); | |
509 uint8_t nitrogen; | |
510 | |
511 nitrogen = 100; | |
512 nitrogen -= pSettings->gas[gasId].oxygen_percentage; | |
513 nitrogen -= pSettings->gas[gasId].helium_percentage; | |
514 | |
515 lifeData->actualGas.GasIdInSettings = gasId; | |
516 lifeData->actualGas.nitrogen_percentage = nitrogen; | |
517 lifeData->actualGas.helium_percentage = pSettings->gas[gasId].helium_percentage; | |
518 lifeData->actualGas.setPoint_cbar = setpoint_cbar; | |
519 lifeData->actualGas.change_during_ascent_depth_meter_otherwise_zero = 0; | |
682 | 520 lifeData->actualGas.AppliedDiveMode = stateUsed->diveSettings.diveMode; |
662 | 521 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
|
522 if (isLoopMode(pSettings->dive_mode) && gasId > NUM_OFFSET_DILUENT) { |
38 | 523 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
|
524 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
|
525 } |
38 | 526 } |
527 | |
528 | |
529 void setActualGas_DM(SLifeData *lifeData, uint8_t gasId, uint8_t setpoint_cbar) | |
530 { | |
531 if(stateUsed->diveSettings.ccrOption && gasId < 6) | |
532 { | |
533 if(lifeData->actualGas.GasIdInSettings != gasId) | |
534 { | |
535 SSettings* pSettings = settingsGetPointer(); | |
271
1303747b5ba2
cleanup: also write gas and setpoint changes in simulator mode
Jan Mulder <jlmulder@xs4all.nl>
parents:
270
diff
changeset
|
536 stateUsedWrite->events.bailout = 1; |
1303747b5ba2
cleanup: also write gas and setpoint changes in simulator mode
Jan Mulder <jlmulder@xs4all.nl>
parents:
270
diff
changeset
|
537 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
|
538 stateUsedWrite->events.info_bailoutHe = pSettings->gas[gasId].helium_percentage; |
38 | 539 } |
540 } | |
541 else | |
542 { | |
543 if(lifeData->actualGas.GasIdInSettings != gasId) | |
544 { | |
271
1303747b5ba2
cleanup: also write gas and setpoint changes in simulator mode
Jan Mulder <jlmulder@xs4all.nl>
parents:
270
diff
changeset
|
545 stateUsedWrite->events.gasChange = 1; |
1303747b5ba2
cleanup: also write gas and setpoint changes in simulator mode
Jan Mulder <jlmulder@xs4all.nl>
parents:
270
diff
changeset
|
546 stateUsedWrite->events.info_GasChange = gasId; |
38 | 547 } |
548 if( lifeData->actualGas.setPoint_cbar != setpoint_cbar) | |
549 { | |
550 // 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
|
551 stateUsedWrite->events.setpointChange = 1; |
1303747b5ba2
cleanup: also write gas and setpoint changes in simulator mode
Jan Mulder <jlmulder@xs4all.nl>
parents:
270
diff
changeset
|
552 stateUsedWrite->events.info_SetpointChange = setpoint_cbar; |
38 | 553 } |
554 } | |
555 setActualGas(lifeData, gasId, setpoint_cbar); | |
556 } | |
557 | |
558 void setActualGas_ExtraGas(SLifeData *lifeData, uint8_t oxygen, uint8_t helium, uint8_t setpoint_cbar) | |
559 { | |
560 uint8_t nitrogen; | |
561 | |
562 nitrogen = 100; | |
563 nitrogen -= oxygen; | |
564 nitrogen -= helium; | |
565 | |
736
8a2337c7af52
Fixed logbook download after switch from CCR to extra (OC) gas if the extra gas
heinrichsweikamp
parents:
683
diff
changeset
|
566 |
864
fa431d42b5fb
Fix incorrect logging of bailout to Open Circuit when using the best gas.
heinrichsweikamp
parents:
805
diff
changeset
|
567 if ((lifeData->actualGas.nitrogen_percentage != nitrogen) || (lifeData->actualGas.helium_percentage != helium) || lifeData->actualGas.AppliedDiveMode != DIVEMODE_OC) |
38 | 568 { |
864
fa431d42b5fb
Fix incorrect logging of bailout to Open Circuit when using the best gas.
heinrichsweikamp
parents:
805
diff
changeset
|
569 if (stateUsed->diveSettings.ccrOption) { |
fa431d42b5fb
Fix incorrect logging of bailout to Open Circuit when using the best gas.
heinrichsweikamp
parents:
805
diff
changeset
|
570 stateUsedWrite->events.bailout = 1; |
fa431d42b5fb
Fix incorrect logging of bailout to Open Circuit when using the best gas.
heinrichsweikamp
parents:
805
diff
changeset
|
571 stateUsedWrite->events.info_bailoutHe = helium; |
fa431d42b5fb
Fix incorrect logging of bailout to Open Circuit when using the best gas.
heinrichsweikamp
parents:
805
diff
changeset
|
572 stateUsedWrite->events.info_bailoutO2 = oxygen; |
fa431d42b5fb
Fix incorrect logging of bailout to Open Circuit when using the best gas.
heinrichsweikamp
parents:
805
diff
changeset
|
573 } else { |
fa431d42b5fb
Fix incorrect logging of bailout to Open Circuit when using the best gas.
heinrichsweikamp
parents:
805
diff
changeset
|
574 stateUsedWrite->events.manualGasSet = 1; |
fa431d42b5fb
Fix incorrect logging of bailout to Open Circuit when using the best gas.
heinrichsweikamp
parents:
805
diff
changeset
|
575 stateUsedWrite->events.info_manualGasSetHe = helium; |
fa431d42b5fb
Fix incorrect logging of bailout to Open Circuit when using the best gas.
heinrichsweikamp
parents:
805
diff
changeset
|
576 stateUsedWrite->events.info_manualGasSetO2 = oxygen; |
fa431d42b5fb
Fix incorrect logging of bailout to Open Circuit when using the best gas.
heinrichsweikamp
parents:
805
diff
changeset
|
577 } |
38 | 578 } |
864
fa431d42b5fb
Fix incorrect logging of bailout to Open Circuit when using the best gas.
heinrichsweikamp
parents:
805
diff
changeset
|
579 |
38 | 580 if( lifeData->actualGas.setPoint_cbar != setpoint_cbar) |
581 { | |
271
1303747b5ba2
cleanup: also write gas and setpoint changes in simulator mode
Jan Mulder <jlmulder@xs4all.nl>
parents:
270
diff
changeset
|
582 stateUsedWrite->events.setpointChange = 1; |
1303747b5ba2
cleanup: also write gas and setpoint changes in simulator mode
Jan Mulder <jlmulder@xs4all.nl>
parents:
270
diff
changeset
|
583 stateUsedWrite->events.info_SetpointChange = setpoint_cbar; |
38 | 584 } |
585 lifeData->actualGas.GasIdInSettings = 0; | |
586 lifeData->actualGas.nitrogen_percentage = nitrogen; | |
587 lifeData->actualGas.helium_percentage = helium; | |
588 lifeData->actualGas.setPoint_cbar = setpoint_cbar; | |
589 lifeData->actualGas.change_during_ascent_depth_meter_otherwise_zero = 0; | |
662 | 590 lifeData->actualGas.AppliedDiveMode = stateUsed->diveSettings.diveMode; |
38 | 591 } |
592 | |
593 void setButtonResponsiveness(uint8_t *ButtonSensitivyList) | |
594 { | |
595 SDataReceiveFromMaster *pDataOut = dataOutGetPointer(); | |
596 | |
597 for(int i=0; i<4; i++) | |
598 { | |
599 pDataOut->data.buttonResponsiveness[i] = settingsHelperButtonSens_translate_percentage_to_hwOS_values(ButtonSensitivyList[i]); | |
600 } | |
601 pDataOut->setButtonSensitivityNow = 1; | |
602 } | |
603 | |
604 | |
605 void setDate(RTC_DateTypeDef Sdate) | |
606 { | |
607 SDataReceiveFromMaster *pDataOut = dataOutGetPointer(); | |
608 | |
609 pDataOut->data.newDate = Sdate; | |
610 pDataOut->setDateNow = 1; | |
611 } | |
612 | |
613 | |
614 void setTime(RTC_TimeTypeDef Stime) | |
615 { | |
616 SDataReceiveFromMaster *pDataOut = dataOutGetPointer(); | |
617 | |
618 pDataOut->data.newTime = Stime; | |
619 pDataOut->setTimeNow = 1; | |
620 } | |
621 | |
622 | |
623 void setBatteryPercentage(uint8_t newChargePercentage) | |
624 { | |
625 SDataReceiveFromMaster *pDataOut = dataOutGetPointer(); | |
626 | |
627 pDataOut->data.newBatteryGaugePercentageFloat = settingsGetPointer()->lastKnownBatteryPercentage; | |
628 pDataOut->setBatteryGaugeNow = 1; | |
629 } | |
630 | |
631 | |
632 void calibrateCompass(void) | |
633 { | |
634 SDataReceiveFromMaster *pDataOut = dataOutGetPointer(); | |
635 pDataOut->calibrateCompassNow = 1; | |
636 } | |
637 | |
638 | |
639 void clearDeco(void) | |
640 { | |
641 SDataReceiveFromMaster *pDataOut = dataOutGetPointer(); | |
642 pDataOut->clearDecoNow = 1; | |
643 | |
644 stateRealGetPointerWrite()->cnsHigh_at_the_end_of_dive = 0; | |
645 stateRealGetPointerWrite()->decoMissed_at_the_end_of_dive = 0; | |
646 } | |
647 | |
648 | |
300
5ca177d2df5d
cleanup: remove commented/unused code, make static
Jan Mulder <jlmulder@xs4all.nl>
parents:
281
diff
changeset
|
649 static int32_t helper_days_from_civil(int32_t y, uint32_t m, uint32_t d) |
38 | 650 { |
651 y += 2000; | |
652 y -= m <= 2; | |
653 int32_t era = (y >= 0 ? y : y-399) / 400; | |
654 uint32_t yoe = (uint32_t)(y - era * 400); // [0, 399] | |
655 uint32_t doy = (153*(m + (m > 2 ? -3 : 9)) + 2)/5 + d-1; // [0, 365] | |
656 uint32_t doe = yoe * 365 + yoe/4 - yoe/100 + doy; // [0, 146096] | |
657 return era * 146097 + (int32_t)(doe) - 719468; | |
658 } | |
659 | |
660 | |
300
5ca177d2df5d
cleanup: remove commented/unused code, make static
Jan Mulder <jlmulder@xs4all.nl>
parents:
281
diff
changeset
|
661 static uint8_t helper_weekday_from_days(int32_t z) |
38 | 662 { |
663 return (uint8_t)(z >= -4 ? (z+4) % 7 : (z+5) % 7 + 6); | |
664 } | |
665 | |
666 | |
667 void setWeekday(RTC_DateTypeDef *sDate) | |
668 { | |
669 uint8_t day; | |
670 // [0, 6] -> [Sun, Sat] | |
671 day = helper_weekday_from_days(helper_days_from_civil(sDate->Year, sDate->Month, sDate->Date)); | |
672 // [1, 7] -> [Mon, Sun] | |
673 if(day == 0) | |
674 day = 7; | |
675 sDate->WeekDay = day; | |
676 } | |
677 | |
678 | |
679 void translateDate(uint32_t datetmpreg, RTC_DateTypeDef *sDate) | |
680 { | |
681 datetmpreg = (uint32_t)(datetmpreg & RTC_DR_RESERVED_MASK); | |
682 | |
683 /* Fill the structure fields with the read parameters */ | |
684 sDate->Year = (uint8_t)((datetmpreg & (RTC_DR_YT | RTC_DR_YU)) >> 16); | |
685 sDate->Month = (uint8_t)((datetmpreg & (RTC_DR_MT | RTC_DR_MU)) >> 8); | |
686 sDate->Date = (uint8_t)(datetmpreg & (RTC_DR_DT | RTC_DR_DU)); | |
687 sDate->WeekDay = (uint8_t)((datetmpreg & (RTC_DR_WDU)) >> 13); | |
688 | |
689 /* Convert the date structure parameters to Binary format */ | |
690 sDate->Year = (uint8_t)RTC_Bcd2ToByte(sDate->Year); | |
691 sDate->Month = (uint8_t)RTC_Bcd2ToByte(sDate->Month); | |
692 sDate->Date = (uint8_t)RTC_Bcd2ToByte(sDate->Date); | |
693 } | |
694 | |
695 void translateTime(uint32_t tmpreg, RTC_TimeTypeDef *sTime) | |
696 { | |
697 tmpreg = (uint32_t)(tmpreg & RTC_TR_RESERVED_MASK); | |
698 | |
699 /* Fill the structure fields with the read parameters */ | |
700 sTime->Hours = (uint8_t)((tmpreg & (RTC_TR_HT | RTC_TR_HU)) >> 16); | |
701 sTime->Minutes = (uint8_t)((tmpreg & (RTC_TR_MNT | RTC_TR_MNU)) >>8); | |
702 sTime->Seconds = (uint8_t)(tmpreg & (RTC_TR_ST | RTC_TR_SU)); | |
703 sTime->TimeFormat = (uint8_t)((tmpreg & (RTC_TR_PM)) >> 16); | |
704 | |
705 /* Convert the time structure parameters to Binary format */ | |
706 sTime->Hours = (uint8_t)RTC_Bcd2ToByte(sTime->Hours); | |
707 sTime->Minutes = (uint8_t)RTC_Bcd2ToByte(sTime->Minutes); | |
708 sTime->Seconds = (uint8_t)RTC_Bcd2ToByte(sTime->Seconds); | |
709 sTime->SubSeconds = 0; | |
710 } | |
711 | |
270
2e58a4094770
feature, debug: make simulator write a logbook entry
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
712 void resetEvents(const SDiveState *pStateUsed) |
38 | 713 { |
270
2e58a4094770
feature, debug: make simulator write a logbook entry
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
714 memset((void *)&pStateUsed->events, 0, sizeof(SEvents)); |
38 | 715 } |
716 | |
717 | |
718 uint32_t CRC_CalcBlockCRC_moreThan768000(uint32_t *buffer1, uint32_t *buffer2, uint32_t words) | |
719 { | |
720 cm_t crc_model; | |
721 uint32_t word_to_do; | |
722 uint8_t byte_to_do; | |
723 int i; | |
724 | |
725 // Values for the STM32F generator. | |
726 | |
727 crc_model.cm_width = 32; // 32-bit CRC | |
728 crc_model.cm_poly = 0x04C11DB7; // CRC-32 polynomial | |
729 crc_model.cm_init = 0xFFFFFFFF; // CRC initialized to 1's | |
730 crc_model.cm_refin = FALSE; // CRC calculated MSB first | |
731 crc_model.cm_refot = FALSE; // Final result is not bit-reversed | |
732 crc_model.cm_xorot = 0x00000000; // Final result XOR'ed with this | |
733 | |
734 cm_ini(&crc_model); | |
735 | |
736 while (words--) | |
737 { | |
738 // The STM32F10x hardware does 32-bit words at a time!!! | |
739 if(words > (768000/4)) | |
740 word_to_do = *buffer2++; | |
741 else | |
742 word_to_do = *buffer1++; | |
743 | |
744 // Do all bytes in the 32-bit word. | |
745 | |
746 for (i = 0; i < sizeof(word_to_do); i++) | |
747 { | |
748 // We calculate a *byte* at a time. If the CRC is MSB first we | |
749 // do the next MS byte and vica-versa. | |
750 | |
751 if (crc_model.cm_refin == FALSE) | |
752 { | |
753 // MSB first. Do the next MS byte. | |
754 | |
755 byte_to_do = (uint8_t) ((word_to_do & 0xFF000000) >> 24); | |
756 word_to_do <<= 8; | |
757 } | |
758 else | |
759 { | |
760 // LSB first. Do the next LS byte. | |
761 | |
762 byte_to_do = (uint8_t) (word_to_do & 0x000000FF); | |
763 word_to_do >>= 8; | |
764 } | |
765 | |
766 cm_nxt(&crc_model, byte_to_do); | |
767 } | |
768 } | |
769 | |
770 // Return the final result. | |
771 | |
772 return (cm_crc(&crc_model)); | |
773 } | |
774 | |
775 | |
776 uint32_t CRC_CalcBlockCRC(uint32_t *buffer, uint32_t words) | |
777 { | |
778 cm_t crc_model; | |
779 uint32_t word_to_do; | |
780 uint8_t byte_to_do; | |
781 int i; | |
782 | |
783 // Values for the STM32F generator. | |
784 | |
785 crc_model.cm_width = 32; // 32-bit CRC | |
786 crc_model.cm_poly = 0x04C11DB7; // CRC-32 polynomial | |
787 crc_model.cm_init = 0xFFFFFFFF; // CRC initialized to 1's | |
788 crc_model.cm_refin = FALSE; // CRC calculated MSB first | |
789 crc_model.cm_refot = FALSE; // Final result is not bit-reversed | |
790 crc_model.cm_xorot = 0x00000000; // Final result XOR'ed with this | |
791 | |
792 cm_ini(&crc_model); | |
793 | |
794 while (words--) | |
795 { | |
796 // The STM32F10x hardware does 32-bit words at a time!!! | |
797 | |
798 word_to_do = *buffer++; | |
799 | |
800 // Do all bytes in the 32-bit word. | |
801 | |
802 for (i = 0; i < sizeof(word_to_do); i++) | |
803 { | |
804 // We calculate a *byte* at a time. If the CRC is MSB first we | |
805 // do the next MS byte and vica-versa. | |
806 | |
807 if (crc_model.cm_refin == FALSE) | |
808 { | |
809 // MSB first. Do the next MS byte. | |
810 | |
811 byte_to_do = (uint8_t) ((word_to_do & 0xFF000000) >> 24); | |
812 word_to_do <<= 8; | |
813 } | |
814 else | |
815 { | |
816 // LSB first. Do the next LS byte. | |
817 | |
818 byte_to_do = (uint8_t) (word_to_do & 0x000000FF); | |
819 word_to_do >>= 8; | |
820 } | |
821 | |
822 cm_nxt(&crc_model, byte_to_do); | |
823 } | |
824 } | |
825 | |
826 // Return the final result. | |
827 | |
828 return (cm_crc(&crc_model)); | |
829 } | |
830 | |
302
eba8d1eb5bef
bugfix, cleanup: keep both is_ambient_pressure_close_to_surface in sync
Jan Mulder <jlmulder@xs4all.nl>
parents:
300
diff
changeset
|
831 // This code is also in RTE. Keep it in sync when editing |
38 | 832 _Bool is_ambient_pressure_close_to_surface(SLifeData *lifeData) |
833 { | |
310
95928ef3986f
Make dive mode detection more advanced
Jan Mulder <jlmulder@xs4all.nl>
parents:
302
diff
changeset
|
834 if (lifeData->pressure_ambient_bar > 1.16) |
95928ef3986f
Make dive mode detection more advanced
Jan Mulder <jlmulder@xs4all.nl>
parents:
302
diff
changeset
|
835 return false; |
95928ef3986f
Make dive mode detection more advanced
Jan Mulder <jlmulder@xs4all.nl>
parents:
302
diff
changeset
|
836 else if(lifeData->pressure_ambient_bar < (lifeData->pressure_surface_bar + 0.1f)) |
38 | 837 return true; |
838 else | |
839 return false; | |
840 } | |
539
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 void compass_Inertia(float newHeading) |
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 float newTarget = newHeading; |
d784f281833a
Added inertia simulation for compass heading:
Ideenmodellierer
parents:
310
diff
changeset
|
845 |
d784f281833a
Added inertia simulation for compass heading:
Ideenmodellierer
parents:
310
diff
changeset
|
846 if(settingsGetPointer()->compassInertia == 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 = newHeading; |
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 else |
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 if((compass_compensated > 270.0) && (newHeading < 90.0)) /* transition passing 0 clockwise */ |
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 newTarget = newHeading + 360.0; |
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 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
|
858 { |
d784f281833a
Added inertia simulation for compass heading:
Ideenmodellierer
parents:
310
diff
changeset
|
859 newTarget = newHeading - 360.0; |
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 |
d784f281833a
Added inertia simulation for compass heading:
Ideenmodellierer
parents:
310
diff
changeset
|
862 compass_compensated = compass_compensated + ((newTarget - compass_compensated) / (COMPASS_FRACTION * (settingsGetPointer()->compassInertia))); |
d784f281833a
Added inertia simulation for compass heading:
Ideenmodellierer
parents:
310
diff
changeset
|
863 if(compass_compensated < 0.0) |
d784f281833a
Added inertia simulation for compass heading:
Ideenmodellierer
parents:
310
diff
changeset
|
864 { |
d784f281833a
Added inertia simulation for compass heading:
Ideenmodellierer
parents:
310
diff
changeset
|
865 compass_compensated += 360.0; |
d784f281833a
Added inertia simulation for compass heading:
Ideenmodellierer
parents:
310
diff
changeset
|
866 } |
d784f281833a
Added inertia simulation for compass heading:
Ideenmodellierer
parents:
310
diff
changeset
|
867 if(compass_compensated >= 360.0) |
d784f281833a
Added inertia simulation for compass heading:
Ideenmodellierer
parents:
310
diff
changeset
|
868 { |
d784f281833a
Added inertia simulation for compass heading:
Ideenmodellierer
parents:
310
diff
changeset
|
869 compass_compensated -= 360.0; |
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 |
d784f281833a
Added inertia simulation for compass heading:
Ideenmodellierer
parents:
310
diff
changeset
|
874 float compass_getCompensated() |
d784f281833a
Added inertia simulation for compass heading:
Ideenmodellierer
parents:
310
diff
changeset
|
875 { |
d784f281833a
Added inertia simulation for compass heading:
Ideenmodellierer
parents:
310
diff
changeset
|
876 return compass_compensated; |
d784f281833a
Added inertia simulation for compass heading:
Ideenmodellierer
parents:
310
diff
changeset
|
877 } |
d784f281833a
Added inertia simulation for compass heading:
Ideenmodellierer
parents:
310
diff
changeset
|
878 |
662 | 879 uint8_t isLoopMode(uint8_t Mode) |
880 { | |
881 uint8_t retVal = 0; | |
882 if((Mode == DIVEMODE_CCR) || (Mode == DIVEMODE_PSCR)) | |
883 { | |
884 retVal = 1; | |
885 } | |
886 return retVal; | |
887 } | |
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
|
888 |
776
45b8f3c2acce
Add support for a configurable compass declination in a range of -99 to 99 degrees.
heinrichsweikamp
parents:
774
diff
changeset
|
889 |
45b8f3c2acce
Add support for a configurable compass declination in a range of -99 to 99 degrees.
heinrichsweikamp
parents:
774
diff
changeset
|
890 bool isCompassCalibrated(void) |
45b8f3c2acce
Add support for a configurable compass declination in a range of -99 to 99 degrees.
heinrichsweikamp
parents:
774
diff
changeset
|
891 { |
45b8f3c2acce
Add support for a configurable compass declination in a range of -99 to 99 degrees.
heinrichsweikamp
parents:
774
diff
changeset
|
892 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
|
893 } |
45b8f3c2acce
Add support for a configurable compass declination in a range of -99 to 99 degrees.
heinrichsweikamp
parents:
774
diff
changeset
|
894 |
929
63c340abd70e
Add a line to the compass heading dive menu that shows the currently set heading to enable the
heinrichsweikamp
parents:
912
diff
changeset
|
895 static void internalLogCompassHeading(uint16_t heading, bool applyHeading, bool clearHeading) |
63c340abd70e
Add a line to the compass heading dive menu that shows the currently set heading to enable the
heinrichsweikamp
parents:
912
diff
changeset
|
896 { |
63c340abd70e
Add a line to the compass heading dive menu that shows the currently set heading to enable the
heinrichsweikamp
parents:
912
diff
changeset
|
897 uint16_t compassHeading = 0; |
63c340abd70e
Add a line to the compass heading dive menu that shows the currently set heading to enable the
heinrichsweikamp
parents:
912
diff
changeset
|
898 if (clearHeading) { |
63c340abd70e
Add a line to the compass heading dive menu that shows the currently set heading to enable the
heinrichsweikamp
parents:
912
diff
changeset
|
899 compassHeading |= 0x8000; |
63c340abd70e
Add a line to the compass heading dive menu that shows the currently set heading to enable the
heinrichsweikamp
parents:
912
diff
changeset
|
900 } else { |
63c340abd70e
Add a line to the compass heading dive menu that shows the currently set heading to enable the
heinrichsweikamp
parents:
912
diff
changeset
|
901 compassHeading = heading & 0x1FF; |
63c340abd70e
Add a line to the compass heading dive menu that shows the currently set heading to enable the
heinrichsweikamp
parents:
912
diff
changeset
|
902 } |
63c340abd70e
Add a line to the compass heading dive menu that shows the currently set heading to enable the
heinrichsweikamp
parents:
912
diff
changeset
|
903 if (applyHeading) { |
63c340abd70e
Add a line to the compass heading dive menu that shows the currently set heading to enable the
heinrichsweikamp
parents:
912
diff
changeset
|
904 compassHeading |= 0x4000; |
63c340abd70e
Add a line to the compass heading dive menu that shows the currently set heading to enable the
heinrichsweikamp
parents:
912
diff
changeset
|
905 } |
63c340abd70e
Add a line to the compass heading dive menu that shows the currently set heading to enable the
heinrichsweikamp
parents:
912
diff
changeset
|
906 |
63c340abd70e
Add a line to the compass heading dive menu that shows the currently set heading to enable the
heinrichsweikamp
parents:
912
diff
changeset
|
907 stateUsedWrite->events.compassHeadingUpdate = 1; |
63c340abd70e
Add a line to the compass heading dive menu that shows the currently set heading to enable the
heinrichsweikamp
parents:
912
diff
changeset
|
908 stateUsedWrite->events.info_compassHeadingUpdate = compassHeading; |
63c340abd70e
Add a line to the compass heading dive menu that shows the currently set heading to enable the
heinrichsweikamp
parents:
912
diff
changeset
|
909 } |
63c340abd70e
Add a line to the compass heading dive menu that shows the currently set heading to enable the
heinrichsweikamp
parents:
912
diff
changeset
|
910 |
63c340abd70e
Add a line to the compass heading dive menu that shows the currently set heading to enable the
heinrichsweikamp
parents:
912
diff
changeset
|
911 void logCompassHeading(uint16_t heading) { |
63c340abd70e
Add a line to the compass heading dive menu that shows the currently set heading to enable the
heinrichsweikamp
parents:
912
diff
changeset
|
912 internalLogCompassHeading(heading, false, false); |
63c340abd70e
Add a line to the compass heading dive menu that shows the currently set heading to enable the
heinrichsweikamp
parents:
912
diff
changeset
|
913 } |
63c340abd70e
Add a line to the compass heading dive menu that shows the currently set heading to enable the
heinrichsweikamp
parents:
912
diff
changeset
|
914 |
63c340abd70e
Add a line to the compass heading dive menu that shows the currently set heading to enable the
heinrichsweikamp
parents:
912
diff
changeset
|
915 void clearCompassHeading(void) { |
63c340abd70e
Add a line to the compass heading dive menu that shows the currently set heading to enable the
heinrichsweikamp
parents:
912
diff
changeset
|
916 uint16_t clearHeading = 0; |
63c340abd70e
Add a line to the compass heading dive menu that shows the currently set heading to enable the
heinrichsweikamp
parents:
912
diff
changeset
|
917 stateUsedWrite->diveSettings.compassHeading = clearHeading; |
63c340abd70e
Add a line to the compass heading dive menu that shows the currently set heading to enable the
heinrichsweikamp
parents:
912
diff
changeset
|
918 |
63c340abd70e
Add a line to the compass heading dive menu that shows the currently set heading to enable the
heinrichsweikamp
parents:
912
diff
changeset
|
919 internalLogCompassHeading(clearHeading, true, true); |
63c340abd70e
Add a line to the compass heading dive menu that shows the currently set heading to enable the
heinrichsweikamp
parents:
912
diff
changeset
|
920 } |
776
45b8f3c2acce
Add support for a configurable compass declination in a range of -99 to 99 degrees.
heinrichsweikamp
parents:
774
diff
changeset
|
921 |
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
|
922 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
|
923 { |
929
63c340abd70e
Add a line to the compass heading dive menu that shows the currently set heading to enable the
heinrichsweikamp
parents:
912
diff
changeset
|
924 stateUsedWrite->diveSettings.compassHeading = ((heading - 360) % 360) + 360; |
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
|
925 |
929
63c340abd70e
Add a line to the compass heading dive menu that shows the currently set heading to enable the
heinrichsweikamp
parents:
912
diff
changeset
|
926 internalLogCompassHeading(heading, true, false); |
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
|
927 } |
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
|
928 |
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
|
929 |
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
|
930 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
|
931 { |
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
|
932 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
|
933 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
|
934 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
|
935 } 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
|
936 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
|
937 } |
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
|
938 |
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
|
939 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
|
940 } |
805
dd7ce655db26
Adds a simple countdown timer, available as a custom view in surface and dive mode.
heinrichsweikamp
parents:
788
diff
changeset
|
941 |
dd7ce655db26
Adds a simple countdown timer, available as a custom view in surface and dive mode.
heinrichsweikamp
parents:
788
diff
changeset
|
942 |
dd7ce655db26
Adds a simple countdown timer, available as a custom view in surface and dive mode.
heinrichsweikamp
parents:
788
diff
changeset
|
943 void disableTimer(void) |
dd7ce655db26
Adds a simple countdown timer, available as a custom view in surface and dive mode.
heinrichsweikamp
parents:
788
diff
changeset
|
944 { |
dd7ce655db26
Adds a simple countdown timer, available as a custom view in surface and dive mode.
heinrichsweikamp
parents:
788
diff
changeset
|
945 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
|
946 } |
868
db92692c014f
Introduce speed dependend coloring of depth:
Ideenmodellierer
parents:
841
diff
changeset
|
947 |
912 | 948 #define SPEED_SLOW (5.1f) |
949 #define SPEED_MEDIUM (10.1f) | |
950 #define SPEED_HIGH (15.1f) | |
891
a7f4451ba69e
Added hysteresis for ascent speed coloring:
ideenmodellierer
parents:
873
diff
changeset
|
951 #define SPEED_HYSTERESE (1.0f) |
868
db92692c014f
Introduce speed dependend coloring of depth:
Ideenmodellierer
parents:
841
diff
changeset
|
952 |
db92692c014f
Introduce speed dependend coloring of depth:
Ideenmodellierer
parents:
841
diff
changeset
|
953 uint8_t drawingColor_from_ascentspeed(float speed) |
db92692c014f
Introduce speed dependend coloring of depth:
Ideenmodellierer
parents:
841
diff
changeset
|
954 { |
891
a7f4451ba69e
Added hysteresis for ascent speed coloring:
ideenmodellierer
parents:
873
diff
changeset
|
955 static uint8_t lastColor = 0; |
a7f4451ba69e
Added hysteresis for ascent speed coloring:
ideenmodellierer
parents:
873
diff
changeset
|
956 |
868
db92692c014f
Introduce speed dependend coloring of depth:
Ideenmodellierer
parents:
841
diff
changeset
|
957 uint8_t color = CLUT_Font020; |
db92692c014f
Introduce speed dependend coloring of depth:
Ideenmodellierer
parents:
841
diff
changeset
|
958 |
891
a7f4451ba69e
Added hysteresis for ascent speed coloring:
ideenmodellierer
parents:
873
diff
changeset
|
959 if((speed >= SPEED_HIGH) || ((lastColor == CLUT_WarningRed) && (speed >= SPEED_HIGH - SPEED_HYSTERESE))) |
868
db92692c014f
Introduce speed dependend coloring of depth:
Ideenmodellierer
parents:
841
diff
changeset
|
960 { |
db92692c014f
Introduce speed dependend coloring of depth:
Ideenmodellierer
parents:
841
diff
changeset
|
961 color = CLUT_WarningRed; |
db92692c014f
Introduce speed dependend coloring of depth:
Ideenmodellierer
parents:
841
diff
changeset
|
962 } |
891
a7f4451ba69e
Added hysteresis for ascent speed coloring:
ideenmodellierer
parents:
873
diff
changeset
|
963 else if((speed >= SPEED_MEDIUM) || ((lastColor == CLUT_WarningYellow) && (speed >= SPEED_MEDIUM - SPEED_HYSTERESE))) |
868
db92692c014f
Introduce speed dependend coloring of depth:
Ideenmodellierer
parents:
841
diff
changeset
|
964 { |
db92692c014f
Introduce speed dependend coloring of depth:
Ideenmodellierer
parents:
841
diff
changeset
|
965 color = CLUT_WarningYellow; |
db92692c014f
Introduce speed dependend coloring of depth:
Ideenmodellierer
parents:
841
diff
changeset
|
966 } |
891
a7f4451ba69e
Added hysteresis for ascent speed coloring:
ideenmodellierer
parents:
873
diff
changeset
|
967 else if((speed >= SPEED_SLOW) || ((lastColor == CLUT_NiceGreen) && (speed >= SPEED_SLOW - SPEED_HYSTERESE))) |
868
db92692c014f
Introduce speed dependend coloring of depth:
Ideenmodellierer
parents:
841
diff
changeset
|
968 { |
db92692c014f
Introduce speed dependend coloring of depth:
Ideenmodellierer
parents:
841
diff
changeset
|
969 color = CLUT_NiceGreen; |
db92692c014f
Introduce speed dependend coloring of depth:
Ideenmodellierer
parents:
841
diff
changeset
|
970 } |
891
a7f4451ba69e
Added hysteresis for ascent speed coloring:
ideenmodellierer
parents:
873
diff
changeset
|
971 lastColor = color; |
868
db92692c014f
Introduce speed dependend coloring of depth:
Ideenmodellierer
parents:
841
diff
changeset
|
972 return color; |
db92692c014f
Introduce speed dependend coloring of depth:
Ideenmodellierer
parents:
841
diff
changeset
|
973 } |
db92692c014f
Introduce speed dependend coloring of depth:
Ideenmodellierer
parents:
841
diff
changeset
|
974 |
944 | 975 /* returns the date in the order defined by the settings DDMMYY => X */ |
976 void convertStringOfDate_DDMMYY(char* pString, uint8_t strLen, uint8_t day, uint8_t month, uint8_t year) | |
977 { | |
978 if(strLen > 10) | |
979 { | |
980 switch(settingsGetPointer()->date_format) | |
981 { | |
982 default: | |
983 case DDMMYY: snprintf(pString,strLen,"%02d.%02d.%02d",day,month,year); | |
984 break; | |
985 case MMDDYY: snprintf(pString,strLen,"%02d.%02d.%02d",month,day,year); | |
986 break; | |
987 case YYMMDD: snprintf(pString,strLen,"%02d.%02d.%02d",year,month,day); | |
988 break; | |
989 } | |
990 } | |
991 } | |
992 /* returns the format in the order defined by the settings DDMMYY => X */ | |
993 void getStringOfFormat_DDMMYY(char* pString, uint8_t strLen) | |
994 { | |
995 if(strLen > 10) | |
996 { | |
997 switch(settingsGetPointer()->date_format) | |
998 { | |
999 default: | |
1000 case DDMMYY: snprintf(pString,strLen,"%c%c",TXT_2BYTE,TXT2BYTE_DDMMYY); | |
1001 break; | |
1002 case MMDDYY: snprintf(pString,strLen,"%c%c",TXT_2BYTE,TXT2BYTE_MMDDYY); | |
1003 break; | |
1004 case YYMMDD: snprintf(pString,strLen,"%c%c",TXT_2BYTE,TXT2BYTE_YYMMDD); | |
1005 break; | |
1006 } | |
1007 } | |
1008 } | |
868
db92692c014f
Introduce speed dependend coloring of depth:
Ideenmodellierer
parents:
841
diff
changeset
|
1009 |
945 | 1010 uint8_t calculateSlowExit(uint16_t* pCountDownSec, float* pExitDepthMeter, uint8_t* pColor) /* this function is only called if diver is below last last stop depth */ |
1011 { | |
1012 static SSlowExitState slowExitState = SE_END; | |
1013 static uint16_t countDownSec = 0; | |
1014 static float exitDepthMeter = 0.0; | |
1015 static uint32_t exitSecTick = 0; | |
1016 static uint32_t lastSecTick = 0; | |
1017 static uint8_t color = 0; | |
1018 static uint8_t drawingActive = 0; | |
944 | 1019 |
945 | 1020 SSettings* pSettings; |
1021 pSettings = settingsGetPointer(); | |
1022 | |
1023 if((stateUsed->lifeData.max_depth_meter < pSettings->last_stop_depth_meter) /* start of dive => reinit timer */ | |
1024 || (slowExitState == SE_REINIT)) | |
1025 { | |
1026 if(slowExitState != SE_INIT) | |
1027 { | |
1028 countDownSec = pSettings->slowExitTime * 60; | |
1029 slowExitState = SE_INIT; | |
1030 exitDepthMeter = pSettings->last_stop_depth_meter; | |
1031 color = 0; | |
1032 drawingActive = 0; | |
1033 } | |
1034 } | |
1035 else | |
1036 { | |
1037 if(slowExitState != SE_END) | |
1038 { | |
1039 if((slowExitState == SE_INIT) && (stateUsed->lifeData.dive_time_seconds > 900)) /* min 15min divetime */ | |
1040 { | |
1041 slowExitState = SE_ACTIVE; | |
1042 exitSecTick = HAL_GetTick(); | |
1043 lastSecTick = exitSecTick; | |
1044 } | |
1045 else if(slowExitState == SE_ACTIVE) | |
1046 { | |
1047 if(time_elapsed_ms(lastSecTick, HAL_GetTick()) > 60000) /* restart timer if diver go below exit zone */ | |
1048 { | |
1049 slowExitState = SE_REINIT; | |
1050 } | |
1051 else if(time_elapsed_ms(exitSecTick, HAL_GetTick()) > 1000) | |
1052 { | |
1053 exitSecTick = HAL_GetTick(); | |
1054 lastSecTick = exitSecTick; | |
1055 /* select depth digit color */ | |
1056 if(fabsf(stateUsed->lifeData.depth_meter - exitDepthMeter) < 0.5 ) | |
1057 { | |
1058 color = CLUT_NiceGreen; | |
1059 } | |
1060 else if(fabsf(stateUsed->lifeData.depth_meter - exitDepthMeter) <= 1.5) | |
1061 { | |
1062 color = CLUT_WarningYellow; | |
1063 } | |
1064 else if(stateUsed->lifeData.depth_meter - exitDepthMeter < -1.5 ) | |
1065 { | |
1066 color = CLUT_WarningRed; | |
1067 } | |
1068 else | |
1069 { | |
1070 color = 0; | |
1071 } | |
1072 | |
1073 if((fabsf(stateUsed->lifeData.depth_meter - exitDepthMeter) <= 1.6 ) /* only decrease counter if diver is close to target depth */ | |
1074 || (color == CLUT_WarningRed)) /* or if diver is far ahead */ | |
1075 { | |
1076 countDownSec--; | |
1077 if(countDownSec == 0) | |
1078 { | |
1079 slowExitState = SE_END; | |
1080 color = 0; | |
1081 exitDepthMeter = 0; | |
1082 } | |
1083 else | |
1084 { | |
1085 exitDepthMeter -= (pSettings->last_stop_depth_meter / (float)(pSettings->slowExitTime * 60)); | |
1086 } | |
1087 } | |
1088 drawingActive = 1; | |
1089 } | |
1090 } | |
1091 } | |
1092 } | |
1093 *pCountDownSec = countDownSec; | |
1094 *pExitDepthMeter = exitDepthMeter; | |
1095 *pColor = color; | |
1096 return drawingActive; | |
1097 } | |
949 | 1098 |
1099 void convertUTCToLocal(uint8_t utcHours, uint8_t utcMinutes, uint8_t* pLocalHours, uint8_t* pLocalMinutes) | |
1100 { | |
1101 int8_t localHours = 0; | |
1102 int8_t localMinutes = 0; | |
1103 SSettings* pSettings = settingsGetPointer(); | |
1104 | |
1105 localHours = utcHours + pSettings->timeZone.hours; | |
1106 if(localHours < 0) | |
1107 { | |
1108 localHours += 24; | |
1109 } | |
1110 if(localHours > 24) | |
1111 { | |
1112 localHours -= 24; | |
1113 } | |
1114 localMinutes = utcMinutes + pSettings->timeZone.minutes; | |
1115 if(localMinutes < 0) | |
1116 { | |
1117 localMinutes += 60; | |
1118 } | |
1119 if(localMinutes > 60) | |
1120 { | |
1121 localMinutes -= 60; | |
1122 } | |
1123 *pLocalHours = localHours; | |
1124 *pLocalMinutes = localMinutes; | |
1125 } |