comparison Discovery/Src/timer.c @ 519:2c49561c8062

Reset Safety Stop display in case of a new descend: In previous version safety stop was displayed in while the stop depth was reached. The count down was interrupted in case of a new descend but the safety stop was still displayed, blocking the NDL visualization in the big font view. To avoid this scenario a restart function has been added which will return to NDL view in case of a descend > 2m. If just a short drop happend then the countdown will be continued when the safety stop depth is reached again. If that takes more then a minute the safety stop counter is restarted.
author Ideenmodellierer
date Sun, 06 Sep 2020 22:11:51 +0200
parents ddbe8bed5096
children aa6006975e76
comparison
equal deleted inserted replaced
518:0a09afac969f 519:2c49561c8062
44 void timer_UpdateSecond(_Bool checkOncePerSecond) 44 void timer_UpdateSecond(_Bool checkOncePerSecond)
45 { 45 {
46 static int last_second = -1; 46 static int last_second = -1;
47 static _Bool bSafetyStop = false; 47 static _Bool bSafetyStop = false;
48 static float last_depth_meter = 0; 48 static float last_depth_meter = 0;
49 static uint8_t safetyStopResetCnt = 0;
50 static uint16_t safetyStopRestartCnt = 0;
49 long stopWatchTime_Second = 0; 51 long stopWatchTime_Second = 0;
50 52
51 if(checkOncePerSecond) 53 if(checkOncePerSecond)
52 { 54 {
53 int now = current_second(); 55 int now = current_second();
84 if(stateUsed->decolistVPM.output_ndl_seconds > 0) 86 if(stateUsed->decolistVPM.output_ndl_seconds > 0)
85 bSafetyStop = true; 87 bSafetyStop = true;
86 } 88 }
87 } 89 }
88 90
91 /* Has the diver left safety stop depth (descend)? => need to restart safety stop timer? */
92 if(safetyStopCountDown_Second != 0)
93 {
94 if(stateUsed->lifeData.depth_meter >= (settingsGetPointer()->safetystopDepth + 2.0))
95 {
96 safetyStopRestartCnt = safetyStopCountDown_Second;
97 safetyStopCountDown_Second = 0;
98 safetyStopResetCnt = 60; /* restart safety stop from scratch if depth is left for more than one minute */
99 }
100 }
101 else if(safetyStopResetCnt)
102 {
103 safetyStopResetCnt--;
104 if(safetyStopResetCnt == 0)
105 {
106 safetyStopRestartCnt = 0;
107 }
108 }
109
89 //Countdown starts at 5 meters 110 //Countdown starts at 5 meters
90 if(bSafetyStop && (stateUsed->lifeData.depth_meter - 0.0001f <= (settingsGetPointer()->safetystopDepth) )) 111 if(bSafetyStop && (stateUsed->lifeData.depth_meter - 0.0001f <= (settingsGetPointer()->safetystopDepth) ))
91 { 112 {
92 if(safetyStopCountDown_Second == 0) 113 if(safetyStopCountDown_Second == 0)
93 { 114 {
94 safetyStopCountDown_Second = (settingsGetPointer()->safetystopDuration) * 60; 115 if(safetyStopRestartCnt) /* just a short interrupt of the safetystop => continue using old count */
116 {
117 safetyStopCountDown_Second = safetyStopRestartCnt;
118 safetyStopRestartCnt = 0;
119 }
120 else /* setup safety stop duration */
121 {
122 safetyStopCountDown_Second = (settingsGetPointer()->safetystopDuration) * 60;
123 }
95 } 124 }
96 else 125 else
126 {
97 safetyStopCountDown_Second--; 127 safetyStopCountDown_Second--;
128 }
98 } 129 }
99 130
100 // after safetystopDuration minutes or below 3 (2) meter safetyStop is disabled 131 // after safetystopDuration minutes or below 3 (2) meter safetyStop is disabled
101 if(settingsGetPointer()->safetystopDepth == 3) 132 if(settingsGetPointer()->safetystopDepth == 3)
102 depthToStopSafetyStopCount = 1.999f; // instead of 2 133 depthToStopSafetyStopCount = 1.999f; // instead of 2