comparison Discovery/Src/simulation.c @ 304:43b44f8d4fb0 cleanup-4

bugfix, simulator: fix the 1 sec difference between stopwatch and divetime This is a rather subtle bugfix. counterSecondsShallowDepth is used to decide to increase dive_time_seconds_without_surface_time. But just after using it, logic is present to reset counterSecondsShallowDepth. So, basically, we are looking to an old state. Simply increase dive_time_seconds_without_surface_time *after* we have reset counterSecondsShallowDepth, so that we are looking to a current state instead of an old one. Notice that this is simulator only. Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
author Jan Mulder <jlmulder@xs4all.nl>
date Mon, 20 May 2019 13:06:02 +0200
parents 5ca177d2df5d
children b6436edfb2c0
comparison
equal deleted inserted replaced
303:90e65971f15d 304:43b44f8d4fb0
157 pDiveState->lifeData.sensorVoltage_mV[2] = stateRealGetPointer()->lifeData.sensorVoltage_mV[2]; 157 pDiveState->lifeData.sensorVoltage_mV[2] = stateRealGetPointer()->lifeData.sensorVoltage_mV[2];
158 158
159 pDiveState->lifeData.dive_time_seconds += 1; 159 pDiveState->lifeData.dive_time_seconds += 1;
160 pDiveState->lifeData.pressure_ambient_bar = sim_get_ambient_pressure(pDiveState); 160 pDiveState->lifeData.pressure_ambient_bar = sim_get_ambient_pressure(pDiveState);
161 161
162 if(!is_ambient_pressure_close_to_surface(&pDiveState->lifeData) && !(stateSimGetPointer()->lifeData.counterSecondsShallowDepth) )
163 {
164 pDiveState->lifeData.dive_time_seconds_without_surface_time += 1;
165 }
166
167 if(is_ambient_pressure_close_to_surface(&pDiveState->lifeData)) // new hw 170214 162 if(is_ambient_pressure_close_to_surface(&pDiveState->lifeData)) // new hw 170214
168 { 163 {
169 if(!(stateSimGetPointer()->lifeData.counterSecondsShallowDepth)) 164 if(!(stateSimGetPointer()->lifeData.counterSecondsShallowDepth))
170 { 165 {
171 if(pDiveState->diveSettings.diveMode != DIVEMODE_Apnea) 166 if(pDiveState->diveSettings.diveMode != DIVEMODE_Apnea)
181 } 176 }
182 } 177 }
183 else 178 else
184 { 179 {
185 pDiveState->lifeData.counterSecondsShallowDepth = 0; 180 pDiveState->lifeData.counterSecondsShallowDepth = 0;
181 }
182
183 if(!is_ambient_pressure_close_to_surface(&pDiveState->lifeData) && !(stateSimGetPointer()->lifeData.counterSecondsShallowDepth) )
184 {
185 pDiveState->lifeData.dive_time_seconds_without_surface_time += 1;
186 } 186 }
187 187
188 pDiveState->lifeData.depth_meter = (pDiveState->lifeData.pressure_ambient_bar - pDiveState->lifeData.pressure_surface_bar) * 10.0f; 188 pDiveState->lifeData.depth_meter = (pDiveState->lifeData.pressure_ambient_bar - pDiveState->lifeData.pressure_surface_bar) * 10.0f;
189 if(pDiveState->lifeData.max_depth_meter < pDiveState->lifeData.depth_meter) 189 if(pDiveState->lifeData.max_depth_meter < pDiveState->lifeData.depth_meter)
190 pDiveState->lifeData.max_depth_meter = pDiveState->lifeData.depth_meter; 190 pDiveState->lifeData.max_depth_meter = pDiveState->lifeData.depth_meter;