Mercurial > public > ostc4
comparison Discovery/Src/timer.c @ 367:e309f78f89a5 MotionDetection
Merge default
author | Ideenmodellierer |
---|---|
date | Sat, 20 Jul 2019 21:42:45 +0200 |
parents | ddbe8bed5096 |
children | 2c49561c8062 |
comparison
equal
deleted
inserted
replaced
366:3c7030d6d67a | 367:e309f78f89a5 |
---|---|
26 /// along with this program. If not, see <http://www.gnu.org/licenses/>. | 26 /// along with this program. If not, see <http://www.gnu.org/licenses/>. |
27 ////////////////////////////////////////////////////////////////////////////// | 27 ////////////////////////////////////////////////////////////////////////////// |
28 | 28 |
29 #include "data_central.h" | 29 #include "data_central.h" |
30 | 30 |
31 static long stopWatchTime_Second = 0; | |
32 static _Bool bStopWatch = false; | 31 static _Bool bStopWatch = false; |
33 static float stopWatchAverageDepth_Meter = 0.0f; | 32 static float stopWatchAverageDepth_Meter = 0.0f; |
34 static long safetyStopCountDown_Second = 0; | 33 static long safetyStopCountDown_Second = 0; |
34 static long stopWatchOffset = 0; | |
35 | 35 |
36 void timer_init(void) | 36 void timer_init(void) |
37 { | 37 { |
38 stopWatchTime_Second = 0; | |
39 stopWatchAverageDepth_Meter = 0.0f; | 38 stopWatchAverageDepth_Meter = 0.0f; |
40 bStopWatch = true; | 39 bStopWatch = true; |
41 safetyStopCountDown_Second = 0; | 40 safetyStopCountDown_Second = 0; |
42 | 41 stopWatchOffset = 0; |
43 } | 42 } |
44 | 43 |
45 void timer_UpdateSecond(_Bool checkOncePerSecond) | 44 void timer_UpdateSecond(_Bool checkOncePerSecond) |
46 { | 45 { |
47 static int last_second = -1; | 46 static int last_second = -1; |
48 static _Bool bSafetyStop = false; | 47 static _Bool bSafetyStop = false; |
49 static float last_depth_meter = 0; | 48 static float last_depth_meter = 0; |
49 long stopWatchTime_Second = 0; | |
50 | 50 |
51 if(checkOncePerSecond) | 51 if(checkOncePerSecond) |
52 { | 52 { |
53 int now = current_second(); | 53 int now = current_second(); |
54 if( last_second == now) | 54 if( last_second == now) |
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 stopWatchTime_Second = stateUsed->lifeData.dive_time_seconds_without_surface_time - stopWatchOffset; |
61 if(bStopWatch && !is_ambient_pressure_close_to_surface(&stateUsedWrite->lifeData)) | |
61 { | 62 { |
62 if((stopWatchTime_Second == 0) && (stateUsed->lifeData.dive_time_seconds >= 1)) | 63 if(stopWatchTime_Second == 0) |
63 { | 64 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 | 65 else |
68 { | |
69 stopWatchAverageDepth_Meter = (stopWatchAverageDepth_Meter * stopWatchTime_Second + stateUsed->lifeData.depth_meter)/ (stopWatchTime_Second + 1); | 66 stopWatchAverageDepth_Meter = (stopWatchAverageDepth_Meter * stopWatchTime_Second + stateUsed->lifeData.depth_meter)/ (stopWatchTime_Second + 1); |
70 stopWatchTime_Second++; | |
71 } | |
72 } | 67 } |
73 | 68 |
74 /** SafetyStop **/ | 69 /** SafetyStop **/ |
75 float depthToStopSafetyStopCount; | 70 float depthToStopSafetyStopCount; |
76 if(settingsGetPointer()->safetystopDuration && (stateUsed->lifeData.max_depth_meter > 10.0f) && (stateUsed->lifeData.dive_time_seconds > 60)) | 71 if(settingsGetPointer()->safetystopDuration && (stateUsed->lifeData.max_depth_meter > 10.0f) && (stateUsed->lifeData.dive_time_seconds > 60)) |
123 } | 118 } |
124 | 119 |
125 | 120 |
126 void timer_Stopwatch_Restart(void) | 121 void timer_Stopwatch_Restart(void) |
127 { | 122 { |
128 stopWatchTime_Second = 1; | |
129 stopWatchAverageDepth_Meter = stateUsed->lifeData.depth_meter; | 123 stopWatchAverageDepth_Meter = stateUsed->lifeData.depth_meter; |
130 bStopWatch = true; | 124 bStopWatch = true; |
125 stopWatchOffset = stateUsed->lifeData.dive_time_seconds_without_surface_time; | |
131 } | 126 } |
132 | 127 |
133 void timer_Stopwatch_Stop(void) | 128 void timer_Stopwatch_Stop(void) |
134 { | 129 { |
135 bStopWatch = false; | 130 bStopWatch = false; |
136 } | 131 } |
137 | 132 |
138 long timer_Stopwatch_GetTime(void) | 133 long timer_Stopwatch_GetTime(void) |
139 { | 134 { |
140 return stopWatchTime_Second; | 135 return stateUsed->lifeData.dive_time_seconds_without_surface_time - stopWatchOffset; |
141 } | 136 } |
142 | 137 |
143 float timer_Stopwatch_GetAvarageDepth_Meter(void) | 138 float timer_Stopwatch_GetAvarageDepth_Meter(void) |
144 { | 139 { |
145 return stopWatchAverageDepth_Meter; | 140 return stopWatchAverageDepth_Meter; |