# HG changeset patch
# User Jan Mulder <jlmulder@xs4all.nl>
# Date 1558349851 -7200
# Node ID 90e65971f15d2481cda3482ff510946eab6a3134
# Parent  eba8d1eb5bef95bd1de0abd47e646c886a86c54b
bugfix, cleanup: simplify stopwatch logic and fix fallout

The previous 2 commits (making the depth switch between surface
and diving consistent) increased the time difference (in the
simulator) to about 4 seconds. This commit fixes this again, and
we are back at 1 sec. difference between the 2 timers (notice:
in the simulator). Still not the wanted 0 sec. difference, but
the old stopwatch logic logic was rather convoluted. Resetting to
1 second (instead of 0), and second-1 logic. Basically, this feels
like a bug fixed with a second bug on top to mask it. The code
is now much more logic and consistent (despite the fact that the
real reason for the 1 sec. difference is not yet found).

Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>

diff -r eba8d1eb5bef -r 90e65971f15d Discovery/Src/timer.c
--- a/Discovery/Src/timer.c	Mon May 20 10:13:44 2019 +0200
+++ b/Discovery/Src/timer.c	Mon May 20 12:57:31 2019 +0200
@@ -57,18 +57,14 @@
     }
 
     /** Stopwatch **/
-    if(bStopWatch && stateUsed->lifeData.depth_meter > 1)
+    if(bStopWatch && !is_ambient_pressure_close_to_surface(&stateUsedWrite->lifeData))
     {
-        if((stopWatchTime_Second == 0) && (stateUsed->lifeData.dive_time_seconds >= 1))
-        {
-            stopWatchTime_Second = stateUsed->lifeData.dive_time_seconds - 1;
-            stopWatchAverageDepth_Meter = stateUsed->lifeData.average_depth_meter * (stopWatchTime_Second - 1) / stopWatchTime_Second;
-        }
+        if(stopWatchTime_Second == 0)
+            stopWatchAverageDepth_Meter = stateUsed->lifeData.depth_meter;
         else
-        {
             stopWatchAverageDepth_Meter = (stopWatchAverageDepth_Meter * stopWatchTime_Second + stateUsed->lifeData.depth_meter)/ (stopWatchTime_Second + 1);
-            stopWatchTime_Second++;
-        }
+
+        stopWatchTime_Second++;
     }
 
     /** SafetyStop **/
@@ -125,7 +121,7 @@
 
 void timer_Stopwatch_Restart(void)
 {
-  stopWatchTime_Second = 1;
+  stopWatchTime_Second = 0;
   stopWatchAverageDepth_Meter = stateUsed->lifeData.depth_meter;
   bStopWatch = true;
 }