# HG changeset patch
# User Jan Mulder <jlmulder@xs4all.nl>
# Date 1558350362 -7200
# Node ID 43b44f8d4fb0bd69b571922b42a538bf1b42c717
# Parent  90e65971f15d2481cda3482ff510946eab6a3134
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>

diff -r 90e65971f15d -r 43b44f8d4fb0 Discovery/Src/simulation.c
--- a/Discovery/Src/simulation.c	Mon May 20 12:57:31 2019 +0200
+++ b/Discovery/Src/simulation.c	Mon May 20 13:06:02 2019 +0200
@@ -159,11 +159,6 @@
     pDiveState->lifeData.dive_time_seconds += 1;
     pDiveState->lifeData.pressure_ambient_bar = sim_get_ambient_pressure(pDiveState);
 
-    if(!is_ambient_pressure_close_to_surface(&pDiveState->lifeData) && !(stateSimGetPointer()->lifeData.counterSecondsShallowDepth) )
-    {
-        pDiveState->lifeData.dive_time_seconds_without_surface_time += 1;
-    }
-
     if(is_ambient_pressure_close_to_surface(&pDiveState->lifeData)) // new hw 170214
     {
         if(!(stateSimGetPointer()->lifeData.counterSecondsShallowDepth))
@@ -185,6 +180,11 @@
         pDiveState->lifeData.counterSecondsShallowDepth = 0;
     }
 
+    if(!is_ambient_pressure_close_to_surface(&pDiveState->lifeData) && !(stateSimGetPointer()->lifeData.counterSecondsShallowDepth) )
+    {
+    	pDiveState->lifeData.dive_time_seconds_without_surface_time += 1;
+    }
+
     pDiveState->lifeData.depth_meter = (pDiveState->lifeData.pressure_ambient_bar - pDiveState->lifeData.pressure_surface_bar) * 10.0f;
     if(pDiveState->lifeData.max_depth_meter < pDiveState->lifeData.depth_meter)
             pDiveState->lifeData.max_depth_meter = pDiveState->lifeData.depth_meter;