diff Discovery/Src/timer.c @ 303:90e65971f15d cleanup-4

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>
author Jan Mulder <jlmulder@xs4all.nl>
date Mon, 20 May 2019 12:57:31 +0200
parents f11f0bf6ef2d
children ddbe8bed5096
line wrap: on
line diff
--- 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;
 }