comparison 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
comparison
equal deleted inserted replaced
302:eba8d1eb5bef 303:90e65971f15d
55 return; 55 return;
56 last_second = now; 56 last_second = now;
57 } 57 }
58 58
59 /** Stopwatch **/ 59 /** Stopwatch **/
60 if(bStopWatch && stateUsed->lifeData.depth_meter > 1) 60 if(bStopWatch && !is_ambient_pressure_close_to_surface(&stateUsedWrite->lifeData))
61 { 61 {
62 if((stopWatchTime_Second == 0) && (stateUsed->lifeData.dive_time_seconds >= 1)) 62 if(stopWatchTime_Second == 0)
63 { 63 stopWatchAverageDepth_Meter = stateUsed->lifeData.depth_meter;
64 stopWatchTime_Second = stateUsed->lifeData.dive_time_seconds - 1;
65 stopWatchAverageDepth_Meter = stateUsed->lifeData.average_depth_meter * (stopWatchTime_Second - 1) / stopWatchTime_Second;
66 }
67 else 64 else
68 {
69 stopWatchAverageDepth_Meter = (stopWatchAverageDepth_Meter * stopWatchTime_Second + stateUsed->lifeData.depth_meter)/ (stopWatchTime_Second + 1); 65 stopWatchAverageDepth_Meter = (stopWatchAverageDepth_Meter * stopWatchTime_Second + stateUsed->lifeData.depth_meter)/ (stopWatchTime_Second + 1);
70 stopWatchTime_Second++; 66
71 } 67 stopWatchTime_Second++;
72 } 68 }
73 69
74 /** SafetyStop **/ 70 /** SafetyStop **/
75 float depthToStopSafetyStopCount; 71 float depthToStopSafetyStopCount;
76 if(settingsGetPointer()->safetystopDuration && (stateUsed->lifeData.max_depth_meter > 10.0f) && (stateUsed->lifeData.dive_time_seconds > 60)) 72 if(settingsGetPointer()->safetystopDuration && (stateUsed->lifeData.max_depth_meter > 10.0f) && (stateUsed->lifeData.dive_time_seconds > 60))
123 } 119 }
124 120
125 121
126 void timer_Stopwatch_Restart(void) 122 void timer_Stopwatch_Restart(void)
127 { 123 {
128 stopWatchTime_Second = 1; 124 stopWatchTime_Second = 0;
129 stopWatchAverageDepth_Meter = stateUsed->lifeData.depth_meter; 125 stopWatchAverageDepth_Meter = stateUsed->lifeData.depth_meter;
130 bStopWatch = true; 126 bStopWatch = true;
131 } 127 }
132 128
133 void timer_Stopwatch_Stop(void) 129 void timer_Stopwatch_Stop(void)