# HG changeset patch
# User Ideenmodellierer
# Date 1619376176 -7200
# Node ID 980b4aa60a0eba5ee7a5522b527e834c06474681
# Parent  890440ab993a012906d9bc6f138a7c9ddc7dd445
Added count down timer for scrubber time:
The countdown is performed in case CCR mode and scrubber timer are active

diff -r 890440ab993a -r 980b4aa60a0e Discovery/Src/tCCR.c
--- a/Discovery/Src/tCCR.c	Sun Apr 25 20:41:19 2021 +0200
+++ b/Discovery/Src/tCCR.c	Sun Apr 25 20:42:56 2021 +0200
@@ -75,6 +75,7 @@
 
 static uint8_t StartListeningToUART_HUD = 0;
 static uint16_t HUDTimeoutCount = 0;
+static uint16_t ScrubberTimeoutCount = 0;
 
 static __IO ITStatus UartReadyHUD = RESET;
 static uint32_t LastReceivedTick_HUD = 0;
@@ -312,7 +313,9 @@
     */
 void tCCR_tick(void)
 {
-	if(settingsGetPointer()->ppo2sensors_source == O2_SENSOR_SOURCE_OPTIC)
+	SSettings* pSettings = settingsGetPointer();
+
+	if(pSettings->ppo2sensors_source == O2_SENSOR_SOURCE_OPTIC)
 	{
 		if(HUDTimeoutCount < 3 * 10)
 			HUDTimeoutCount++;
@@ -325,6 +328,20 @@
 				tCCR_fallbackToFixedSetpoint();
 		}
 	}
+
+	/* decrease scrubber timer only in real dive mode */
+    if((pSettings->scrubTimerMode != SCRUB_TIMER_OFF) && (pSettings->dive_mode == DIVEMODE_CCR) && (stateUsed->mode == MODE_DIVE) && (stateUsed == stateRealGetPointer()))
+    {
+    	ScrubberTimeoutCount++;
+    	if(ScrubberTimeoutCount >= 600)		/* resolution is minutes */
+    	{
+    		ScrubberTimeoutCount = 0;
+    		if(pSettings->scrubTimerCur > 0)
+    		{
+    			pSettings->scrubTimerCur--;
+    		}
+    	}
+    }
 }
 
 void tCCR_SetRXIndication(void)