annotate Discovery/Src/data_central.c @ 902:d4622533271d Evo_2_23 tip

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