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
+ − 31 static _Bool bStopWatch = false;
+ − 32 static float stopWatchAverageDepth_Meter = 0.0f;
+ − 33 static long safetyStopCountDown_Second = 0;
311
+ − 34 static long stopWatchOffset = 0;
38
+ − 35
+ − 36 void timer_init(void)
+ − 37 {
+ − 38 stopWatchAverageDepth_Meter = 0.0f;
+ − 39 bStopWatch = true;
+ − 40 safetyStopCountDown_Second = 0;
311
+ − 41 stopWatchOffset = 0;
38
+ − 42 }
+ − 43
+ − 44 void timer_UpdateSecond(_Bool checkOncePerSecond)
+ − 45 {
+ − 46 static int last_second = -1;
+ − 47 static _Bool bSafetyStop = false;
+ − 48 static float last_depth_meter = 0;
311
+ − 49 long stopWatchTime_Second = 0;
186
+ − 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 **/
311
+ − 60 stopWatchTime_Second = stateUsed->lifeData.dive_time_seconds_without_surface_time - stopWatchOffset;
303
+ − 61 if(bStopWatch && !is_ambient_pressure_close_to_surface(&stateUsedWrite->lifeData))
38
+ − 62 {
303
+ − 63 if(stopWatchTime_Second == 0)
+ − 64 stopWatchAverageDepth_Meter = stateUsed->lifeData.depth_meter;
38
+ − 65 else
+ − 66 stopWatchAverageDepth_Meter = (stopWatchAverageDepth_Meter * stopWatchTime_Second + stateUsed->lifeData.depth_meter)/ (stopWatchTime_Second + 1);
+ − 67 }
+ − 68
+ − 69 /** SafetyStop **/
+ − 70 float depthToStopSafetyStopCount;
+ − 71 if(settingsGetPointer()->safetystopDuration && (stateUsed->lifeData.max_depth_meter > 10.0f) && (stateUsed->lifeData.dive_time_seconds > 60))
+ − 72 {
+ − 73
+ − 74 //No deco when 10 meters are crossed from below => Activate SecurityStop
+ − 75 if( last_depth_meter > 10.0f && stateUsed->lifeData.depth_meter <= 10.0f)
+ − 76 {
+ − 77 if(stateUsed->diveSettings.deco_type.ub.standard == GF_MODE)
+ − 78 {
+ − 79 if(stateUsed->decolistBuehlmann.output_ndl_seconds > 0)
+ − 80 bSafetyStop = true;
+ − 81 }
+ − 82 else
+ − 83 {
+ − 84 if(stateUsed->decolistVPM.output_ndl_seconds > 0)
+ − 85 bSafetyStop = true;
+ − 86 }
+ − 87 }
+ − 88
+ − 89 //Countdown starts at 5 meters
+ − 90 if(bSafetyStop && (stateUsed->lifeData.depth_meter - 0.0001f <= (settingsGetPointer()->safetystopDepth) ))
+ − 91 {
+ − 92 if(safetyStopCountDown_Second == 0)
+ − 93 {
+ − 94 safetyStopCountDown_Second = (settingsGetPointer()->safetystopDuration) * 60;
+ − 95 }
+ − 96 else
+ − 97 safetyStopCountDown_Second--;
+ − 98 }
+ − 99
+ − 100 // after safetystopDuration minutes or below 3 (2) meter safetyStop is disabled
+ − 101 if(settingsGetPointer()->safetystopDepth == 3)
+ − 102 depthToStopSafetyStopCount = 1.999f; // instead of 2
+ − 103 else
+ − 104 depthToStopSafetyStopCount = 2.999f;// instead of 3
+ − 105
+ − 106 if((safetyStopCountDown_Second == 1) || (stateUsed->lifeData.depth_meter <= depthToStopSafetyStopCount))
+ − 107 {
+ − 108 bSafetyStop = false;
+ − 109 safetyStopCountDown_Second = 0;
+ − 110 }
+ − 111 }
+ − 112 else
+ − 113 {
+ − 114 bSafetyStop = false;
+ − 115 safetyStopCountDown_Second = 0;
+ − 116 }
+ − 117 last_depth_meter = stateUsed->lifeData.depth_meter;
+ − 118 }
+ − 119
+ − 120
+ − 121 void timer_Stopwatch_Restart(void)
+ − 122 {
+ − 123 stopWatchAverageDepth_Meter = stateUsed->lifeData.depth_meter;
+ − 124 bStopWatch = true;
311
+ − 125 stopWatchOffset = stateUsed->lifeData.dive_time_seconds_without_surface_time;
38
+ − 126 }
+ − 127
+ − 128 void timer_Stopwatch_Stop(void)
+ − 129 {
+ − 130 bStopWatch = false;
+ − 131 }
+ − 132
+ − 133 long timer_Stopwatch_GetTime(void)
+ − 134 {
311
+ − 135 return stateUsed->lifeData.dive_time_seconds_without_surface_time - stopWatchOffset;
38
+ − 136 }
+ − 137
+ − 138 float timer_Stopwatch_GetAvarageDepth_Meter(void)
+ − 139 {
+ − 140 return stopWatchAverageDepth_Meter;
+ − 141 }
+ − 142
+ − 143 long timer_Safetystop_GetCountDown(void)
+ − 144 {
+ − 145 return safetyStopCountDown_Second;
+ − 146 }
+ − 147
+ − 148 uint8_t timer_Safetystop_GetDepthUpperLimit(void)
+ − 149 {
+ − 150 if(settingsGetPointer()->safetystopDepth == 3)
+ − 151 return 2;
+ − 152 else
+ − 153 return 3;
+ − 154 }
+ − 155