diff Discovery/Src/t3.c @ 838:aed39d19269c Evo_2_23

Added T3 autofocus for Gas list: An automatic switch to the gaslist will now happen in case a better gas is available or in case the current gas is not breathable (ppo2 HIGH/LOW). From the gaslist view a new gas may be selected view quickmenu or switching to the common gas selection tab.
author Ideenmodellierer
date Fri, 05 Jan 2024 16:01:22 +0100
parents 18946846b95b
children 70092f552f5a
line wrap: on
line diff
--- a/Discovery/Src/t3.c	Wed Dec 27 19:37:17 2023 +0100
+++ b/Discovery/Src/t3.c	Fri Jan 05 16:01:22 2024 +0100
@@ -1968,6 +1968,51 @@
         return snprintf(text, size, "%c%u\016\016%%\017", colour, currentTimerMinutes * 100 / settingsGetPointer()->scrubberData[settings->scubberActiveId].TimerMax);
     }
 }
+
+uint8_t t3_HandleAFGaslist()
+{
+	static uint8_t debounce = 0;
+	static uint8_t lastState = AF_VIEW_NOCHANGE;
+	uint8_t detectionState = AF_VIEW_NOCHANGE;
+
+	if((stateUsed->warnings.betterGas) /* switch if better gas is available or depending on ppo2 if in OC mode */
+			|| ((stateUsed->diveSettings.diveMode == DIVEMODE_OC) && ((stateUsed->warnings.ppO2Low) || (stateUsed->warnings.ppO2High))))
+	{
+		if(debounce < 10)
+		{
+			debounce++;
+		}
+		else
+		{
+			detectionState = AF_VIEW_ACTIVATED;
+		}
+	}
+	else
+	{
+		if(debounce > 0)
+		{
+			debounce--;
+		}
+		else
+		{
+			detectionState = AF_VIEW_DEACTIVATED;
+		}
+	}
+	if(detectionState)	/* no state change => return 0 */
+	{
+		if((detectionState == lastState))
+		{
+			detectionState = AF_VIEW_NOCHANGE;
+		}
+		else
+		{
+			lastState = detectionState;
+		}
+	}
+
+	return detectionState;
+}
+
 void t3_handleAutofocus(void)
 {
 	static uint8_t returnView = CVIEW_T3_END;
@@ -1990,4 +2035,22 @@
 				break;
 		}
 	}
+	if(stateUsed->diveSettings.activeAFViews & (1 << CVIEW_T3_GasList))
+	{
+		switch(t3_HandleAFGaslist())
+		{
+			case AF_VIEW_ACTIVATED:	returnView = t3_selection_customview;
+									t3_select_customview(CVIEW_T3_GasList);
+
+				break;
+			case AF_VIEW_DEACTIVATED: if((returnView != CVIEW_T3_END) && (t3_selection_customview == CVIEW_T3_GasList))
+										{
+											t3_select_customview(returnView);
+											returnView = CVIEW_T3_END;
+										}
+				break;
+			default:
+				break;
+		}
+	}
 }