annotate Discovery/Src/simulation.c @ 996:8507a87f6401 GasConsumption

Improve buzzer opreation: In the previous version the buzzer was operated in case warning events. In the new version the buzzer is inactive in surface mode in order to prevent annoying warning just because e.g. the sensors are not connected. In addition it is now possible to request a short activation only e.g. in case of the activation of the buzzer via the menu.
author Ideenmodellierer
date Mon, 21 Apr 2025 21:00:34 +0200
parents 7891160acde3
children 5a690195b6b7
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 /// -*- coding: UTF-8 -*-
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3 ///
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
4 /// \file Discovery/Src/simulation.c
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
5 /// \brief Contains dive simulation functionality
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
6 /// \author Heinrichs Weikamp gmbh
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
7 /// \date 13-Oct-2014
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
8 ///
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
9 /// \details
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
10 /// The simulation uses "extern SDiveState stateSim" defined in dataCentral.h"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
11 ///
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
12 /// simulation_start(void) sets stateUsed to stateSim and initializes simulation
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
13 /// simulation_UpdateLifeData should be called at least once per second
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
14 /// simulation_end() sets stateUsed back to stateReal
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
15 ///
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
16 /// $Id$
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
17 ///////////////////////////////////////////////////////////////////////////////
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
18 /// \par Copyright (c) 2014-2018 Heinrichs Weikamp gmbh
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
19 ///
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
20 /// This program is free software: you can redistribute it and/or modify
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
21 /// it under the terms of the GNU General Public License as published by
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
22 /// the Free Software Foundation, either version 3 of the License, or
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
23 /// (at your option) any later version.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
24 ///
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
25 /// This program is distributed in the hope that it will be useful,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
26 /// but WITHOUT ANY WARRANTY; without even the implied warranty of
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
27 /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
28 /// GNU General Public License for more details.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
29 ///
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
30 /// You should have received a copy of the GNU General Public License
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
31 /// along with this program. If not, see <http://www.gnu.org/licenses/>.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
32 //////////////////////////////////////////////////////////////////////////////
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
33
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
34 #include <string.h>
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
35 #include "simulation.h"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
36
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
37 #include "decom.h"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
38 #include "calc_crush.h"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
39 #include "data_exchange.h"
308
1203255481e4 cleanup: introduce function setAvgDepth
Jan Mulder <jlmulder@xs4all.nl>
parents: 307
diff changeset
40 #include "data_exchange_main.h"
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
41 #include "timer.h"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
42 #include "check_warning.h"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
43 #include "vpm.h"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
44 #include "buehlmann.h"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
45 #include "logbook_miniLive.h"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
46
450
b2f8a39c11ea Added new compile switches for variants:
ideenmodellierer
parents: 446
diff changeset
47 #include "configuration.h"
b2f8a39c11ea Added new compile switches for variants:
ideenmodellierer
parents: 446
diff changeset
48
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
49 //Private state variables
225
2bb1db22b5f5 cleanup: random set of cleanups
Jan Mulder <jlmulder@xs4all.nl>
parents: 176
diff changeset
50 static float sim_aim_depth_meter;
760
21949c88da90 Quit simualted dives after the dive time set in the SIM tab.
heinrichsweikamp
parents: 748
diff changeset
51 static float sim_aim_time_minutes;
225
2bb1db22b5f5 cleanup: random set of cleanups
Jan Mulder <jlmulder@xs4all.nl>
parents: 176
diff changeset
52 static _Bool sim_heed_decostops = 1;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
53
897
65772ddee88c Use dive profile as source for simulator:
ideenmodellierer
parents: 888
diff changeset
54 static float sim_descent_rate_meter_per_min = 20;
65772ddee88c Use dive profile as source for simulator:
ideenmodellierer
parents: 888
diff changeset
55
65772ddee88c Use dive profile as source for simulator:
ideenmodellierer
parents: 888
diff changeset
56 static uint16_t* pReplayData; /* pointer to source dive data */
65772ddee88c Use dive profile as source for simulator:
ideenmodellierer
parents: 888
diff changeset
57 static uint8_t simReplayActive = 0;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
58
924
4d98fb2a178e Bugfix real scrubber time decreased in sim mode:
Ideenmodellierer
parents: 910
diff changeset
59 static uint16_t simScrubberTimeoutCount = 0;
4d98fb2a178e Bugfix real scrubber time decreased in sim mode:
Ideenmodellierer
parents: 910
diff changeset
60
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
61
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
62 //Private functions
300
5ca177d2df5d cleanup: remove commented/unused code, make static
Jan Mulder <jlmulder@xs4all.nl>
parents: 233
diff changeset
63 static float sim_get_ambient_pressure(SDiveState * pDiveState);
225
2bb1db22b5f5 cleanup: random set of cleanups
Jan Mulder <jlmulder@xs4all.nl>
parents: 176
diff changeset
64 static void sim_reduce_deco_time_one_second(SDiveState* pDiveState);
2bb1db22b5f5 cleanup: random set of cleanups
Jan Mulder <jlmulder@xs4all.nl>
parents: 176
diff changeset
65 static void simulation_set_aim_depth(int depth_meter);
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
66
629
55a9aa740f13 Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents: 548
diff changeset
67 #define NUM_OF_SENSORS (3u)
55a9aa740f13 Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents: 548
diff changeset
68 #define SIM_PPO2_STEP (1.1f)
55a9aa740f13 Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents: 548
diff changeset
69 static float simSensmVOffset[NUM_OF_SENSORS];
55a9aa740f13 Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents: 548
diff changeset
70
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
71 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
72 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
73 * @brief sets heed_decostops_while_ascending
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
74 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
75 * @param heed_decostops_while_ascending : true -> deco_stops are considered while ascending
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
76 * @return void
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
77 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
78 void simulation_set_heed_decostops(_Bool heed_decostops_while_ascending)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
79 {
629
55a9aa740f13 Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents: 548
diff changeset
80 sim_heed_decostops = heed_decostops_while_ascending;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
81 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
82
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
83 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
84 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
85 * @brief start of simulation
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
86 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
87 * @return void
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
88 */
760
21949c88da90 Quit simualted dives after the dive time set in the SIM tab.
heinrichsweikamp
parents: 748
diff changeset
89 void simulation_start(int aim_depth, uint16_t aim_time_minutes)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
90 {
897
65772ddee88c Use dive profile as source for simulator:
ideenmodellierer
parents: 888
diff changeset
91 uint16_t replayDataLength = 0;
65772ddee88c Use dive profile as source for simulator:
ideenmodellierer
parents: 888
diff changeset
92 uint8_t* pReplayMarker;
65772ddee88c Use dive profile as source for simulator:
ideenmodellierer
parents: 888
diff changeset
93 uint16_t max_depth = 10;
65772ddee88c Use dive profile as source for simulator:
ideenmodellierer
parents: 888
diff changeset
94 uint16_t diveMinutes = 0;
65772ddee88c Use dive profile as source for simulator:
ideenmodellierer
parents: 888
diff changeset
95
629
55a9aa740f13 Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents: 548
diff changeset
96 copyDiveSettingsToSim();
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
97 copyVpmRepetetiveDataToSim();
901
e4e9acfde839 Bugfix simulator/planer:
Ideenmodellierer
parents: 897
diff changeset
98
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
99 //vpm_init(&stateSimGetPointerWrite()->vpm, stateSimGetPointerWrite()->diveSettings.vpm_conservatism, 0, 0);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
100 stateSimGetPointerWrite()->lifeData.counterSecondsShallowDepth = 0;
629
55a9aa740f13 Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents: 548
diff changeset
101 stateSimGetPointerWrite()->mode = MODE_DIVE;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
102 if(aim_depth <= 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
103 aim_depth = 20;
897
65772ddee88c Use dive profile as source for simulator:
ideenmodellierer
parents: 888
diff changeset
104 sim_descent_rate_meter_per_min = 20;
629
55a9aa740f13 Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents: 548
diff changeset
105 simulation_set_aim_depth(aim_depth);
760
21949c88da90 Quit simualted dives after the dive time set in the SIM tab.
heinrichsweikamp
parents: 748
diff changeset
106 sim_aim_time_minutes = aim_time_minutes;
629
55a9aa740f13 Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents: 548
diff changeset
107 timer_init();
55a9aa740f13 Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents: 548
diff changeset
108 set_stateUsedToSim();
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
109 stateSim.lifeData.boolResetAverageDepth = 1;
629
55a9aa740f13 Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents: 548
diff changeset
110 decoLock = DECO_CALC_init_as_is_start_of_dive;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
111
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
112 stateSim.lifeData.apnea_total_max_depth_meter = 0;
924
4d98fb2a178e Bugfix real scrubber time decreased in sim mode:
Ideenmodellierer
parents: 910
diff changeset
113
4d98fb2a178e Bugfix real scrubber time decreased in sim mode:
Ideenmodellierer
parents: 910
diff changeset
114 memcpy(stateSim.scrubberDataDive, settingsGetPointer()->scrubberData, sizeof(stateSim.scrubberDataDive));
629
55a9aa740f13 Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents: 548
diff changeset
115 memset(simSensmVOffset,0,sizeof(simSensmVOffset));
897
65772ddee88c Use dive profile as source for simulator:
ideenmodellierer
parents: 888
diff changeset
116 if(getReplayOffset() != 0xFFFF)
65772ddee88c Use dive profile as source for simulator:
ideenmodellierer
parents: 888
diff changeset
117 {
65772ddee88c Use dive profile as source for simulator:
ideenmodellierer
parents: 888
diff changeset
118 simReplayActive = 1;
65772ddee88c Use dive profile as source for simulator:
ideenmodellierer
parents: 888
diff changeset
119 getReplayInfo(&pReplayData, &pReplayMarker, &replayDataLength, &max_depth, &diveMinutes);
65772ddee88c Use dive profile as source for simulator:
ideenmodellierer
parents: 888
diff changeset
120 }
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
121 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
122
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 * @brief end of simulation
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
126 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
127 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
128 * @return void
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
129 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
130 void simulation_exit(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
131 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
132 timer_Stopwatch_Stop();
805
dd7ce655db26 Adds a simple countdown timer, available as a custom view in surface and dive mode.
heinrichsweikamp
parents: 790
diff changeset
133
dd7ce655db26 Adds a simple countdown timer, available as a custom view in surface and dive mode.
heinrichsweikamp
parents: 790
diff changeset
134 disableTimer();
dd7ce655db26 Adds a simple countdown timer, available as a custom view in surface and dive mode.
heinrichsweikamp
parents: 790
diff changeset
135
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
136 set_stateUsedToReal();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
137 }
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 * @brief simulates change of Lifedata (saturation, depth change, etc.) within one second
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
142 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
143 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
144 * @param checkOncePerSecond : true -> simulation in real time (function is evaluated only once per second)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
145 * and copy of parts of LifeData from SmallCPU with each call from HAL_TIM_PeriodElapsedCallback()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
146 * : false -> fast simulation (many simulation cycles per second are possible)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
147 * @return void
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
148 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
149 void simulation_UpdateLifeData( _Bool checkOncePerSecond)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
150 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
151 SDiveState * pDiveState = &stateSim;
813
1e688b630a6e Used real sensor state in simulation:
Ideenmodellierer
parents: 805
diff changeset
152 const SDiveState * pRealState = stateRealGetPointer();
629
55a9aa740f13 Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents: 548
diff changeset
153 SSettings *pSettings;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
154
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
155 static int last_second = -1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
156 static _Bool two_second = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
157 static float lastPressure_bar = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
158
924
4d98fb2a178e Bugfix real scrubber time decreased in sim mode:
Ideenmodellierer
parents: 910
diff changeset
159 pSettings = settingsGetPointer();
4d98fb2a178e Bugfix real scrubber time decreased in sim mode:
Ideenmodellierer
parents: 910
diff changeset
160
897
65772ddee88c Use dive profile as source for simulator:
ideenmodellierer
parents: 888
diff changeset
161 if ((sim_aim_time_minutes && sim_aim_time_minutes * 60 <= pDiveState->lifeData.dive_time_seconds)
65772ddee88c Use dive profile as source for simulator:
ideenmodellierer
parents: 888
diff changeset
162 && (!simReplayActive))
65772ddee88c Use dive profile as source for simulator:
ideenmodellierer
parents: 888
diff changeset
163 {
760
21949c88da90 Quit simualted dives after the dive time set in the SIM tab.
heinrichsweikamp
parents: 748
diff changeset
164 simulation_set_aim_depth(0);
21949c88da90 Quit simualted dives after the dive time set in the SIM tab.
heinrichsweikamp
parents: 748
diff changeset
165 }
21949c88da90 Quit simualted dives after the dive time set in the SIM tab.
heinrichsweikamp
parents: 748
diff changeset
166
699
01f40cb1057e Cleanup warnings:
Ideenmodellierer
parents: 678
diff changeset
167 float localCalibCoeff[3] = { 0.0, 0.0, 0.0 };
629
55a9aa740f13 Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents: 548
diff changeset
168 uint8_t index, index2;
55a9aa740f13 Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents: 548
diff changeset
169
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
170 if(checkOncePerSecond)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
171 {
901
e4e9acfde839 Bugfix simulator/planer:
Ideenmodellierer
parents: 897
diff changeset
172 int now = current_second();
e4e9acfde839 Bugfix simulator/planer:
Ideenmodellierer
parents: 897
diff changeset
173 if( last_second == now)
e4e9acfde839 Bugfix simulator/planer:
Ideenmodellierer
parents: 897
diff changeset
174 return;
e4e9acfde839 Bugfix simulator/planer:
Ideenmodellierer
parents: 897
diff changeset
175 last_second = now;
629
55a9aa740f13 Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents: 548
diff changeset
176
901
e4e9acfde839 Bugfix simulator/planer:
Ideenmodellierer
parents: 897
diff changeset
177 if(!two_second)
e4e9acfde839 Bugfix simulator/planer:
Ideenmodellierer
parents: 897
diff changeset
178 two_second = 1;
e4e9acfde839 Bugfix simulator/planer:
Ideenmodellierer
parents: 897
diff changeset
179 else
e4e9acfde839 Bugfix simulator/planer:
Ideenmodellierer
parents: 897
diff changeset
180 {
e4e9acfde839 Bugfix simulator/planer:
Ideenmodellierer
parents: 897
diff changeset
181 two_second = 0;
e4e9acfde839 Bugfix simulator/planer:
Ideenmodellierer
parents: 897
diff changeset
182 }
924
4d98fb2a178e Bugfix real scrubber time decreased in sim mode:
Ideenmodellierer
parents: 910
diff changeset
183
629
55a9aa740f13 Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents: 548
diff changeset
184 for(index = 0; index < 3; index++)
55a9aa740f13 Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents: 548
diff changeset
185 {
977
f0622dd93fdf Bugfix ppo2 display in simulator mode:
Ideenmodellierer
parents: 973
diff changeset
186 if(pDiveState->lifeData.extIf_sensor_map[index] == SENSOR_DIGO2M)
f0622dd93fdf Bugfix ppo2 display in simulator mode:
Ideenmodellierer
parents: 973
diff changeset
187 {
f0622dd93fdf Bugfix ppo2 display in simulator mode:
Ideenmodellierer
parents: 973
diff changeset
188 localCalibCoeff[index] = 0.01;
f0622dd93fdf Bugfix ppo2 display in simulator mode:
Ideenmodellierer
parents: 973
diff changeset
189 }
f0622dd93fdf Bugfix ppo2 display in simulator mode:
Ideenmodellierer
parents: 973
diff changeset
190 else
629
55a9aa740f13 Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents: 548
diff changeset
191 {
977
f0622dd93fdf Bugfix ppo2 display in simulator mode:
Ideenmodellierer
parents: 973
diff changeset
192 localCalibCoeff[index] = pSettings->ppo2sensors_calibCoeff[index];
f0622dd93fdf Bugfix ppo2 display in simulator mode:
Ideenmodellierer
parents: 973
diff changeset
193 if(localCalibCoeff[index] < 0.01)
f0622dd93fdf Bugfix ppo2 display in simulator mode:
Ideenmodellierer
parents: 973
diff changeset
194 {
f0622dd93fdf Bugfix ppo2 display in simulator mode:
Ideenmodellierer
parents: 973
diff changeset
195 for(index2 = 0; index2 < 3; index2++) /* no valid coeff => check other entries */
f0622dd93fdf Bugfix ppo2 display in simulator mode:
Ideenmodellierer
parents: 973
diff changeset
196 {
f0622dd93fdf Bugfix ppo2 display in simulator mode:
Ideenmodellierer
parents: 973
diff changeset
197 if(pSettings->ppo2sensors_calibCoeff[index2] > 0.01)
f0622dd93fdf Bugfix ppo2 display in simulator mode:
Ideenmodellierer
parents: 973
diff changeset
198 {
f0622dd93fdf Bugfix ppo2 display in simulator mode:
Ideenmodellierer
parents: 973
diff changeset
199 localCalibCoeff[index] = pSettings->ppo2sensors_calibCoeff[index2];
f0622dd93fdf Bugfix ppo2 display in simulator mode:
Ideenmodellierer
parents: 973
diff changeset
200 break;
f0622dd93fdf Bugfix ppo2 display in simulator mode:
Ideenmodellierer
parents: 973
diff changeset
201 }
f0622dd93fdf Bugfix ppo2 display in simulator mode:
Ideenmodellierer
parents: 973
diff changeset
202 if(index2 == 3) /* no coeff at all => use default */
f0622dd93fdf Bugfix ppo2 display in simulator mode:
Ideenmodellierer
parents: 973
diff changeset
203 {
f0622dd93fdf Bugfix ppo2 display in simulator mode:
Ideenmodellierer
parents: 973
diff changeset
204 localCalibCoeff[index] = 0.02;
f0622dd93fdf Bugfix ppo2 display in simulator mode:
Ideenmodellierer
parents: 973
diff changeset
205 }
f0622dd93fdf Bugfix ppo2 display in simulator mode:
Ideenmodellierer
parents: 973
diff changeset
206 }
f0622dd93fdf Bugfix ppo2 display in simulator mode:
Ideenmodellierer
parents: 973
diff changeset
207 }
629
55a9aa740f13 Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents: 548
diff changeset
208 }
55a9aa740f13 Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents: 548
diff changeset
209 }
55a9aa740f13 Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents: 548
diff changeset
210
813
1e688b630a6e Used real sensor state in simulation:
Ideenmodellierer
parents: 805
diff changeset
211 pDiveState->lifeData.temperature_celsius = pRealState->lifeData.temperature_celsius;
1e688b630a6e Used real sensor state in simulation:
Ideenmodellierer
parents: 805
diff changeset
212 pDiveState->lifeData.battery_charge = pRealState->lifeData.battery_charge;
1e688b630a6e Used real sensor state in simulation:
Ideenmodellierer
parents: 805
diff changeset
213 pDiveState->lifeData.compass_heading = pRealState->lifeData.compass_heading;
1e688b630a6e Used real sensor state in simulation:
Ideenmodellierer
parents: 805
diff changeset
214 pDiveState->lifeData.compass_roll = pRealState->lifeData.compass_roll;
1e688b630a6e Used real sensor state in simulation:
Ideenmodellierer
parents: 805
diff changeset
215 pDiveState->lifeData.compass_pitch = pRealState->lifeData.compass_pitch;
1e688b630a6e Used real sensor state in simulation:
Ideenmodellierer
parents: 805
diff changeset
216
1e688b630a6e Used real sensor state in simulation:
Ideenmodellierer
parents: 805
diff changeset
217 for(index = 0; index < 3; index++)
1e688b630a6e Used real sensor state in simulation:
Ideenmodellierer
parents: 805
diff changeset
218 {
1e688b630a6e Used real sensor state in simulation:
Ideenmodellierer
parents: 805
diff changeset
219 memcpy(&pDiveState->lifeData.extIf_sensor_data[index], &pRealState->lifeData.extIf_sensor_data[index], 32);
1e688b630a6e Used real sensor state in simulation:
Ideenmodellierer
parents: 805
diff changeset
220 }
548
e7e44986684a Update roll and pitch value in simulation mode:
Ideenmodellierer
parents: 450
diff changeset
221
446
f1257a32f2d4 Introduced configuration header for variant managment:
ideenmodellierer
parents: 308
diff changeset
222 #ifdef ENABLE_BOTTLE_SENSOR
813
1e688b630a6e Used real sensor state in simulation:
Ideenmodellierer
parents: 805
diff changeset
223 pDiveState->lifeData.bottle_bar[pDiveState->lifeData.actualGas.GasIdInSettings] = pRealState->lifeData.bottle_bar[pRealState->lifeData.actualGas.GasIdInSettings];
1e688b630a6e Used real sensor state in simulation:
Ideenmodellierer
parents: 805
diff changeset
224 pDiveState->lifeData.bottle_bar_age_MilliSeconds[pDiveState->lifeData.actualGas.GasIdInSettings] = pRealState->lifeData.bottle_bar_age_MilliSeconds[pRealState->lifeData.actualGas.GasIdInSettings];
446
f1257a32f2d4 Introduced configuration header for variant managment:
ideenmodellierer
parents: 308
diff changeset
225 #endif
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
226 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
227 else if(pDiveState->lifeData.depth_meter <= (float)(decom_get_actual_deco_stop(pDiveState) + 0.001))
901
e4e9acfde839 Bugfix simulator/planer:
Ideenmodellierer
parents: 897
diff changeset
228 {
e4e9acfde839 Bugfix simulator/planer:
Ideenmodellierer
parents: 897
diff changeset
229 if(decoLock == DECO_CALC_FINSHED_vpm)
e4e9acfde839 Bugfix simulator/planer:
Ideenmodellierer
parents: 897
diff changeset
230 {
e4e9acfde839 Bugfix simulator/planer:
Ideenmodellierer
parents: 897
diff changeset
231 sim_reduce_deco_time_one_second(&stateDeco);
e4e9acfde839 Bugfix simulator/planer:
Ideenmodellierer
parents: 897
diff changeset
232 }
e4e9acfde839 Bugfix simulator/planer:
Ideenmodellierer
parents: 897
diff changeset
233 else
e4e9acfde839 Bugfix simulator/planer:
Ideenmodellierer
parents: 897
diff changeset
234 {
e4e9acfde839 Bugfix simulator/planer:
Ideenmodellierer
parents: 897
diff changeset
235 sim_reduce_deco_time_one_second(pDiveState);
e4e9acfde839 Bugfix simulator/planer:
Ideenmodellierer
parents: 897
diff changeset
236 }
e4e9acfde839 Bugfix simulator/planer:
Ideenmodellierer
parents: 897
diff changeset
237 }
897
65772ddee88c Use dive profile as source for simulator:
ideenmodellierer
parents: 888
diff changeset
238
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
239 pDiveState->lifeData.dive_time_seconds += 1;
300
5ca177d2df5d cleanup: remove commented/unused code, make static
Jan Mulder <jlmulder@xs4all.nl>
parents: 233
diff changeset
240 pDiveState->lifeData.pressure_ambient_bar = sim_get_ambient_pressure(pDiveState);
953
d565812061f4 Bugfix ascent graph in simulator:
Ideenmodellierer
parents: 924
diff changeset
241 if(pDiveState->lifeData.depth_meter < 1.5)
897
65772ddee88c Use dive profile as source for simulator:
ideenmodellierer
parents: 888
diff changeset
242 {
65772ddee88c Use dive profile as source for simulator:
ideenmodellierer
parents: 888
diff changeset
243 lastPressure_bar = 0;
65772ddee88c Use dive profile as source for simulator:
ideenmodellierer
parents: 888
diff changeset
244 pDiveState->lifeData.ascent_rate_meter_per_min = 0;
65772ddee88c Use dive profile as source for simulator:
ideenmodellierer
parents: 888
diff changeset
245 }
924
4d98fb2a178e Bugfix real scrubber time decreased in sim mode:
Ideenmodellierer
parents: 910
diff changeset
246
4d98fb2a178e Bugfix real scrubber time decreased in sim mode:
Ideenmodellierer
parents: 910
diff changeset
247 if((pSettings->scrubTimerMode != SCRUB_TIMER_OFF) && (isLoopMode(pSettings->dive_mode)) && (pDiveState->mode == MODE_DIVE) && isLoopMode(pDiveState->diveSettings.diveMode))
4d98fb2a178e Bugfix real scrubber time decreased in sim mode:
Ideenmodellierer
parents: 910
diff changeset
248 {
4d98fb2a178e Bugfix real scrubber time decreased in sim mode:
Ideenmodellierer
parents: 910
diff changeset
249 simScrubberTimeoutCount++;
4d98fb2a178e Bugfix real scrubber time decreased in sim mode:
Ideenmodellierer
parents: 910
diff changeset
250 if(simScrubberTimeoutCount >= 60) /* resolution is minutes */
4d98fb2a178e Bugfix real scrubber time decreased in sim mode:
Ideenmodellierer
parents: 910
diff changeset
251 {
4d98fb2a178e Bugfix real scrubber time decreased in sim mode:
Ideenmodellierer
parents: 910
diff changeset
252 simScrubberTimeoutCount = 0;
4d98fb2a178e Bugfix real scrubber time decreased in sim mode:
Ideenmodellierer
parents: 910
diff changeset
253 if(pDiveState->scrubberDataDive[pSettings->scubberActiveId].TimerCur > MIN_SCRUBBER_TIME)
4d98fb2a178e Bugfix real scrubber time decreased in sim mode:
Ideenmodellierer
parents: 910
diff changeset
254 {
4d98fb2a178e Bugfix real scrubber time decreased in sim mode:
Ideenmodellierer
parents: 910
diff changeset
255 pDiveState->scrubberDataDive[pSettings->scubberActiveId].TimerCur--;
4d98fb2a178e Bugfix real scrubber time decreased in sim mode:
Ideenmodellierer
parents: 910
diff changeset
256 }
980
7149f372b0ba Fix a couple of bugs in the scrubber timer:
heinrichsweikamp
parents: 977
diff changeset
257 translateDate(stateUsed->lifeData.dateBinaryFormat, &pDiveState->scrubberDataDive[pSettings->scubberActiveId].lastDive);
924
4d98fb2a178e Bugfix real scrubber time decreased in sim mode:
Ideenmodellierer
parents: 910
diff changeset
258 }
4d98fb2a178e Bugfix real scrubber time decreased in sim mode:
Ideenmodellierer
parents: 910
diff changeset
259 }
4d98fb2a178e Bugfix real scrubber time decreased in sim mode:
Ideenmodellierer
parents: 910
diff changeset
260
4d98fb2a178e Bugfix real scrubber time decreased in sim mode:
Ideenmodellierer
parents: 910
diff changeset
261
897
65772ddee88c Use dive profile as source for simulator:
ideenmodellierer
parents: 888
diff changeset
262 if(lastPressure_bar > 0)
65772ddee88c Use dive profile as source for simulator:
ideenmodellierer
parents: 888
diff changeset
263 {
65772ddee88c Use dive profile as source for simulator:
ideenmodellierer
parents: 888
diff changeset
264 //1 second * 60 == 1 minute, bar * 10 = meter
65772ddee88c Use dive profile as source for simulator:
ideenmodellierer
parents: 888
diff changeset
265 pDiveState->lifeData.ascent_rate_meter_per_min = (lastPressure_bar - pDiveState->lifeData.pressure_ambient_bar) * 600.0;
65772ddee88c Use dive profile as source for simulator:
ideenmodellierer
parents: 888
diff changeset
266 }
65772ddee88c Use dive profile as source for simulator:
ideenmodellierer
parents: 888
diff changeset
267 lastPressure_bar = pDiveState->lifeData.pressure_ambient_bar;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
268
813
1e688b630a6e Used real sensor state in simulation:
Ideenmodellierer
parents: 805
diff changeset
269 pDiveState->lifeData.sensorVoltage_mV[0] = pRealState->lifeData.sensorVoltage_mV[0] + simSensmVOffset[0];
629
55a9aa740f13 Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents: 548
diff changeset
270 if(pDiveState->lifeData.sensorVoltage_mV[0] < 0.0) { pDiveState->lifeData.sensorVoltage_mV[0] = 0.0; }
813
1e688b630a6e Used real sensor state in simulation:
Ideenmodellierer
parents: 805
diff changeset
271 pDiveState->lifeData.sensorVoltage_mV[1] = pRealState->lifeData.sensorVoltage_mV[1] + simSensmVOffset[1];
629
55a9aa740f13 Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents: 548
diff changeset
272 if(pDiveState->lifeData.sensorVoltage_mV[1] < 0.0) { pDiveState->lifeData.sensorVoltage_mV[1] = 0.0; }
813
1e688b630a6e Used real sensor state in simulation:
Ideenmodellierer
parents: 805
diff changeset
273 pDiveState->lifeData.sensorVoltage_mV[2] = pRealState->lifeData.sensorVoltage_mV[2] + simSensmVOffset[2];
629
55a9aa740f13 Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents: 548
diff changeset
274 if(pDiveState->lifeData.sensorVoltage_mV[2] < 0.0) { pDiveState->lifeData.sensorVoltage_mV[2] = 0.0; }
55a9aa740f13 Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents: 548
diff changeset
275
55a9aa740f13 Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents: 548
diff changeset
276 pDiveState->lifeData.ppO2Sensor_bar[0] = pDiveState->lifeData.sensorVoltage_mV[0] * localCalibCoeff[0] * pDiveState->lifeData.pressure_ambient_bar;
55a9aa740f13 Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents: 548
diff changeset
277 pDiveState->lifeData.ppO2Sensor_bar[1] = pDiveState->lifeData.sensorVoltage_mV[1] * localCalibCoeff[1] * pDiveState->lifeData.pressure_ambient_bar;
55a9aa740f13 Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents: 548
diff changeset
278 pDiveState->lifeData.ppO2Sensor_bar[2] = pDiveState->lifeData.sensorVoltage_mV[2] * localCalibCoeff[2] * pDiveState->lifeData.pressure_ambient_bar;
55a9aa740f13 Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents: 548
diff changeset
279
813
1e688b630a6e Used real sensor state in simulation:
Ideenmodellierer
parents: 805
diff changeset
280 pDiveState->lifeData.CO2_data.CO2_ppm = pRealState->lifeData.CO2_data.CO2_ppm;
629
55a9aa740f13 Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents: 548
diff changeset
281
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
282 if(is_ambient_pressure_close_to_surface(&pDiveState->lifeData)) // new hw 170214
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
283 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
284 if(!(stateSimGetPointer()->lifeData.counterSecondsShallowDepth))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
285 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
286 if(pDiveState->diveSettings.diveMode != DIVEMODE_Apnea)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
287 pDiveState->lifeData.counterSecondsShallowDepth = settingsGetPointer()->timeoutDiveReachedZeroDepth - 15;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
288 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
289 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
290 pDiveState->lifeData.apnea_last_dive_time_seconds = pDiveState->lifeData.dive_time_seconds;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
291 if(pDiveState->lifeData.apnea_last_dive_time_seconds > pDiveState->lifeData.dive_time_seconds_without_surface_time)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
292 pDiveState->lifeData.apnea_last_dive_time_seconds = pDiveState->lifeData.dive_time_seconds_without_surface_time;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
293 pDiveState->lifeData.apnea_last_max_depth_meter = pDiveState->lifeData.max_depth_meter;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
294 pDiveState->lifeData.counterSecondsShallowDepth = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
295 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
296 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
297 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
298 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
299 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
300 pDiveState->lifeData.counterSecondsShallowDepth = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
301 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
302
304
43b44f8d4fb0 bugfix, simulator: fix the 1 sec difference between stopwatch and divetime
Jan Mulder <jlmulder@xs4all.nl>
parents: 300
diff changeset
303 if(!is_ambient_pressure_close_to_surface(&pDiveState->lifeData) && !(stateSimGetPointer()->lifeData.counterSecondsShallowDepth) )
43b44f8d4fb0 bugfix, simulator: fix the 1 sec difference between stopwatch and divetime
Jan Mulder <jlmulder@xs4all.nl>
parents: 300
diff changeset
304 {
43b44f8d4fb0 bugfix, simulator: fix the 1 sec difference between stopwatch and divetime
Jan Mulder <jlmulder@xs4all.nl>
parents: 300
diff changeset
305 pDiveState->lifeData.dive_time_seconds_without_surface_time += 1;
43b44f8d4fb0 bugfix, simulator: fix the 1 sec difference between stopwatch and divetime
Jan Mulder <jlmulder@xs4all.nl>
parents: 300
diff changeset
306 }
43b44f8d4fb0 bugfix, simulator: fix the 1 sec difference between stopwatch and divetime
Jan Mulder <jlmulder@xs4all.nl>
parents: 300
diff changeset
307
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
308 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
309 if(pDiveState->lifeData.max_depth_meter < pDiveState->lifeData.depth_meter)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
310 pDiveState->lifeData.max_depth_meter = pDiveState->lifeData.depth_meter;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
311
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
312 /* apnoe specials
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
313 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
314 if(pDiveState->diveSettings.diveMode == DIVEMODE_Apnea)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
315 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
316 if(pDiveState->lifeData.max_depth_meter > pDiveState->lifeData.apnea_total_max_depth_meter)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
317 pDiveState->lifeData.apnea_total_max_depth_meter = pDiveState->lifeData.max_depth_meter;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
318
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
319 if(pDiveState->lifeData.counterSecondsShallowDepth)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
320 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
321 pDiveState->lifeData.dive_time_seconds = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
322 pDiveState->lifeData.max_depth_meter = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
323 pDiveState->lifeData.boolResetAverageDepth = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
324 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
325 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
326
308
1203255481e4 cleanup: introduce function setAvgDepth
Jan Mulder <jlmulder@xs4all.nl>
parents: 307
diff changeset
327 setAvgDepth(pDiveState);
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
328
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
329 /* Exposure Tissues
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
330 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
331 decom_tissues_exposure(1, &pDiveState->lifeData);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
332 decom_oxygen_calculate_cns_exposure(1, &pDiveState->lifeData.actualGas, pDiveState->lifeData.pressure_ambient_bar, &pDiveState->lifeData.cns);
233
9f0efc4df01e cleanup, bugfix: do not exit simulator on 5h dive time
Jan Mulder <jlmulder@xs4all.nl>
parents: 225
diff changeset
333
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
334 if(stateSimGetPointer()->lifeData.counterSecondsShallowDepth)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
335 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
336 stateSimGetPointerWrite()->lifeData.counterSecondsShallowDepth += 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
337 if(stateSimGetPointer()->lifeData.counterSecondsShallowDepth >= settingsGetPointer()->timeoutDiveReachedZeroDepth)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
338 simulation_exit();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
339 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
340 vpm_crush(pDiveState);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
341 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
342
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
343 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
344 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
345 * @brief adds extra time for fast simulation
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
346 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
347 *@param minutes
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
348 * @return float : new pressure
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
349 */
225
2bb1db22b5f5 cleanup: random set of cleanups
Jan Mulder <jlmulder@xs4all.nl>
parents: 176
diff changeset
350 static void simulation_add_time(int minutes)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
351 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
352 for(int i = 0; i < 60 * minutes; i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
353 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
354 simulation_UpdateLifeData(0);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
355 updateMiniLiveLogbook(0);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
356 timer_UpdateSecond(0);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
357 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
358 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
359
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
360 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
361 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
362 * @brief get aim_depth
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
363 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
364 * @return sim_aim_depth_meter;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
365 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
366
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
367 uint16_t simulation_get_aim_depth(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
368 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
369 return (uint16_t)sim_aim_depth_meter;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
370 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
371
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
372 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
373 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
374 * @brief get heed decostops
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
375 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
376 * @return true if ascend follows decostops;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
377 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
378
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
379 _Bool simulation_get_heed_decostops(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
380 {
225
2bb1db22b5f5 cleanup: random set of cleanups
Jan Mulder <jlmulder@xs4all.nl>
parents: 176
diff changeset
381 return sim_heed_decostops;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
382 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
383
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
384 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
385 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
386 * @brief sets aim_depth
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
387 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
388 *@param depth_meter
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
389 * @return float : new pressure
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
390 */
225
2bb1db22b5f5 cleanup: random set of cleanups
Jan Mulder <jlmulder@xs4all.nl>
parents: 176
diff changeset
391 static void simulation_set_aim_depth(int depth_meter)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
392 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
393 sim_aim_depth_meter = depth_meter;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
394 }
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 ******************************************************************************
300
5ca177d2df5d cleanup: remove commented/unused code, make static
Jan Mulder <jlmulder@xs4all.nl>
parents: 233
diff changeset
398 * @brief simulates ambient pressure depending on aim depth
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
399 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
400 * @note if aim_depth != actual depth, the depth change within one second
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
401 * (depending on descent or ascent) rate is calculated
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
402 * @param SDiveState* pDiveState:
300
5ca177d2df5d cleanup: remove commented/unused code, make static
Jan Mulder <jlmulder@xs4all.nl>
parents: 233
diff changeset
403 * @return float : new ambient pressure
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
404 */
300
5ca177d2df5d cleanup: remove commented/unused code, make static
Jan Mulder <jlmulder@xs4all.nl>
parents: 233
diff changeset
405 static float sim_get_ambient_pressure(SDiveState * pDiveState)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
406 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
407 //Calc next depth
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
408 uint8_t actual_deco_stop = decom_get_actual_deco_stop(pDiveState);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
409 float depth_meter = pDiveState->lifeData.depth_meter;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
410 float surface_pressure_bar = pDiveState->lifeData.pressure_surface_bar;
897
65772ddee88c Use dive profile as source for simulator:
ideenmodellierer
parents: 888
diff changeset
411 static uint8_t sampleToggle = 0;
910
7bd347bdaa81 Devbugfix Sample time resolution for longer dives:
Ideenmodellierer
parents: 907
diff changeset
412 static float sim_ascent_rate_meter_per_min_local = 0;
7bd347bdaa81 Devbugfix Sample time resolution for longer dives:
Ideenmodellierer
parents: 907
diff changeset
413 uint8_t sampleTime = getReplayDataResolution();
897
65772ddee88c Use dive profile as source for simulator:
ideenmodellierer
parents: 888
diff changeset
414
910
7bd347bdaa81 Devbugfix Sample time resolution for longer dives:
Ideenmodellierer
parents: 907
diff changeset
415 if(simReplayActive) /* precondition: function is called once per second, sample rate is a multiple of second */
897
65772ddee88c Use dive profile as source for simulator:
ideenmodellierer
parents: 888
diff changeset
416 {
65772ddee88c Use dive profile as source for simulator:
ideenmodellierer
parents: 888
diff changeset
417 if(sampleToggle == 0)
65772ddee88c Use dive profile as source for simulator:
ideenmodellierer
parents: 888
diff changeset
418 {
910
7bd347bdaa81 Devbugfix Sample time resolution for longer dives:
Ideenmodellierer
parents: 907
diff changeset
419 sampleToggle = sampleTime - 1;
897
65772ddee88c Use dive profile as source for simulator:
ideenmodellierer
parents: 888
diff changeset
420 sim_aim_depth_meter = (float)(*pReplayData++/100.0);
910
7bd347bdaa81 Devbugfix Sample time resolution for longer dives:
Ideenmodellierer
parents: 907
diff changeset
421 if(sim_aim_depth_meter > depth_meter)
7bd347bdaa81 Devbugfix Sample time resolution for longer dives:
Ideenmodellierer
parents: 907
diff changeset
422 {
7bd347bdaa81 Devbugfix Sample time resolution for longer dives:
Ideenmodellierer
parents: 907
diff changeset
423 sim_descent_rate_meter_per_min = (sim_aim_depth_meter - depth_meter) * (60 / sampleTime);
7bd347bdaa81 Devbugfix Sample time resolution for longer dives:
Ideenmodellierer
parents: 907
diff changeset
424 }
7bd347bdaa81 Devbugfix Sample time resolution for longer dives:
Ideenmodellierer
parents: 907
diff changeset
425 else
7bd347bdaa81 Devbugfix Sample time resolution for longer dives:
Ideenmodellierer
parents: 907
diff changeset
426 {
7bd347bdaa81 Devbugfix Sample time resolution for longer dives:
Ideenmodellierer
parents: 907
diff changeset
427 sim_ascent_rate_meter_per_min_local = (depth_meter - sim_aim_depth_meter) * (60 / sampleTime);
7bd347bdaa81 Devbugfix Sample time resolution for longer dives:
Ideenmodellierer
parents: 907
diff changeset
428 }
897
65772ddee88c Use dive profile as source for simulator:
ideenmodellierer
parents: 888
diff changeset
429 }
65772ddee88c Use dive profile as source for simulator:
ideenmodellierer
parents: 888
diff changeset
430 else
65772ddee88c Use dive profile as source for simulator:
ideenmodellierer
parents: 888
diff changeset
431 {
910
7bd347bdaa81 Devbugfix Sample time resolution for longer dives:
Ideenmodellierer
parents: 907
diff changeset
432 sampleToggle--;
897
65772ddee88c Use dive profile as source for simulator:
ideenmodellierer
parents: 888
diff changeset
433 }
65772ddee88c Use dive profile as source for simulator:
ideenmodellierer
parents: 888
diff changeset
434 }
910
7bd347bdaa81 Devbugfix Sample time resolution for longer dives:
Ideenmodellierer
parents: 907
diff changeset
435 else
7bd347bdaa81 Devbugfix Sample time resolution for longer dives:
Ideenmodellierer
parents: 907
diff changeset
436 {
7bd347bdaa81 Devbugfix Sample time resolution for longer dives:
Ideenmodellierer
parents: 907
diff changeset
437 sim_ascent_rate_meter_per_min_local = pDiveState->diveSettings.ascentRate_meterperminute;
7bd347bdaa81 Devbugfix Sample time resolution for longer dives:
Ideenmodellierer
parents: 907
diff changeset
438 }
897
65772ddee88c Use dive profile as source for simulator:
ideenmodellierer
parents: 888
diff changeset
439
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
440 if(depth_meter < sim_aim_depth_meter)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
441 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
442 depth_meter = depth_meter + sim_descent_rate_meter_per_min / 60;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
443 if(depth_meter > sim_aim_depth_meter)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
444 depth_meter = sim_aim_depth_meter;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
445 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
446 else if(depth_meter > sim_aim_depth_meter)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
447 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
448
910
7bd347bdaa81 Devbugfix Sample time resolution for longer dives:
Ideenmodellierer
parents: 907
diff changeset
449 depth_meter -= sim_ascent_rate_meter_per_min_local / 60;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
450 if(depth_meter < sim_aim_depth_meter)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
451 depth_meter = sim_aim_depth_meter;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
452
225
2bb1db22b5f5 cleanup: random set of cleanups
Jan Mulder <jlmulder@xs4all.nl>
parents: 176
diff changeset
453 if(sim_heed_decostops && depth_meter < actual_deco_stop)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
454 {
910
7bd347bdaa81 Devbugfix Sample time resolution for longer dives:
Ideenmodellierer
parents: 907
diff changeset
455 if(actual_deco_stop < (depth_meter + sim_ascent_rate_meter_per_min_local / 60))
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
456 depth_meter = actual_deco_stop;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
457 else
910
7bd347bdaa81 Devbugfix Sample time resolution for longer dives:
Ideenmodellierer
parents: 907
diff changeset
458 depth_meter += sim_ascent_rate_meter_per_min_local / 60;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
459 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
460
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
461 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
462
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
463 return surface_pressure_bar + depth_meter / 10;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
464 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
465
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
466
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
467 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
468 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
469 * @brief Reduces deco time of deepest stop by one second
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
470 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
471 * @note called during fast simulation
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
472 * @param SDiveState* pDiveState:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
473 * @return void
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
474 */
300
5ca177d2df5d cleanup: remove commented/unused code, make static
Jan Mulder <jlmulder@xs4all.nl>
parents: 233
diff changeset
475 static void sim_reduce_deco_time_one_second(SDiveState* pDiveState)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
476 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
477 SDecoinfo* pDecoinfo;
901
e4e9acfde839 Bugfix simulator/planer:
Ideenmodellierer
parents: 897
diff changeset
478 int8_t index = 0;
e4e9acfde839 Bugfix simulator/planer:
Ideenmodellierer
parents: 897
diff changeset
479
e4e9acfde839 Bugfix simulator/planer:
Ideenmodellierer
parents: 897
diff changeset
480
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
481 if(pDiveState->diveSettings.deco_type.ub.standard == GF_MODE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
482 pDecoinfo = &pDiveState->decolistBuehlmann;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
483 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
484 pDecoinfo = &pDiveState->decolistVPM;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
485
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
486 //Reduce deco time of deepest stop by one second
901
e4e9acfde839 Bugfix simulator/planer:
Ideenmodellierer
parents: 897
diff changeset
487 for(index = DECOINFO_STRUCT_MAX_STOPS -1 ;index >= 0; index--)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
488 {
901
e4e9acfde839 Bugfix simulator/planer:
Ideenmodellierer
parents: 897
diff changeset
489 if(pDecoinfo->output_stop_length_seconds[index] > 0)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
490 {
901
e4e9acfde839 Bugfix simulator/planer:
Ideenmodellierer
parents: 897
diff changeset
491 pDecoinfo->output_stop_length_seconds[index]--;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
492 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
493 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
494 }
901
e4e9acfde839 Bugfix simulator/planer:
Ideenmodellierer
parents: 897
diff changeset
495 /* update TTS */
e4e9acfde839 Bugfix simulator/planer:
Ideenmodellierer
parents: 897
diff changeset
496 if(pDecoinfo->output_time_to_surface_seconds)
e4e9acfde839 Bugfix simulator/planer:
Ideenmodellierer
parents: 897
diff changeset
497 {
e4e9acfde839 Bugfix simulator/planer:
Ideenmodellierer
parents: 897
diff changeset
498 pDecoinfo->output_time_to_surface_seconds--;
e4e9acfde839 Bugfix simulator/planer:
Ideenmodellierer
parents: 897
diff changeset
499 }
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
500 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
501
983
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
502 SDecoinfo* simulation_decoplaner(uint16_t depth_meter, uint16_t intervall_time_minutes, uint16_t dive_time_minutes, SgasChangeList *pGasChangeList)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
503 {
983
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
504 uint8_t GasChangeIndex = 0;
678
05cdd367dbd0 Bugfix: deco planner did not initialize properly
Jan Mulder <jan@jlmulder.nl>
parents: 629
diff changeset
505
983
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
506 for (GasChangeIndex = 0; GasChangeIndex < GAS_CHANGE_LIST_ITEMS; GasChangeIndex++)
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
507 {
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
508 pGasChangeList[GasChangeIndex].depth = 0;
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
509 pGasChangeList[GasChangeIndex].gasId = 0;
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
510 }
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
511 SDiveState * pDiveState = &stateSim;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
512 copyDiveSettingsToSim();
888
07af9efd7c13 Dev bugfix: Consider decogas in planner independen from calculation setting:
Ideenmodellierer
parents: 830
diff changeset
513
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
514 vpm_init(&pDiveState->vpm, pDiveState->diveSettings.vpm_conservatism, 0, 0);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
515 //buehlmann_init();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
516 //timer_init();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
517 memset(&pDiveState->events,0, sizeof(SEvents));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
518 pDiveState->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
519 //Calc desaturation during intervall (with Air)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
520 setActualGasAir(&pDiveState->lifeData);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
521 if(intervall_time_minutes > 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
522 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
523 decom_tissues_exposure(intervall_time_minutes * 60, &pDiveState->lifeData);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
524 decom_oxygen_calculate_cns_degrade(&pDiveState->lifeData.cns, intervall_time_minutes * 60);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
525 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
526
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
527 //Switch to first Gas
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
528 setActualGasFirst(&pDiveState->lifeData);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
529
983
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
530 GasChangeIndex = 0;
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
531
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
532 if(pGasChangeList)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
533 {
983
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
534 pGasChangeList[GasChangeIndex].depth = 0;
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
535 pGasChangeList[GasChangeIndex].gasId = pDiveState->lifeData.actualGas.GasIdInSettings;
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
536 GasChangeIndex++;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
537 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
538
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
539 //Going down / descent
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
540 simulation_set_aim_depth(depth_meter);
790
3b5f9557c053 Fix bug introduced in 04b98a2, causing the deco planner to not show deco stops.
heinrichsweikamp
parents: 760
diff changeset
541 sim_aim_time_minutes = 0;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
542 for(int i = 0; i < 60 * dive_time_minutes; i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
543 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
544 simulation_UpdateLifeData(0);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
545 check_warning2(pDiveState);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
546 if(pDiveState->warnings.betterGas)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
547 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
548 setActualGas(&pDiveState->lifeData,actualBetterGasId(),pDiveState->lifeData.actualGas.setPoint_cbar);
983
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
549 if(pGasChangeList && (pDiveState->diveSettings.diveMode == DIVEMODE_OC))
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
550 {
983
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
551 pGasChangeList[GasChangeIndex].depth = pDiveState->lifeData.depth_meter;
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
552 pGasChangeList[GasChangeIndex].gasId = actualBetterGasId();
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
553 GasChangeIndex++;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
554 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
555 }
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 decom_CreateGasChangeList(&pDiveState->diveSettings, &pDiveState->lifeData); // was there before and needed for buehlmann_calc_deco and vpm_calc
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
559
983
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
560 if(pGasChangeList && (pDiveState->diveSettings.diveMode == DIVEMODE_OC))
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
561 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
562 // change direction from better gas to deco gas
983
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
563 pGasChangeList[GasChangeIndex].depth = 255;
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
564 pGasChangeList[GasChangeIndex].gasId = 255;
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
565 GasChangeIndex++;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
566
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
567 // ascend (deco) gases
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
568 for(int i=1; i<=5;i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
569 {
983
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
570 if((pDiveState->diveSettings.decogaslist[i].change_during_ascent_depth_meter_otherwise_zero != 0)
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
571 && (pDiveState->diveSettings.gas[pDiveState->diveSettings.decogaslist[i].GasIdInSettings].note.ub.deco))
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
572 {
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
573 pGasChangeList[GasChangeIndex].depth = pDiveState->diveSettings.decogaslist[i].change_during_ascent_depth_meter_otherwise_zero;
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
574 pGasChangeList[GasChangeIndex].gasId = pDiveState->diveSettings.decogaslist[i].GasIdInSettings;
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
575 GasChangeIndex++;
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
576 }
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
577 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
578 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
579
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
580 // deco and ascend calc
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
581 if(pDiveState->diveSettings.deco_type.ub.standard == GF_MODE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
582 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
583 /* this does modify the cns now 11.06.2015 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
584 buehlmann_calc_deco(&pDiveState->lifeData,&pDiveState->diveSettings,&pDiveState->decolistBuehlmann);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
585 pDiveState->lifeData.cns += buehlmann_get_gCNS();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
586 return &pDiveState->decolistBuehlmann;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
587 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
588 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
589 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
590 /* this does modify the cns now 11.06.2015 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
591 vpm_calc(&pDiveState->lifeData,&pDiveState->diveSettings,&pDiveState->vpm,&pDiveState->decolistVPM, DECOSTOPS);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
592 pDiveState->lifeData.cns += vpm_get_CNS();
910
7bd347bdaa81 Devbugfix Sample time resolution for longer dives:
Ideenmodellierer
parents: 907
diff changeset
593
7bd347bdaa81 Devbugfix Sample time resolution for longer dives:
Ideenmodellierer
parents: 907
diff changeset
594 while(decoLock == DECO_CALC_FINSHED_vpm)
7bd347bdaa81 Devbugfix Sample time resolution for longer dives:
Ideenmodellierer
parents: 907
diff changeset
595 {
7bd347bdaa81 Devbugfix Sample time resolution for longer dives:
Ideenmodellierer
parents: 907
diff changeset
596 HAL_Delay(2); /* The deco data is copied during the timer ISR => wait till this has happened */
7bd347bdaa81 Devbugfix Sample time resolution for longer dives:
Ideenmodellierer
parents: 907
diff changeset
597 }
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
598 return &pDiveState->decolistVPM;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
599 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
600 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
601
225
2bb1db22b5f5 cleanup: random set of cleanups
Jan Mulder <jlmulder@xs4all.nl>
parents: 176
diff changeset
602 static float sGChelper_bar(uint16_t depth_meter)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
603 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
604 SDiveState * pDiveState = &stateSim;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
605 float ambient, surface, density, meter;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
606
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
607 surface = pDiveState->lifeData.pressure_surface_bar;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
608
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
609 if(!depth_meter)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
610 return surface;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
611
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
612 density = ((float)( 100 + settingsGetPointer()->salinity)) / 100.0f;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
613 meter = depth_meter * (0.09807f * density);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
614 ambient = (meter + surface);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
615
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
616 return ambient;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
617 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
618
983
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
619 void getNextDecoDepthAndTime(uint8_t* pDepth, uint16_t* pTime, uint8_t currentDepth, SDecoinfo *decoInfoInput)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
620 {
983
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
621 uint8_t depthLast, depthSecond, depthInc;
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
622 uint8_t decoIndex = 0;
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
623
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
624 depthLast = (uint8_t)(stateUsed->diveSettings.last_stop_depth_bar * 10);
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
625 depthSecond = (uint8_t)(stateUsed->diveSettings.input_second_to_last_stop_depth_bar * 10);
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
626 depthInc = (uint8_t)(stateUsed->diveSettings.input_next_stop_increment_depth_bar * 10);
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
627
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
628 if(currentDepth > depthLast)
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
629 {
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
630 for(decoIndex = DECOINFO_STRUCT_MAX_STOPS-1; decoIndex > 0; decoIndex--)
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
631 {
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
632 if(decoInfoInput->output_stop_length_seconds[decoIndex])
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
633 {
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
634 *pDepth = depthSecond + ( decoIndex - 1 ) * depthInc;
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
635 if(*pDepth < currentDepth)
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
636 {
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
637 break;
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
638 }
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
639 }
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
640 }
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
641
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
642 if(decoIndex == 0)
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
643 {
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
644 *pDepth = depthLast;
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
645 }
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
646 *pTime = decoInfoInput->output_stop_length_seconds[decoIndex];
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
647 }
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
648 else
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
649 {
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
650 *pDepth = 0;
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
651 *pTime = 0;
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
652 }
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
653 }
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
654
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
655 void simulation_evaluate_profil(uint16_t *outputConsumptionList,
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
656 SSimDataSummary *outputSummary,
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
657 uint16_t depth_meter, uint16_t dive_time_minutes,uint8_t gasConsumTravelInput, uint8_t gasConsumDecoInput,
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
658 SDecoinfo *decoInfoInput,
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
659 const SgasChangeList *pGasChangeList)
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
660 {
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
661 uint16_t nextDecoTime = 0;
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
662 uint8_t nextDecoDepth = 0;
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
663
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
664 uint8_t currentConsumGasId = 0;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
665 uint8_t nextGasChangeMeter = 0;
983
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
666 uint8_t nextGasChangeGasId = 0;
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
667 uint8_t ChangeListIndex = 0;
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
668 uint8_t firstDecoGasIndex = 0;
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
669 float outputConsumptionTempFloat[6];
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
670
983
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
671 float sim_descent_rate_meter_per_sec_local = 10.0;
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
672 float sim_ascent_rate_meter_per_sec_local = 10.0;
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
673
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
674 float currentDepth_m = 0.0;
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
675 uint16_t currentTime_sec = 0;
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
676 float currentGasConsumption = 0.0;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
677
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
678 SDiveState * pDiveState = &stateSim;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
679
983
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
680 for(ChangeListIndex = 0; ChangeListIndex < 6; ChangeListIndex++)
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
681 {
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
682 outputConsumptionTempFloat[ChangeListIndex] = 0.0;
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
683 }
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
684
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
685 if(pDiveState->diveSettings.deco_type.ub.standard == GF_MODE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
686 {
983
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
687 sim_descent_rate_meter_per_sec_local = sim_descent_rate_meter_per_min / 60.0;
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
688 sim_ascent_rate_meter_per_sec_local = pDiveState->diveSettings.ascentRate_meterperminute / 60.0;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
689 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
690 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
691 {
983
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
692 sim_descent_rate_meter_per_sec_local = sim_descent_rate_meter_per_min / 60.0;
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
693 sim_ascent_rate_meter_per_sec_local = 10.0 / 60.0; // fix in vpm_calc_deco();
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
694 }
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
695
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
696 outputSummary->descentRateMeterPerMinute = sim_descent_rate_meter_per_sec_local * 60;
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
697 outputSummary->ascentRateMeterPerMinute = sim_ascent_rate_meter_per_sec_local * 60;
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
698 outputSummary->timeToBottom = 0;
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
699 outputSummary->timeToFirstStop = 0;
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
700 outputSummary->depthMeterFirstStop = 0;
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
701 outputSummary->timeAtBottom = 0;
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
702 outputSummary->timeToSurface = 0;
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
703
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
704 currentConsumGasId = pGasChangeList[0].gasId;
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
705
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
706 /* ascent + at depth loop at the moment work gas does not support change depth => no need to check */
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
707 while(currentTime_sec < dive_time_minutes * 60)
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
708 {
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
709 if(currentDepth_m < depth_meter)
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
710 {
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
711 currentDepth_m += sim_descent_rate_meter_per_sec_local;
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
712 currentGasConsumption = ((float)gasConsumTravelInput) * sGChelper_bar(currentDepth_m ) / 60.0;
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
713 }
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
714 else
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
715 {
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
716 if(outputSummary->timeToBottom == 0)
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
717 {
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
718 currentDepth_m = depth_meter;
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
719 outputSummary->timeToBottom = currentTime_sec / 60;
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
720 outputSummary->ppO2AtBottom = (sGChelper_bar(depth_meter) - WATER_VAPOUR_PRESSURE) * pDiveState->diveSettings.gas[currentConsumGasId].oxygen_percentage / 100.0f;
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
721 }
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
722 }
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
723 currentTime_sec++;
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
724 outputConsumptionTempFloat[currentConsumGasId] += currentGasConsumption;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
725 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
726
983
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
727 outputSummary->timeAtBottom = (currentTime_sec / 60); /* - outputSummary->timeToBottom; */
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
728
983
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
729 /* move forward to deco gas section (behind 255 entry) */
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
730 for(ChangeListIndex = 0; ChangeListIndex < GAS_CHANGE_LIST_ITEMS; ChangeListIndex++)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
731 {
983
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
732 if(pGasChangeList[ChangeListIndex].depth == 255)
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
733 {
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
734 ChangeListIndex++;
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
735 firstDecoGasIndex = ChangeListIndex;
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
736 nextGasChangeMeter = pGasChangeList[firstDecoGasIndex].depth;
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
737 nextGasChangeGasId = pGasChangeList[firstDecoGasIndex].gasId;
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
738 }
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
739 if((firstDecoGasIndex != 0) && (pGasChangeList[ChangeListIndex].depth > nextGasChangeMeter) /* find deepest gas switch */
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
740 && (pGasChangeList[ChangeListIndex].depth < currentDepth_m))
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
741 {
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
742 nextGasChangeMeter = pGasChangeList[ChangeListIndex].depth;
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
743 nextGasChangeGasId = pGasChangeList[ChangeListIndex].gasId;
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
744 }
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
745 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
746
983
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
747 /* do ascent with stops */
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
748 getNextDecoDepthAndTime(&nextDecoDepth, &nextDecoTime, currentDepth_m, decoInfoInput);
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
749 while(currentDepth_m > 0)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
750 {
983
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
751 if(currentDepth_m > nextDecoDepth)
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
752 {
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
753 currentDepth_m -= sim_ascent_rate_meter_per_sec_local;
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
754 currentGasConsumption = ((float)gasConsumDecoInput) * sGChelper_bar(currentDepth_m ) / 60.0;
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
755 }
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
756 else
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
757 {
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
758 if(outputSummary->timeToFirstStop == 0)
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
759 {
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
760 currentDepth_m = nextDecoDepth;
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
761 outputSummary->timeToFirstStop = currentTime_sec / 60;
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
762 outputSummary->depthMeterFirstStop = nextDecoDepth;
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
763 }
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
764 if(nextDecoTime)
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
765 {
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
766 nextDecoTime--;
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
767 }
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
768 else
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
769 {
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
770 getNextDecoDepthAndTime(&nextDecoDepth, &nextDecoTime, currentDepth_m, decoInfoInput);
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
771 }
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
772 }
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
773 if(currentDepth_m <= nextGasChangeMeter) /* switch gas ? */
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
774 {
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
775 nextGasChangeMeter = 0;
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
776 currentConsumGasId = nextGasChangeGasId;
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
777 for(ChangeListIndex = firstDecoGasIndex; ChangeListIndex < GAS_CHANGE_LIST_ITEMS; ChangeListIndex++)
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
778 {
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
779 if((pGasChangeList[ChangeListIndex].depth > nextGasChangeMeter) /* find deepest gas switch */
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
780 && (pGasChangeList[ChangeListIndex].depth < currentDepth_m))
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
781 {
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
782 nextGasChangeMeter = pGasChangeList[ChangeListIndex].depth;
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
783 nextGasChangeGasId = pGasChangeList[ChangeListIndex].gasId;
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
784 }
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
785 }
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
786 }
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
787 currentTime_sec++;
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
788 outputConsumptionTempFloat[currentConsumGasId] += currentGasConsumption;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
789 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
790
901
e4e9acfde839 Bugfix simulator/planer:
Ideenmodellierer
parents: 897
diff changeset
791 if(decoInfoInput->output_time_to_surface_seconds)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
792 {
901
e4e9acfde839 Bugfix simulator/planer:
Ideenmodellierer
parents: 897
diff changeset
793 outputSummary->timeToSurface = outputSummary->timeAtBottom + (decoInfoInput->output_time_to_surface_seconds / 60);
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
794 }
901
e4e9acfde839 Bugfix simulator/planer:
Ideenmodellierer
parents: 897
diff changeset
795 else
e4e9acfde839 Bugfix simulator/planer:
Ideenmodellierer
parents: 897
diff changeset
796 {
983
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
797 outputSummary->timeToSurface = currentTime_sec / 60;
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
798 }
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
799
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
800 for(ChangeListIndex = 0; ChangeListIndex < 6; ChangeListIndex++)
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
801 {
7891160acde3 Bugfix calculation of needed gas:
Ideenmodellierer
parents: 980
diff changeset
802 outputConsumptionList[ChangeListIndex] = (uint16_t)outputConsumptionTempFloat[ChangeListIndex];
901
e4e9acfde839 Bugfix simulator/planer:
Ideenmodellierer
parents: 897
diff changeset
803 }
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
804 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
805
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
806
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
807 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
808 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
809 * @brief Simulator control during simulated dive
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
810 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
811 * @note called by user via tHomeDiveMenuControl()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
812 * @param void
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
813 * @return void
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
814 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
815
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
816
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
817 void Sim_Descend (void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
818 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
819 stateSimGetPointerWrite()->lifeData.counterSecondsShallowDepth = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
820 if(simulation_get_aim_depth() < 200)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
821 simulation_set_aim_depth(simulation_get_aim_depth() + 1);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
822 }
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 void Sim_Ascend (void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
826 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
827 if(simulation_get_aim_depth() > 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
828 simulation_set_aim_depth(simulation_get_aim_depth() - 1);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
829 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
830
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
831
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
832 void Sim_Divetime (void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
833 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
834 simulation_add_time(5);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
835 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
836
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
837
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
838 void Sim_Quit (void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
839 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
840 if(stateSimGetPointer()->lifeData.counterSecondsShallowDepth)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
841 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
842 simulation_exit();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
843 return;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
844 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
845
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
846 if(simulation_get_aim_depth() > 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
847 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
848 simulation_set_aim_depth(0);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
849 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
850 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
851 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
852 stateSimGetPointerWrite()->lifeData.depth_meter = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
853 if(stateSimGetPointer()->diveSettings.diveMode == DIVEMODE_Apnea)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
854 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
855 stateSimGetPointerWrite()->lifeData.counterSecondsShallowDepth = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
856 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
857 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
858 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
859 stateSimGetPointerWrite()->lifeData.counterSecondsShallowDepth = settingsGetPointer()->timeoutDiveReachedZeroDepth - 15;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
860 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
861 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
862 }
760
21949c88da90 Quit simualted dives after the dive time set in the SIM tab.
heinrichsweikamp
parents: 748
diff changeset
863
629
55a9aa740f13 Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents: 548
diff changeset
864 void Sim_IncreasePPO(uint8_t sensorIdx)
55a9aa740f13 Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents: 548
diff changeset
865 {
55a9aa740f13 Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents: 548
diff changeset
866 if((sensorIdx < NUM_OF_SENSORS) && (simSensmVOffset[sensorIdx] + SIM_PPO2_STEP < 100.0) && ((stateUsed->diveSettings.ppo2sensors_deactivated & (1 << sensorIdx)) == 0))
55a9aa740f13 Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents: 548
diff changeset
867 {
55a9aa740f13 Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents: 548
diff changeset
868 simSensmVOffset[sensorIdx] += SIM_PPO2_STEP;
55a9aa740f13 Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents: 548
diff changeset
869 }
55a9aa740f13 Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents: 548
diff changeset
870 }
55a9aa740f13 Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents: 548
diff changeset
871 void Sim_DecreasePPO(uint8_t sensorIdx)
55a9aa740f13 Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents: 548
diff changeset
872 {
55a9aa740f13 Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents: 548
diff changeset
873 if((sensorIdx < NUM_OF_SENSORS) && (simSensmVOffset[sensorIdx] - SIM_PPO2_STEP >= -100.0))
55a9aa740f13 Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents: 548
diff changeset
874 {
55a9aa740f13 Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents: 548
diff changeset
875 simSensmVOffset[sensorIdx] -= SIM_PPO2_STEP;
55a9aa740f13 Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents: 548
diff changeset
876 }
55a9aa740f13 Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents: 548
diff changeset
877 }