Mercurial > public > ostc4
annotate Discovery/Src/timer.c @ 307:b6436edfb2c0 cleanup-4
cleanup: factor out unused stopwatch code
Visually, this looks a bit of a dangerous cleanup, but its not :-)
To explain this cleanup: stopwatch_seconds is never used, so assign
to it is useless, and the variable can be removed. Now,
stopwatch_start_at_this_dive_time_seconds is not used any more, so
remove it as well. Now, look at the boolResetStopwatch code. It
is used but only to reset itself. This makes the whole stopwatch
block in data_exchange_main.c a useless thing. All the other
cleanup is trivial.
Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
author | Jan Mulder <jlmulder@xs4all.nl> |
---|---|
date | Wed, 22 May 2019 22:22:15 +0200 |
parents | 90e65971f15d |
children | ddbe8bed5096 |
rev | line source |
---|---|
38 | 1 /////////////////////////////////////////////////////////////////////////////// |
2 /// -*- coding: UTF-8 -*- | |
3 /// | |
4 /// \file Discovery/Src/timer.c | |
5 /// \brief Contains timer related functionality like stopwatch and security stop | |
6 /// \author Peter Ryser & heinrichs weikamp gmbh | |
7 /// \date 5. Feb.2015 (maybe) | |
8 /// | |
9 /// \details | |
10 /// | |
11 /// $Id$ | |
12 /////////////////////////////////////////////////////////////////////////////// | |
13 /// \par Copyright (c) 2014-2018 Heinrichs Weikamp gmbh | |
14 /// | |
15 /// This program is free software: you can redistribute it and/or modify | |
16 /// it under the terms of the GNU General Public License as published by | |
17 /// the Free Software Foundation, either version 3 of the License, or | |
18 /// (at your option) any later version. | |
19 /// | |
20 /// This program is distributed in the hope that it will be useful, | |
21 /// but WITHOUT ANY WARRANTY; without even the implied warranty of | |
22 /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
23 /// GNU General Public License for more details. | |
24 /// | |
25 /// You should have received a copy of the GNU General Public License | |
26 /// along with this program. If not, see <http://www.gnu.org/licenses/>. | |
27 ////////////////////////////////////////////////////////////////////////////// | |
28 | |
29 #include "data_central.h" | |
30 | |
186
f11f0bf6ef2d
cleanup: remove obsolete code, make static, etc.
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
31 static long stopWatchTime_Second = 0; |
f11f0bf6ef2d
cleanup: remove obsolete code, make static, etc.
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
32 static _Bool bStopWatch = false; |
f11f0bf6ef2d
cleanup: remove obsolete code, make static, etc.
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
33 static float stopWatchAverageDepth_Meter = 0.0f; |
f11f0bf6ef2d
cleanup: remove obsolete code, make static, etc.
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
34 static long safetyStopCountDown_Second = 0; |
38 | 35 |
36 void timer_init(void) | |
37 { | |
38 stopWatchTime_Second = 0; | |
39 stopWatchAverageDepth_Meter = 0.0f; | |
40 bStopWatch = true; | |
41 safetyStopCountDown_Second = 0; | |
42 | |
43 } | |
44 | |
45 void timer_UpdateSecond(_Bool checkOncePerSecond) | |
46 { | |
47 static int last_second = -1; | |
48 static _Bool bSafetyStop = false; | |
49 static float last_depth_meter = 0; | |
186
f11f0bf6ef2d
cleanup: remove obsolete code, make static, etc.
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
50 |
38 | 51 if(checkOncePerSecond) |
52 { | |
53 int now = current_second(); | |
54 if( last_second == now) | |
55 return; | |
56 last_second = now; | |
57 } | |
58 | |
59 /** Stopwatch **/ | |
303
90e65971f15d
bugfix, cleanup: simplify stopwatch logic and fix fallout
Jan Mulder <jlmulder@xs4all.nl>
parents:
186
diff
changeset
|
60 if(bStopWatch && !is_ambient_pressure_close_to_surface(&stateUsedWrite->lifeData)) |
38 | 61 { |
303
90e65971f15d
bugfix, cleanup: simplify stopwatch logic and fix fallout
Jan Mulder <jlmulder@xs4all.nl>
parents:
186
diff
changeset
|
62 if(stopWatchTime_Second == 0) |
90e65971f15d
bugfix, cleanup: simplify stopwatch logic and fix fallout
Jan Mulder <jlmulder@xs4all.nl>
parents:
186
diff
changeset
|
63 stopWatchAverageDepth_Meter = stateUsed->lifeData.depth_meter; |
38 | 64 else |
65 stopWatchAverageDepth_Meter = (stopWatchAverageDepth_Meter * stopWatchTime_Second + stateUsed->lifeData.depth_meter)/ (stopWatchTime_Second + 1); | |
303
90e65971f15d
bugfix, cleanup: simplify stopwatch logic and fix fallout
Jan Mulder <jlmulder@xs4all.nl>
parents:
186
diff
changeset
|
66 |
90e65971f15d
bugfix, cleanup: simplify stopwatch logic and fix fallout
Jan Mulder <jlmulder@xs4all.nl>
parents:
186
diff
changeset
|
67 stopWatchTime_Second++; |
38 | 68 } |
69 | |
70 /** SafetyStop **/ | |
71 float depthToStopSafetyStopCount; | |
72 if(settingsGetPointer()->safetystopDuration && (stateUsed->lifeData.max_depth_meter > 10.0f) && (stateUsed->lifeData.dive_time_seconds > 60)) | |
73 { | |
74 | |
75 //No deco when 10 meters are crossed from below => Activate SecurityStop | |
76 if( last_depth_meter > 10.0f && stateUsed->lifeData.depth_meter <= 10.0f) | |
77 { | |
78 if(stateUsed->diveSettings.deco_type.ub.standard == GF_MODE) | |
79 { | |
80 if(stateUsed->decolistBuehlmann.output_ndl_seconds > 0) | |
81 bSafetyStop = true; | |
82 } | |
83 else | |
84 { | |
85 if(stateUsed->decolistVPM.output_ndl_seconds > 0) | |
86 bSafetyStop = true; | |
87 } | |
88 } | |
89 | |
90 //Countdown starts at 5 meters | |
91 if(bSafetyStop && (stateUsed->lifeData.depth_meter - 0.0001f <= (settingsGetPointer()->safetystopDepth) )) | |
92 { | |
93 if(safetyStopCountDown_Second == 0) | |
94 { | |
95 safetyStopCountDown_Second = (settingsGetPointer()->safetystopDuration) * 60; | |
96 } | |
97 else | |
98 safetyStopCountDown_Second--; | |
99 } | |
100 | |
101 // after safetystopDuration minutes or below 3 (2) meter safetyStop is disabled | |
102 if(settingsGetPointer()->safetystopDepth == 3) | |
103 depthToStopSafetyStopCount = 1.999f; // instead of 2 | |
104 else | |
105 depthToStopSafetyStopCount = 2.999f;// instead of 3 | |
106 | |
107 if((safetyStopCountDown_Second == 1) || (stateUsed->lifeData.depth_meter <= depthToStopSafetyStopCount)) | |
108 { | |
109 bSafetyStop = false; | |
110 safetyStopCountDown_Second = 0; | |
111 } | |
112 } | |
113 else | |
114 { | |
115 bSafetyStop = false; | |
116 safetyStopCountDown_Second = 0; | |
117 } | |
118 last_depth_meter = stateUsed->lifeData.depth_meter; | |
119 } | |
120 | |
121 | |
122 void timer_Stopwatch_Restart(void) | |
123 { | |
303
90e65971f15d
bugfix, cleanup: simplify stopwatch logic and fix fallout
Jan Mulder <jlmulder@xs4all.nl>
parents:
186
diff
changeset
|
124 stopWatchTime_Second = 0; |
38 | 125 stopWatchAverageDepth_Meter = stateUsed->lifeData.depth_meter; |
126 bStopWatch = true; | |
127 } | |
128 | |
129 void timer_Stopwatch_Stop(void) | |
130 { | |
131 bStopWatch = false; | |
132 } | |
133 | |
134 long timer_Stopwatch_GetTime(void) | |
135 { | |
136 return stopWatchTime_Second; | |
137 } | |
138 | |
139 float timer_Stopwatch_GetAvarageDepth_Meter(void) | |
140 { | |
141 return stopWatchAverageDepth_Meter; | |
142 } | |
143 | |
144 long timer_Safetystop_GetCountDown(void) | |
145 { | |
146 return safetyStopCountDown_Second; | |
147 } | |
148 | |
149 uint8_t timer_Safetystop_GetDepthUpperLimit(void) | |
150 { | |
151 if(settingsGetPointer()->safetystopDepth == 3) | |
152 return 2; | |
153 else | |
154 return 3; | |
155 } | |
156 |