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