Mercurial > public > ostc4
annotate Discovery/Src/data_central.c @ 840:7e714662b93f Evo_2_23
Development bugfix CO2 LLC:
In the previous version the CO2 LLC (lowerleftcorner) was displayed even if no CO2 sensor was present or active. In the new version it will only be displayed if an sensor is active.
author | Ideenmodellierer |
---|---|
date | Sun, 07 Jan 2024 21:21:58 +0100 |
parents | aed39d19269c |
children | 70092f552f5a |
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 } | |
38 | 390 } |
391 | |
392 | |
393 void copyDiveSettingsToSim(void) | |
394 { | |
395 memcpy(&stateSim, &stateReal, sizeof(stateReal)); | |
396 } | |
397 | |
398 | |
399 void copyVpmRepetetiveDataToSim(void) | |
400 { | |
401 SDiveState * pSimData = stateSimGetPointerWrite(); | |
402 const SVpmRepetitiveData * pVpmData = stateVpmRepetitiveDataGetPointer(); | |
403 | |
404 if(pVpmData->is_data_from_RTE_CPU) | |
405 { | |
406 for(int i=0; i<16;i++) | |
407 { | |
408 pSimData->vpm.adjusted_critical_radius_he[i] = pVpmData->adjusted_critical_radius_he[i]; | |
409 pSimData->vpm.adjusted_critical_radius_n2[i] = pVpmData->adjusted_critical_radius_n2[i]; | |
410 | |
411 pSimData->vpm.adjusted_crushing_pressure_he[i] = pVpmData->adjusted_crushing_pressure_he[i]; | |
412 pSimData->vpm.adjusted_crushing_pressure_n2[i] = pVpmData->adjusted_crushing_pressure_n2[i]; | |
413 | |
414 pSimData->vpm.initial_allowable_gradient_he[i] = pVpmData->initial_allowable_gradient_he[i]; | |
415 pSimData->vpm.initial_allowable_gradient_n2[i] = pVpmData->initial_allowable_gradient_n2[i]; | |
416 | |
417 pSimData->vpm.max_actual_gradient[i] = pVpmData->max_actual_gradient[i]; | |
418 } | |
419 pSimData->vpm.repetitive_variables_not_valid = pVpmData->repetitive_variables_not_valid; | |
420 } | |
421 } | |
422 | |
423 | |
424 void updateSetpointStateUsed(void) | |
425 { | |
682 | 426 if(!isLoopMode(stateUsed->diveSettings.diveMode)) |
38 | 427 { |
271
1303747b5ba2
cleanup: also write gas and setpoint changes in simulator mode
Jan Mulder <jlmulder@xs4all.nl>
parents:
270
diff
changeset
|
428 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
|
429 stateUsedWrite->lifeData.ppO2 = decom_calc_ppO2(stateUsed->lifeData.pressure_ambient_bar, &stateUsed->lifeData.actualGas); |
38 | 430 } |
431 else | |
432 { | |
433 if(stateUsed->diveSettings.CCR_Mode == CCRMODE_Sensors) | |
434 { | |
271
1303747b5ba2
cleanup: also write gas and setpoint changes in simulator mode
Jan Mulder <jlmulder@xs4all.nl>
parents:
270
diff
changeset
|
435 stateUsedWrite->lifeData.actualGas.setPoint_cbar = get_ppO2SensorWeightedResult_cbar(); |
38 | 436 } |
662 | 437 #ifdef ENABLE_PSCR_MODE |
438 if(stateUsed->diveSettings.diveMode == DIVEMODE_PSCR) /* calculate a ppO2 value based on assumptions ( transfered approach from hwos code) */ | |
439 { | |
440 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); | |
441 if(stateUsed->diveSettings.CCR_Mode == CCRMODE_Simulation) | |
442 { | |
443 stateUsedWrite->lifeData.actualGas.setPoint_cbar = stateUsedWrite->lifeData.ppo2Simulated_bar * 100; | |
444 } | |
445 } | |
446 #endif | |
447 /* limit calculated value to the physically possible if needed */ | |
38 | 448 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
|
449 stateUsedWrite->lifeData.ppO2 = stateUsed->lifeData.pressure_ambient_bar; |
38 | 450 else |
271
1303747b5ba2
cleanup: also write gas and setpoint changes in simulator mode
Jan Mulder <jlmulder@xs4all.nl>
parents:
270
diff
changeset
|
451 stateUsedWrite->lifeData.ppO2 = ((float)stateUsed->lifeData.actualGas.setPoint_cbar) / 100; |
38 | 452 } |
453 } | |
454 | |
455 void setActualGasFirst(SLifeData *lifeData) | |
456 { | |
457 SSettings* pSettings = settingsGetPointer(); | |
458 uint8_t start = 0; | |
459 uint8_t gasId = 0; | |
460 uint8_t setpoint_cbar = 0; | |
461 | |
662 | 462 if(isLoopMode(pSettings->dive_mode)) |
38 | 463 { |
464 setpoint_cbar = pSettings->setpoint[1].setpoint_cbar; | |
465 start = NUM_OFFSET_DILUENT+1; | |
466 } | |
467 else | |
468 { | |
469 setpoint_cbar = 0; | |
470 start = 1; | |
471 } | |
472 | |
473 gasId = start; | |
474 for(int i=start;i<=NUM_GASES+start;i++) | |
475 { | |
476 if(pSettings->gas[i].note.ub.first) | |
477 { | |
478 gasId = i; | |
479 break; | |
480 } | |
481 } | |
482 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
|
483 |
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
|
484 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
|
485 lifeData->setpointLowDelayed = false; |
38 | 486 } |
487 | |
488 void setActualGasAir(SLifeData *lifeData) | |
489 { | |
490 uint8_t nitrogen; | |
491 nitrogen = 79; | |
492 lifeData->actualGas.GasIdInSettings = 0; | |
493 lifeData->actualGas.nitrogen_percentage = nitrogen; | |
494 lifeData->actualGas.helium_percentage =0; | |
495 lifeData->actualGas.setPoint_cbar = 0; | |
496 lifeData->actualGas.change_during_ascent_depth_meter_otherwise_zero = 0; | |
662 | 497 lifeData->actualGas.AppliedDiveMode = stateUsed->diveSettings.diveMode; |
38 | 498 } |
499 | |
500 | |
501 void setActualGas(SLifeData *lifeData, uint8_t gasId, uint8_t setpoint_cbar) | |
502 { | |
503 SSettings* pSettings = settingsGetPointer(); | |
504 uint8_t nitrogen; | |
505 | |
506 nitrogen = 100; | |
507 nitrogen -= pSettings->gas[gasId].oxygen_percentage; | |
508 nitrogen -= pSettings->gas[gasId].helium_percentage; | |
509 | |
510 lifeData->actualGas.GasIdInSettings = gasId; | |
511 lifeData->actualGas.nitrogen_percentage = nitrogen; | |
512 lifeData->actualGas.helium_percentage = pSettings->gas[gasId].helium_percentage; | |
513 lifeData->actualGas.setPoint_cbar = setpoint_cbar; | |
514 lifeData->actualGas.change_during_ascent_depth_meter_otherwise_zero = 0; | |
682 | 515 lifeData->actualGas.AppliedDiveMode = stateUsed->diveSettings.diveMode; |
662 | 516 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
|
517 if (isLoopMode(pSettings->dive_mode) && gasId > NUM_OFFSET_DILUENT) { |
38 | 518 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
|
519 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
|
520 } |
38 | 521 } |
522 | |
523 | |
524 void setActualGas_DM(SLifeData *lifeData, uint8_t gasId, uint8_t setpoint_cbar) | |
525 { | |
526 if(stateUsed->diveSettings.ccrOption && gasId < 6) | |
527 { | |
528 if(lifeData->actualGas.GasIdInSettings != gasId) | |
529 { | |
530 SSettings* pSettings = settingsGetPointer(); | |
271
1303747b5ba2
cleanup: also write gas and setpoint changes in simulator mode
Jan Mulder <jlmulder@xs4all.nl>
parents:
270
diff
changeset
|
531 stateUsedWrite->events.bailout = 1; |
1303747b5ba2
cleanup: also write gas and setpoint changes in simulator mode
Jan Mulder <jlmulder@xs4all.nl>
parents:
270
diff
changeset
|
532 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
|
533 stateUsedWrite->events.info_bailoutHe = pSettings->gas[gasId].helium_percentage; |
38 | 534 } |
535 } | |
536 else | |
537 { | |
538 if(lifeData->actualGas.GasIdInSettings != gasId) | |
539 { | |
271
1303747b5ba2
cleanup: also write gas and setpoint changes in simulator mode
Jan Mulder <jlmulder@xs4all.nl>
parents:
270
diff
changeset
|
540 stateUsedWrite->events.gasChange = 1; |
1303747b5ba2
cleanup: also write gas and setpoint changes in simulator mode
Jan Mulder <jlmulder@xs4all.nl>
parents:
270
diff
changeset
|
541 stateUsedWrite->events.info_GasChange = gasId; |
38 | 542 } |
543 if( lifeData->actualGas.setPoint_cbar != setpoint_cbar) | |
544 { | |
545 // 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
|
546 stateUsedWrite->events.setpointChange = 1; |
1303747b5ba2
cleanup: also write gas and setpoint changes in simulator mode
Jan Mulder <jlmulder@xs4all.nl>
parents:
270
diff
changeset
|
547 stateUsedWrite->events.info_SetpointChange = setpoint_cbar; |
38 | 548 } |
549 } | |
550 setActualGas(lifeData, gasId, setpoint_cbar); | |
551 } | |
552 | |
553 void setActualGas_ExtraGas(SLifeData *lifeData, uint8_t oxygen, uint8_t helium, uint8_t setpoint_cbar) | |
554 { | |
555 uint8_t nitrogen; | |
556 | |
557 nitrogen = 100; | |
558 nitrogen -= oxygen; | |
559 nitrogen -= helium; | |
560 | |
736
8a2337c7af52
Fixed logbook download after switch from CCR to extra (OC) gas if the extra gas
heinrichsweikamp
parents:
683
diff
changeset
|
561 |
8a2337c7af52
Fixed logbook download after switch from CCR to extra (OC) gas if the extra gas
heinrichsweikamp
parents:
683
diff
changeset
|
562 if((lifeData->actualGas.nitrogen_percentage != nitrogen) || (lifeData->actualGas.helium_percentage != helium) || (lifeData->actualGas.AppliedDiveMode != DIVEMODE_OC)) |
38 | 563 { |
281 | 564 stateUsedWrite->events.manualGasSet = 1; |
565 stateUsedWrite->events.info_manualGasSetHe = helium; | |
566 stateUsedWrite->events.info_manualGasSetO2 = oxygen; | |
38 | 567 } |
568 if( lifeData->actualGas.setPoint_cbar != setpoint_cbar) | |
569 { | |
271
1303747b5ba2
cleanup: also write gas and setpoint changes in simulator mode
Jan Mulder <jlmulder@xs4all.nl>
parents:
270
diff
changeset
|
570 stateUsedWrite->events.setpointChange = 1; |
1303747b5ba2
cleanup: also write gas and setpoint changes in simulator mode
Jan Mulder <jlmulder@xs4all.nl>
parents:
270
diff
changeset
|
571 stateUsedWrite->events.info_SetpointChange = setpoint_cbar; |
38 | 572 } |
573 lifeData->actualGas.GasIdInSettings = 0; | |
574 lifeData->actualGas.nitrogen_percentage = nitrogen; | |
575 lifeData->actualGas.helium_percentage = helium; | |
576 lifeData->actualGas.setPoint_cbar = setpoint_cbar; | |
577 lifeData->actualGas.change_during_ascent_depth_meter_otherwise_zero = 0; | |
662 | 578 lifeData->actualGas.AppliedDiveMode = stateUsed->diveSettings.diveMode; |
38 | 579 } |
580 | |
581 void setButtonResponsiveness(uint8_t *ButtonSensitivyList) | |
582 { | |
583 SDataReceiveFromMaster *pDataOut = dataOutGetPointer(); | |
584 | |
585 for(int i=0; i<4; i++) | |
586 { | |
587 pDataOut->data.buttonResponsiveness[i] = settingsHelperButtonSens_translate_percentage_to_hwOS_values(ButtonSensitivyList[i]); | |
588 } | |
589 pDataOut->setButtonSensitivityNow = 1; | |
590 } | |
591 | |
592 | |
593 void setDate(RTC_DateTypeDef Sdate) | |
594 { | |
595 SDataReceiveFromMaster *pDataOut = dataOutGetPointer(); | |
596 | |
597 pDataOut->data.newDate = Sdate; | |
598 pDataOut->setDateNow = 1; | |
599 } | |
600 | |
601 | |
602 void setTime(RTC_TimeTypeDef Stime) | |
603 { | |
604 SDataReceiveFromMaster *pDataOut = dataOutGetPointer(); | |
605 | |
606 pDataOut->data.newTime = Stime; | |
607 pDataOut->setTimeNow = 1; | |
608 } | |
609 | |
610 | |
611 void setBatteryPercentage(uint8_t newChargePercentage) | |
612 { | |
613 SDataReceiveFromMaster *pDataOut = dataOutGetPointer(); | |
614 | |
615 pDataOut->data.newBatteryGaugePercentageFloat = settingsGetPointer()->lastKnownBatteryPercentage; | |
616 pDataOut->setBatteryGaugeNow = 1; | |
617 } | |
618 | |
619 | |
620 void calibrateCompass(void) | |
621 { | |
622 SDataReceiveFromMaster *pDataOut = dataOutGetPointer(); | |
623 pDataOut->calibrateCompassNow = 1; | |
624 } | |
625 | |
626 | |
627 void clearDeco(void) | |
628 { | |
629 SDataReceiveFromMaster *pDataOut = dataOutGetPointer(); | |
630 pDataOut->clearDecoNow = 1; | |
631 | |
632 stateRealGetPointerWrite()->cnsHigh_at_the_end_of_dive = 0; | |
633 stateRealGetPointerWrite()->decoMissed_at_the_end_of_dive = 0; | |
634 } | |
635 | |
636 | |
300
5ca177d2df5d
cleanup: remove commented/unused code, make static
Jan Mulder <jlmulder@xs4all.nl>
parents:
281
diff
changeset
|
637 static int32_t helper_days_from_civil(int32_t y, uint32_t m, uint32_t d) |
38 | 638 { |
639 y += 2000; | |
640 y -= m <= 2; | |
641 int32_t era = (y >= 0 ? y : y-399) / 400; | |
642 uint32_t yoe = (uint32_t)(y - era * 400); // [0, 399] | |
643 uint32_t doy = (153*(m + (m > 2 ? -3 : 9)) + 2)/5 + d-1; // [0, 365] | |
644 uint32_t doe = yoe * 365 + yoe/4 - yoe/100 + doy; // [0, 146096] | |
645 return era * 146097 + (int32_t)(doe) - 719468; | |
646 } | |
647 | |
648 | |
300
5ca177d2df5d
cleanup: remove commented/unused code, make static
Jan Mulder <jlmulder@xs4all.nl>
parents:
281
diff
changeset
|
649 static uint8_t helper_weekday_from_days(int32_t z) |
38 | 650 { |
651 return (uint8_t)(z >= -4 ? (z+4) % 7 : (z+5) % 7 + 6); | |
652 } | |
653 | |
654 | |
655 void setWeekday(RTC_DateTypeDef *sDate) | |
656 { | |
657 uint8_t day; | |
658 // [0, 6] -> [Sun, Sat] | |
659 day = helper_weekday_from_days(helper_days_from_civil(sDate->Year, sDate->Month, sDate->Date)); | |
660 // [1, 7] -> [Mon, Sun] | |
661 if(day == 0) | |
662 day = 7; | |
663 sDate->WeekDay = day; | |
664 } | |
665 | |
666 | |
667 void translateDate(uint32_t datetmpreg, RTC_DateTypeDef *sDate) | |
668 { | |
669 datetmpreg = (uint32_t)(datetmpreg & RTC_DR_RESERVED_MASK); | |
670 | |
671 /* Fill the structure fields with the read parameters */ | |
672 sDate->Year = (uint8_t)((datetmpreg & (RTC_DR_YT | RTC_DR_YU)) >> 16); | |
673 sDate->Month = (uint8_t)((datetmpreg & (RTC_DR_MT | RTC_DR_MU)) >> 8); | |
674 sDate->Date = (uint8_t)(datetmpreg & (RTC_DR_DT | RTC_DR_DU)); | |
675 sDate->WeekDay = (uint8_t)((datetmpreg & (RTC_DR_WDU)) >> 13); | |
676 | |
677 /* Convert the date structure parameters to Binary format */ | |
678 sDate->Year = (uint8_t)RTC_Bcd2ToByte(sDate->Year); | |
679 sDate->Month = (uint8_t)RTC_Bcd2ToByte(sDate->Month); | |
680 sDate->Date = (uint8_t)RTC_Bcd2ToByte(sDate->Date); | |
681 } | |
682 | |
683 void translateTime(uint32_t tmpreg, RTC_TimeTypeDef *sTime) | |
684 { | |
685 tmpreg = (uint32_t)(tmpreg & RTC_TR_RESERVED_MASK); | |
686 | |
687 /* Fill the structure fields with the read parameters */ | |
688 sTime->Hours = (uint8_t)((tmpreg & (RTC_TR_HT | RTC_TR_HU)) >> 16); | |
689 sTime->Minutes = (uint8_t)((tmpreg & (RTC_TR_MNT | RTC_TR_MNU)) >>8); | |
690 sTime->Seconds = (uint8_t)(tmpreg & (RTC_TR_ST | RTC_TR_SU)); | |
691 sTime->TimeFormat = (uint8_t)((tmpreg & (RTC_TR_PM)) >> 16); | |
692 | |
693 /* Convert the time structure parameters to Binary format */ | |
694 sTime->Hours = (uint8_t)RTC_Bcd2ToByte(sTime->Hours); | |
695 sTime->Minutes = (uint8_t)RTC_Bcd2ToByte(sTime->Minutes); | |
696 sTime->Seconds = (uint8_t)RTC_Bcd2ToByte(sTime->Seconds); | |
697 sTime->SubSeconds = 0; | |
698 } | |
699 | |
270
2e58a4094770
feature, debug: make simulator write a logbook entry
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
700 void resetEvents(const SDiveState *pStateUsed) |
38 | 701 { |
270
2e58a4094770
feature, debug: make simulator write a logbook entry
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
702 memset((void *)&pStateUsed->events, 0, sizeof(SEvents)); |
38 | 703 } |
704 | |
705 | |
706 uint32_t CRC_CalcBlockCRC_moreThan768000(uint32_t *buffer1, uint32_t *buffer2, uint32_t words) | |
707 { | |
708 cm_t crc_model; | |
709 uint32_t word_to_do; | |
710 uint8_t byte_to_do; | |
711 int i; | |
712 | |
713 // Values for the STM32F generator. | |
714 | |
715 crc_model.cm_width = 32; // 32-bit CRC | |
716 crc_model.cm_poly = 0x04C11DB7; // CRC-32 polynomial | |
717 crc_model.cm_init = 0xFFFFFFFF; // CRC initialized to 1's | |
718 crc_model.cm_refin = FALSE; // CRC calculated MSB first | |
719 crc_model.cm_refot = FALSE; // Final result is not bit-reversed | |
720 crc_model.cm_xorot = 0x00000000; // Final result XOR'ed with this | |
721 | |
722 cm_ini(&crc_model); | |
723 | |
724 while (words--) | |
725 { | |
726 // The STM32F10x hardware does 32-bit words at a time!!! | |
727 if(words > (768000/4)) | |
728 word_to_do = *buffer2++; | |
729 else | |
730 word_to_do = *buffer1++; | |
731 | |
732 // Do all bytes in the 32-bit word. | |
733 | |
734 for (i = 0; i < sizeof(word_to_do); i++) | |
735 { | |
736 // We calculate a *byte* at a time. If the CRC is MSB first we | |
737 // do the next MS byte and vica-versa. | |
738 | |
739 if (crc_model.cm_refin == FALSE) | |
740 { | |
741 // MSB first. Do the next MS byte. | |
742 | |
743 byte_to_do = (uint8_t) ((word_to_do & 0xFF000000) >> 24); | |
744 word_to_do <<= 8; | |
745 } | |
746 else | |
747 { | |
748 // LSB first. Do the next LS byte. | |
749 | |
750 byte_to_do = (uint8_t) (word_to_do & 0x000000FF); | |
751 word_to_do >>= 8; | |
752 } | |
753 | |
754 cm_nxt(&crc_model, byte_to_do); | |
755 } | |
756 } | |
757 | |
758 // Return the final result. | |
759 | |
760 return (cm_crc(&crc_model)); | |
761 } | |
762 | |
763 | |
764 uint32_t CRC_CalcBlockCRC(uint32_t *buffer, uint32_t words) | |
765 { | |
766 cm_t crc_model; | |
767 uint32_t word_to_do; | |
768 uint8_t byte_to_do; | |
769 int i; | |
770 | |
771 // Values for the STM32F generator. | |
772 | |
773 crc_model.cm_width = 32; // 32-bit CRC | |
774 crc_model.cm_poly = 0x04C11DB7; // CRC-32 polynomial | |
775 crc_model.cm_init = 0xFFFFFFFF; // CRC initialized to 1's | |
776 crc_model.cm_refin = FALSE; // CRC calculated MSB first | |
777 crc_model.cm_refot = FALSE; // Final result is not bit-reversed | |
778 crc_model.cm_xorot = 0x00000000; // Final result XOR'ed with this | |
779 | |
780 cm_ini(&crc_model); | |
781 | |
782 while (words--) | |
783 { | |
784 // The STM32F10x hardware does 32-bit words at a time!!! | |
785 | |
786 word_to_do = *buffer++; | |
787 | |
788 // Do all bytes in the 32-bit word. | |
789 | |
790 for (i = 0; i < sizeof(word_to_do); i++) | |
791 { | |
792 // We calculate a *byte* at a time. If the CRC is MSB first we | |
793 // do the next MS byte and vica-versa. | |
794 | |
795 if (crc_model.cm_refin == FALSE) | |
796 { | |
797 // MSB first. Do the next MS byte. | |
798 | |
799 byte_to_do = (uint8_t) ((word_to_do & 0xFF000000) >> 24); | |
800 word_to_do <<= 8; | |
801 } | |
802 else | |
803 { | |
804 // LSB first. Do the next LS byte. | |
805 | |
806 byte_to_do = (uint8_t) (word_to_do & 0x000000FF); | |
807 word_to_do >>= 8; | |
808 } | |
809 | |
810 cm_nxt(&crc_model, byte_to_do); | |
811 } | |
812 } | |
813 | |
814 // Return the final result. | |
815 | |
816 return (cm_crc(&crc_model)); | |
817 } | |
818 | |
302
eba8d1eb5bef
bugfix, cleanup: keep both is_ambient_pressure_close_to_surface in sync
Jan Mulder <jlmulder@xs4all.nl>
parents:
300
diff
changeset
|
819 // This code is also in RTE. Keep it in sync when editing |
38 | 820 _Bool is_ambient_pressure_close_to_surface(SLifeData *lifeData) |
821 { | |
310
95928ef3986f
Make dive mode detection more advanced
Jan Mulder <jlmulder@xs4all.nl>
parents:
302
diff
changeset
|
822 if (lifeData->pressure_ambient_bar > 1.16) |
95928ef3986f
Make dive mode detection more advanced
Jan Mulder <jlmulder@xs4all.nl>
parents:
302
diff
changeset
|
823 return false; |
95928ef3986f
Make dive mode detection more advanced
Jan Mulder <jlmulder@xs4all.nl>
parents:
302
diff
changeset
|
824 else if(lifeData->pressure_ambient_bar < (lifeData->pressure_surface_bar + 0.1f)) |
38 | 825 return true; |
826 else | |
827 return false; | |
828 } | |
539
d784f281833a
Added inertia simulation for compass heading:
Ideenmodellierer
parents:
310
diff
changeset
|
829 |
d784f281833a
Added inertia simulation for compass heading:
Ideenmodellierer
parents:
310
diff
changeset
|
830 void compass_Inertia(float newHeading) |
d784f281833a
Added inertia simulation for compass heading:
Ideenmodellierer
parents:
310
diff
changeset
|
831 { |
d784f281833a
Added inertia simulation for compass heading:
Ideenmodellierer
parents:
310
diff
changeset
|
832 float newTarget = newHeading; |
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 if(settingsGetPointer()->compassInertia == 0) |
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 compass_compensated = 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 else |
d784f281833a
Added inertia simulation for compass heading:
Ideenmodellierer
parents:
310
diff
changeset
|
839 { |
d784f281833a
Added inertia simulation for compass heading:
Ideenmodellierer
parents:
310
diff
changeset
|
840 if((compass_compensated > 270.0) && (newHeading < 90.0)) /* transition passing 0 clockwise */ |
d784f281833a
Added inertia simulation for compass heading:
Ideenmodellierer
parents:
310
diff
changeset
|
841 { |
d784f281833a
Added inertia simulation for compass heading:
Ideenmodellierer
parents:
310
diff
changeset
|
842 newTarget = newHeading + 360.0; |
d784f281833a
Added inertia simulation for compass heading:
Ideenmodellierer
parents:
310
diff
changeset
|
843 } |
d784f281833a
Added inertia simulation for compass heading:
Ideenmodellierer
parents:
310
diff
changeset
|
844 |
d784f281833a
Added inertia simulation for compass heading:
Ideenmodellierer
parents:
310
diff
changeset
|
845 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
|
846 { |
d784f281833a
Added inertia simulation for compass heading:
Ideenmodellierer
parents:
310
diff
changeset
|
847 newTarget = newHeading - 360.0; |
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 |
d784f281833a
Added inertia simulation for compass heading:
Ideenmodellierer
parents:
310
diff
changeset
|
850 compass_compensated = compass_compensated + ((newTarget - compass_compensated) / (COMPASS_FRACTION * (settingsGetPointer()->compassInertia))); |
d784f281833a
Added inertia simulation for compass heading:
Ideenmodellierer
parents:
310
diff
changeset
|
851 if(compass_compensated < 0.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 compass_compensated += 360.0; |
d784f281833a
Added inertia simulation for compass heading:
Ideenmodellierer
parents:
310
diff
changeset
|
854 } |
d784f281833a
Added inertia simulation for compass heading:
Ideenmodellierer
parents:
310
diff
changeset
|
855 if(compass_compensated >= 360.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 } |
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 float compass_getCompensated() |
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 return compass_compensated; |
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 |
662 | 867 uint8_t isLoopMode(uint8_t Mode) |
868 { | |
869 uint8_t retVal = 0; | |
870 if((Mode == DIVEMODE_CCR) || (Mode == DIVEMODE_PSCR)) | |
871 { | |
872 retVal = 1; | |
873 } | |
874 return retVal; | |
875 } | |
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
|
876 |
776
45b8f3c2acce
Add support for a configurable compass declination in a range of -99 to 99 degrees.
heinrichsweikamp
parents:
774
diff
changeset
|
877 |
45b8f3c2acce
Add support for a configurable compass declination in a range of -99 to 99 degrees.
heinrichsweikamp
parents:
774
diff
changeset
|
878 bool isCompassCalibrated(void) |
45b8f3c2acce
Add support for a configurable compass declination in a range of -99 to 99 degrees.
heinrichsweikamp
parents:
774
diff
changeset
|
879 { |
45b8f3c2acce
Add support for a configurable compass declination in a range of -99 to 99 degrees.
heinrichsweikamp
parents:
774
diff
changeset
|
880 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
|
881 } |
45b8f3c2acce
Add support for a configurable compass declination in a range of -99 to 99 degrees.
heinrichsweikamp
parents:
774
diff
changeset
|
882 |
45b8f3c2acce
Add support for a configurable compass declination in a range of -99 to 99 degrees.
heinrichsweikamp
parents:
774
diff
changeset
|
883 |
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
|
884 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
|
885 { |
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
|
886 |
6169309d6eb9
more menu items for the compass menu: Delete bearing, and reset to land based bearing. I have also re-enabled the real time bearing display in the menu - makes it easier to set the correct bearing. (mikeller)
heinrichsweikamp
parents:
771
diff
changeset
|
887 // 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
|
888 |
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 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
|
890 } |
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
|
891 |
4abfb8a2a435
Define explicit setpoints for low / high / deco. Add an option to delay the switch to SPlow until all decompression has been cleared. (mikeller)
heinrichsweikamp
parents:
776
diff
changeset
|
892 |
4abfb8a2a435
Define explicit setpoints for low / high / deco. Add an option to delay the switch to SPlow until all decompression has been cleared. (mikeller)
heinrichsweikamp
parents:
776
diff
changeset
|
893 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
|
894 { |
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 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
|
896 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
|
897 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
|
898 } 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
|
899 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
|
900 } |
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 |
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 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
|
903 } |
805
dd7ce655db26
Adds a simple countdown timer, available as a custom view in surface and dive mode.
heinrichsweikamp
parents:
788
diff
changeset
|
904 |
dd7ce655db26
Adds a simple countdown timer, available as a custom view in surface and dive mode.
heinrichsweikamp
parents:
788
diff
changeset
|
905 |
dd7ce655db26
Adds a simple countdown timer, available as a custom view in surface and dive mode.
heinrichsweikamp
parents:
788
diff
changeset
|
906 void disableTimer(void) |
dd7ce655db26
Adds a simple countdown timer, available as a custom view in surface and dive mode.
heinrichsweikamp
parents:
788
diff
changeset
|
907 { |
dd7ce655db26
Adds a simple countdown timer, available as a custom view in surface and dive mode.
heinrichsweikamp
parents:
788
diff
changeset
|
908 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
|
909 } |