Mercurial > public > ostc4
changeset 311:ddbe8bed5096 cleanup-4
bugfix: make stopwatch and divetime run in sync
And this shows the fundamental issue in the difference between dive time and
stopwatch time. The dive time is constructed on the RTE, and rather
independently, the stopwatch time is constructed on CPU1.
This works rather well, but not perfect. This commit fixes things in
a relatively straightforward way. Instead of incrementing the stopwatch
locally on CPU1, simply use the same time data that is coming from the
RTE. Some logic was added to make this stopwatch resettable again.
Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
author | Jan Mulder <jlmulder@xs4all.nl> |
---|---|
date | Wed, 29 May 2019 14:02:27 +0200 (2019-05-29) |
parents | 95928ef3986f |
children | e84a2486933e |
files | Discovery/Src/timer.c |
diffstat | 1 files changed, 6 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/Discovery/Src/timer.c Sun May 26 10:09:22 2019 +0200 +++ b/Discovery/Src/timer.c Wed May 29 14:02:27 2019 +0200 @@ -28,18 +28,17 @@ #include "data_central.h" -static long stopWatchTime_Second = 0; static _Bool bStopWatch = false; static float stopWatchAverageDepth_Meter = 0.0f; static long safetyStopCountDown_Second = 0; +static long stopWatchOffset = 0; void timer_init(void) { - stopWatchTime_Second = 0; stopWatchAverageDepth_Meter = 0.0f; bStopWatch = true; safetyStopCountDown_Second = 0; - + stopWatchOffset = 0; } void timer_UpdateSecond(_Bool checkOncePerSecond) @@ -47,6 +46,7 @@ static int last_second = -1; static _Bool bSafetyStop = false; static float last_depth_meter = 0; + long stopWatchTime_Second = 0; if(checkOncePerSecond) { @@ -57,14 +57,13 @@ } /** Stopwatch **/ + stopWatchTime_Second = stateUsed->lifeData.dive_time_seconds_without_surface_time - stopWatchOffset; if(bStopWatch && !is_ambient_pressure_close_to_surface(&stateUsedWrite->lifeData)) { 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++; } /** SafetyStop **/ @@ -121,9 +120,9 @@ void timer_Stopwatch_Restart(void) { - stopWatchTime_Second = 0; stopWatchAverageDepth_Meter = stateUsed->lifeData.depth_meter; bStopWatch = true; + stopWatchOffset = stateUsed->lifeData.dive_time_seconds_without_surface_time; } void timer_Stopwatch_Stop(void) @@ -133,7 +132,7 @@ long timer_Stopwatch_GetTime(void) { - return stopWatchTime_Second; + return stateUsed->lifeData.dive_time_seconds_without_surface_time - stopWatchOffset; } float timer_Stopwatch_GetAvarageDepth_Meter(void)