Mercurial > public > ostc4
annotate Discovery/Src/data_central.c @ 842:c3dd461ca3f9 Evo_2_23
Migrated Sentinel protocol to new UART structure:
The Sentinel protocol had not been migrated to the new UART structure which was introduced with the introduction of the UART MUX. The Sentinel is now supported by autodetection again (development version only)
author | Ideenmodellierer |
---|---|
date | Mon, 15 Jan 2024 21:44:18 +0100 |
parents | 70092f552f5a |
children | db92692c014f |
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 |
8a2337c7af52
Fixed logbook download after switch from CCR to extra (OC) gas if the extra gas
heinrichsweikamp
parents:
683
diff
changeset
|
566 if((lifeData->actualGas.nitrogen_percentage != nitrogen) || (lifeData->actualGas.helium_percentage != helium) || (lifeData->actualGas.AppliedDiveMode != DIVEMODE_OC)) |
38 | 567 { |
281 | 568 stateUsedWrite->events.manualGasSet = 1; |
569 stateUsedWrite->events.info_manualGasSetHe = helium; | |
570 stateUsedWrite->events.info_manualGasSetO2 = oxygen; | |
38 | 571 } |
572 if( lifeData->actualGas.setPoint_cbar != setpoint_cbar) | |
573 { | |
271
1303747b5ba2
cleanup: also write gas and setpoint changes in simulator mode
Jan Mulder <jlmulder@xs4all.nl>
parents:
270
diff
changeset
|
574 stateUsedWrite->events.setpointChange = 1; |
1303747b5ba2
cleanup: also write gas and setpoint changes in simulator mode
Jan Mulder <jlmulder@xs4all.nl>
parents:
270
diff
changeset
|
575 stateUsedWrite->events.info_SetpointChange = setpoint_cbar; |
38 | 576 } |
577 lifeData->actualGas.GasIdInSettings = 0; | |
578 lifeData->actualGas.nitrogen_percentage = nitrogen; | |
579 lifeData->actualGas.helium_percentage = helium; | |
580 lifeData->actualGas.setPoint_cbar = setpoint_cbar; | |
581 lifeData->actualGas.change_during_ascent_depth_meter_otherwise_zero = 0; | |
662 | 582 lifeData->actualGas.AppliedDiveMode = stateUsed->diveSettings.diveMode; |
38 | 583 } |
584 | |
585 void setButtonResponsiveness(uint8_t *ButtonSensitivyList) | |
586 { | |
587 SDataReceiveFromMaster *pDataOut = dataOutGetPointer(); | |
588 | |
589 for(int i=0; i<4; i++) | |
590 { | |
591 pDataOut->data.buttonResponsiveness[i] = settingsHelperButtonSens_translate_percentage_to_hwOS_values(ButtonSensitivyList[i]); | |
592 } | |
593 pDataOut->setButtonSensitivityNow = 1; | |
594 } | |
595 | |
596 | |
597 void setDate(RTC_DateTypeDef Sdate) | |
598 { | |
599 SDataReceiveFromMaster *pDataOut = dataOutGetPointer(); | |
600 | |
601 pDataOut->data.newDate = Sdate; | |
602 pDataOut->setDateNow = 1; | |
603 } | |
604 | |
605 | |
606 void setTime(RTC_TimeTypeDef Stime) | |
607 { | |
608 SDataReceiveFromMaster *pDataOut = dataOutGetPointer(); | |
609 | |
610 pDataOut->data.newTime = Stime; | |
611 pDataOut->setTimeNow = 1; | |
612 } | |
613 | |
614 | |
615 void setBatteryPercentage(uint8_t newChargePercentage) | |
616 { | |
617 SDataReceiveFromMaster *pDataOut = dataOutGetPointer(); | |
618 | |
619 pDataOut->data.newBatteryGaugePercentageFloat = settingsGetPointer()->lastKnownBatteryPercentage; | |
620 pDataOut->setBatteryGaugeNow = 1; | |
621 } | |
622 | |
623 | |
624 void calibrateCompass(void) | |
625 { | |
626 SDataReceiveFromMaster *pDataOut = dataOutGetPointer(); | |
627 pDataOut->calibrateCompassNow = 1; | |
628 } | |
629 | |
630 | |
631 void clearDeco(void) | |
632 { | |
633 SDataReceiveFromMaster *pDataOut = dataOutGetPointer(); | |
634 pDataOut->clearDecoNow = 1; | |
635 | |
636 stateRealGetPointerWrite()->cnsHigh_at_the_end_of_dive = 0; | |
637 stateRealGetPointerWrite()->decoMissed_at_the_end_of_dive = 0; | |
638 } | |
639 | |
640 | |
300
5ca177d2df5d
cleanup: remove commented/unused code, make static
Jan Mulder <jlmulder@xs4all.nl>
parents:
281
diff
changeset
|
641 static int32_t helper_days_from_civil(int32_t y, uint32_t m, uint32_t d) |
38 | 642 { |
643 y += 2000; | |
644 y -= m <= 2; | |
645 int32_t era = (y >= 0 ? y : y-399) / 400; | |
646 uint32_t yoe = (uint32_t)(y - era * 400); // [0, 399] | |
647 uint32_t doy = (153*(m + (m > 2 ? -3 : 9)) + 2)/5 + d-1; // [0, 365] | |
648 uint32_t doe = yoe * 365 + yoe/4 - yoe/100 + doy; // [0, 146096] | |
649 return era * 146097 + (int32_t)(doe) - 719468; | |
650 } | |
651 | |
652 | |
300
5ca177d2df5d
cleanup: remove commented/unused code, make static
Jan Mulder <jlmulder@xs4all.nl>
parents:
281
diff
changeset
|
653 static uint8_t helper_weekday_from_days(int32_t z) |
38 | 654 { |
655 return (uint8_t)(z >= -4 ? (z+4) % 7 : (z+5) % 7 + 6); | |
656 } | |
657 | |
658 | |
659 void setWeekday(RTC_DateTypeDef *sDate) | |
660 { | |
661 uint8_t day; | |
662 // [0, 6] -> [Sun, Sat] | |
663 day = helper_weekday_from_days(helper_days_from_civil(sDate->Year, sDate->Month, sDate->Date)); | |
664 // [1, 7] -> [Mon, Sun] | |
665 if(day == 0) | |
666 day = 7; | |
667 sDate->WeekDay = day; | |
668 } | |
669 | |
670 | |
671 void translateDate(uint32_t datetmpreg, RTC_DateTypeDef *sDate) | |
672 { | |
673 datetmpreg = (uint32_t)(datetmpreg & RTC_DR_RESERVED_MASK); | |
674 | |
675 /* Fill the structure fields with the read parameters */ | |
676 sDate->Year = (uint8_t)((datetmpreg & (RTC_DR_YT | RTC_DR_YU)) >> 16); | |
677 sDate->Month = (uint8_t)((datetmpreg & (RTC_DR_MT | RTC_DR_MU)) >> 8); | |
678 sDate->Date = (uint8_t)(datetmpreg & (RTC_DR_DT | RTC_DR_DU)); | |
679 sDate->WeekDay = (uint8_t)((datetmpreg & (RTC_DR_WDU)) >> 13); | |
680 | |
681 /* Convert the date structure parameters to Binary format */ | |
682 sDate->Year = (uint8_t)RTC_Bcd2ToByte(sDate->Year); | |
683 sDate->Month = (uint8_t)RTC_Bcd2ToByte(sDate->Month); | |
684 sDate->Date = (uint8_t)RTC_Bcd2ToByte(sDate->Date); | |
685 } | |
686 | |
687 void translateTime(uint32_t tmpreg, RTC_TimeTypeDef *sTime) | |
688 { | |
689 tmpreg = (uint32_t)(tmpreg & RTC_TR_RESERVED_MASK); | |
690 | |
691 /* Fill the structure fields with the read parameters */ | |
692 sTime->Hours = (uint8_t)((tmpreg & (RTC_TR_HT | RTC_TR_HU)) >> 16); | |
693 sTime->Minutes = (uint8_t)((tmpreg & (RTC_TR_MNT | RTC_TR_MNU)) >>8); | |
694 sTime->Seconds = (uint8_t)(tmpreg & (RTC_TR_ST | RTC_TR_SU)); | |
695 sTime->TimeFormat = (uint8_t)((tmpreg & (RTC_TR_PM)) >> 16); | |
696 | |
697 /* Convert the time structure parameters to Binary format */ | |
698 sTime->Hours = (uint8_t)RTC_Bcd2ToByte(sTime->Hours); | |
699 sTime->Minutes = (uint8_t)RTC_Bcd2ToByte(sTime->Minutes); | |
700 sTime->Seconds = (uint8_t)RTC_Bcd2ToByte(sTime->Seconds); | |
701 sTime->SubSeconds = 0; | |
702 } | |
703 | |
270
2e58a4094770
feature, debug: make simulator write a logbook entry
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
704 void resetEvents(const SDiveState *pStateUsed) |
38 | 705 { |
270
2e58a4094770
feature, debug: make simulator write a logbook entry
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
706 memset((void *)&pStateUsed->events, 0, sizeof(SEvents)); |
38 | 707 } |
708 | |
709 | |
710 uint32_t CRC_CalcBlockCRC_moreThan768000(uint32_t *buffer1, uint32_t *buffer2, uint32_t words) | |
711 { | |
712 cm_t crc_model; | |
713 uint32_t word_to_do; | |
714 uint8_t byte_to_do; | |
715 int i; | |
716 | |
717 // Values for the STM32F generator. | |
718 | |
719 crc_model.cm_width = 32; // 32-bit CRC | |
720 crc_model.cm_poly = 0x04C11DB7; // CRC-32 polynomial | |
721 crc_model.cm_init = 0xFFFFFFFF; // CRC initialized to 1's | |
722 crc_model.cm_refin = FALSE; // CRC calculated MSB first | |
723 crc_model.cm_refot = FALSE; // Final result is not bit-reversed | |
724 crc_model.cm_xorot = 0x00000000; // Final result XOR'ed with this | |
725 | |
726 cm_ini(&crc_model); | |
727 | |
728 while (words--) | |
729 { | |
730 // The STM32F10x hardware does 32-bit words at a time!!! | |
731 if(words > (768000/4)) | |
732 word_to_do = *buffer2++; | |
733 else | |
734 word_to_do = *buffer1++; | |
735 | |
736 // Do all bytes in the 32-bit word. | |
737 | |
738 for (i = 0; i < sizeof(word_to_do); i++) | |
739 { | |
740 // We calculate a *byte* at a time. If the CRC is MSB first we | |
741 // do the next MS byte and vica-versa. | |
742 | |
743 if (crc_model.cm_refin == FALSE) | |
744 { | |
745 // MSB first. Do the next MS byte. | |
746 | |
747 byte_to_do = (uint8_t) ((word_to_do & 0xFF000000) >> 24); | |
748 word_to_do <<= 8; | |
749 } | |
750 else | |
751 { | |
752 // LSB first. Do the next LS byte. | |
753 | |
754 byte_to_do = (uint8_t) (word_to_do & 0x000000FF); | |
755 word_to_do >>= 8; | |
756 } | |
757 | |
758 cm_nxt(&crc_model, byte_to_do); | |
759 } | |
760 } | |
761 | |
762 // Return the final result. | |
763 | |
764 return (cm_crc(&crc_model)); | |
765 } | |
766 | |
767 | |
768 uint32_t CRC_CalcBlockCRC(uint32_t *buffer, uint32_t words) | |
769 { | |
770 cm_t crc_model; | |
771 uint32_t word_to_do; | |
772 uint8_t byte_to_do; | |
773 int i; | |
774 | |
775 // Values for the STM32F generator. | |
776 | |
777 crc_model.cm_width = 32; // 32-bit CRC | |
778 crc_model.cm_poly = 0x04C11DB7; // CRC-32 polynomial | |
779 crc_model.cm_init = 0xFFFFFFFF; // CRC initialized to 1's | |
780 crc_model.cm_refin = FALSE; // CRC calculated MSB first | |
781 crc_model.cm_refot = FALSE; // Final result is not bit-reversed | |
782 crc_model.cm_xorot = 0x00000000; // Final result XOR'ed with this | |
783 | |
784 cm_ini(&crc_model); | |
785 | |
786 while (words--) | |
787 { | |
788 // The STM32F10x hardware does 32-bit words at a time!!! | |
789 | |
790 word_to_do = *buffer++; | |
791 | |
792 // Do all bytes in the 32-bit word. | |
793 | |
794 for (i = 0; i < sizeof(word_to_do); i++) | |
795 { | |
796 // We calculate a *byte* at a time. If the CRC is MSB first we | |
797 // do the next MS byte and vica-versa. | |
798 | |
799 if (crc_model.cm_refin == FALSE) | |
800 { | |
801 // MSB first. Do the next MS byte. | |
802 | |
803 byte_to_do = (uint8_t) ((word_to_do & 0xFF000000) >> 24); | |
804 word_to_do <<= 8; | |
805 } | |
806 else | |
807 { | |
808 // LSB first. Do the next LS byte. | |
809 | |
810 byte_to_do = (uint8_t) (word_to_do & 0x000000FF); | |
811 word_to_do >>= 8; | |
812 } | |
813 | |
814 cm_nxt(&crc_model, byte_to_do); | |
815 } | |
816 } | |
817 | |
818 // Return the final result. | |
819 | |
820 return (cm_crc(&crc_model)); | |
821 } | |
822 | |
302
eba8d1eb5bef
bugfix, cleanup: keep both is_ambient_pressure_close_to_surface in sync
Jan Mulder <jlmulder@xs4all.nl>
parents:
300
diff
changeset
|
823 // This code is also in RTE. Keep it in sync when editing |
38 | 824 _Bool is_ambient_pressure_close_to_surface(SLifeData *lifeData) |
825 { | |
310
95928ef3986f
Make dive mode detection more advanced
Jan Mulder <jlmulder@xs4all.nl>
parents:
302
diff
changeset
|
826 if (lifeData->pressure_ambient_bar > 1.16) |
95928ef3986f
Make dive mode detection more advanced
Jan Mulder <jlmulder@xs4all.nl>
parents:
302
diff
changeset
|
827 return false; |
95928ef3986f
Make dive mode detection more advanced
Jan Mulder <jlmulder@xs4all.nl>
parents:
302
diff
changeset
|
828 else if(lifeData->pressure_ambient_bar < (lifeData->pressure_surface_bar + 0.1f)) |
38 | 829 return true; |
830 else | |
831 return false; | |
832 } | |
539
d784f281833a
Added inertia simulation for compass heading:
Ideenmodellierer
parents:
310
diff
changeset
|
833 |
d784f281833a
Added inertia simulation for compass heading:
Ideenmodellierer
parents:
310
diff
changeset
|
834 void compass_Inertia(float newHeading) |
d784f281833a
Added inertia simulation for compass heading:
Ideenmodellierer
parents:
310
diff
changeset
|
835 { |
d784f281833a
Added inertia simulation for compass heading:
Ideenmodellierer
parents:
310
diff
changeset
|
836 float newTarget = newHeading; |
d784f281833a
Added inertia simulation for compass heading:
Ideenmodellierer
parents:
310
diff
changeset
|
837 |
d784f281833a
Added inertia simulation for compass heading:
Ideenmodellierer
parents:
310
diff
changeset
|
838 if(settingsGetPointer()->compassInertia == 0) |
d784f281833a
Added inertia simulation for compass heading:
Ideenmodellierer
parents:
310
diff
changeset
|
839 { |
d784f281833a
Added inertia simulation for compass heading:
Ideenmodellierer
parents:
310
diff
changeset
|
840 compass_compensated = newHeading; |
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 else |
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 if((compass_compensated > 270.0) && (newHeading < 90.0)) /* transition passing 0 clockwise */ |
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 newTarget = newHeading + 360.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 |
d784f281833a
Added inertia simulation for compass heading:
Ideenmodellierer
parents:
310
diff
changeset
|
849 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
|
850 { |
d784f281833a
Added inertia simulation for compass heading:
Ideenmodellierer
parents:
310
diff
changeset
|
851 newTarget = newHeading - 360.0; |
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 |
d784f281833a
Added inertia simulation for compass heading:
Ideenmodellierer
parents:
310
diff
changeset
|
854 compass_compensated = compass_compensated + ((newTarget - compass_compensated) / (COMPASS_FRACTION * (settingsGetPointer()->compassInertia))); |
d784f281833a
Added inertia simulation for compass heading:
Ideenmodellierer
parents:
310
diff
changeset
|
855 if(compass_compensated < 0.0) |
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 compass_compensated += 360.0; |
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 if(compass_compensated >= 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 compass_compensated -= 360.0; |
d784f281833a
Added inertia simulation for compass heading:
Ideenmodellierer
parents:
310
diff
changeset
|
862 } |
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 } |
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 float compass_getCompensated() |
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 return compass_compensated; |
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 |
662 | 871 uint8_t isLoopMode(uint8_t Mode) |
872 { | |
873 uint8_t retVal = 0; | |
874 if((Mode == DIVEMODE_CCR) || (Mode == DIVEMODE_PSCR)) | |
875 { | |
876 retVal = 1; | |
877 } | |
878 return retVal; | |
879 } | |
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
|
880 |
776
45b8f3c2acce
Add support for a configurable compass declination in a range of -99 to 99 degrees.
heinrichsweikamp
parents:
774
diff
changeset
|
881 |
45b8f3c2acce
Add support for a configurable compass declination in a range of -99 to 99 degrees.
heinrichsweikamp
parents:
774
diff
changeset
|
882 bool isCompassCalibrated(void) |
45b8f3c2acce
Add support for a configurable compass declination in a range of -99 to 99 degrees.
heinrichsweikamp
parents:
774
diff
changeset
|
883 { |
45b8f3c2acce
Add support for a configurable compass declination in a range of -99 to 99 degrees.
heinrichsweikamp
parents:
774
diff
changeset
|
884 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
|
885 } |
45b8f3c2acce
Add support for a configurable compass declination in a range of -99 to 99 degrees.
heinrichsweikamp
parents:
774
diff
changeset
|
886 |
45b8f3c2acce
Add support for a configurable compass declination in a range of -99 to 99 degrees.
heinrichsweikamp
parents:
774
diff
changeset
|
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 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
|
889 { |
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
|
890 |
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
|
891 // 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
|
892 |
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
|
893 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
|
894 } |
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
|
895 |
4abfb8a2a435
Define explicit setpoints for low / high / deco. Add an option to delay the switch to SPlow until all decompression has been cleared. (mikeller)
heinrichsweikamp
parents:
776
diff
changeset
|
896 |
4abfb8a2a435
Define explicit setpoints for low / high / deco. Add an option to delay the switch to SPlow until all decompression has been cleared. (mikeller)
heinrichsweikamp
parents:
776
diff
changeset
|
897 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
|
898 { |
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
|
899 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
|
900 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
|
901 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
|
902 } 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
|
903 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
|
904 } |
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 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
|
907 } |
805
dd7ce655db26
Adds a simple countdown timer, available as a custom view in surface and dive mode.
heinrichsweikamp
parents:
788
diff
changeset
|
908 |
dd7ce655db26
Adds a simple countdown timer, available as a custom view in surface and dive mode.
heinrichsweikamp
parents:
788
diff
changeset
|
909 |
dd7ce655db26
Adds a simple countdown timer, available as a custom view in surface and dive mode.
heinrichsweikamp
parents:
788
diff
changeset
|
910 void disableTimer(void) |
dd7ce655db26
Adds a simple countdown timer, available as a custom view in surface and dive mode.
heinrichsweikamp
parents:
788
diff
changeset
|
911 { |
dd7ce655db26
Adds a simple countdown timer, available as a custom view in surface and dive mode.
heinrichsweikamp
parents:
788
diff
changeset
|
912 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
|
913 } |