changeset 835:717b460294cd Evo_2_23

Added autofocus for BF Navigation view: In case of activated autofocus feature for big font the navigation view will now be activated in case the OSTC4 is hold in horizontal position (like it is for example done if you take a bearing). The OSTC4 will return to the previous view in case the OSTC4 is no longer hold in horizontal position.
author Ideenmodellierer
date Sun, 17 Dec 2023 21:49:02 +0100
parents 2a8af51ab04d
children 8d6c35655d4d
files Discovery/Inc/t3.h Discovery/Inc/tMenuEditCustom.h Discovery/Src/base.c Discovery/Src/t3.c Discovery/Src/tMenuEditCustom.c
diffstat 5 files changed, 51 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/Discovery/Inc/t3.h	Sun Dec 17 21:14:17 2023 +0100
+++ b/Discovery/Inc/t3.h	Sun Dec 17 21:49:02 2023 +0100
@@ -42,6 +42,7 @@
 uint8_t t3_getCustomView(void);
 void t3_set_customview_to_primary(void);
 uint8_t t3_customview_disabled(uint8_t view);
+void t3_handleAutofocus(void);
 
 int printScrubberText(char *text, size_t size, SSettings *settings);
 
--- a/Discovery/Inc/tMenuEditCustom.h	Sun Dec 17 21:14:17 2023 +0100
+++ b/Discovery/Inc/tMenuEditCustom.h	Sun Dec 17 21:49:02 2023 +0100
@@ -34,6 +34,14 @@
 #include "settings.h"
 #include "data_central.h"
 
+enum afDetectionState
+{
+	AF_VIEW_NOCHANGE		= 0,
+	AF_VIEW_ACTIVATED,
+	AF_VIEW_DEACTIVATED
+};
+
+
 void openEdit_Custom(uint8_t line);
 void openEdit_CustomviewDivemode(const uint8_t* pcv_changelist);
 void openEdit_CustomviewDivemodeMenu(uint8_t line);
--- a/Discovery/Src/base.c	Sun Dec 17 21:14:17 2023 +0100
+++ b/Discovery/Src/base.c	Sun Dec 17 21:49:02 2023 +0100
@@ -544,7 +544,11 @@
         		HandleMotionDetection();
         	}
 #endif
-
+		/* Autofocus for T3 view */
+        	if((settingsGetPointer()->cvAutofocus) && (settingsGetPointer()->design == 3) && (get_globalState() == StD) && (stateUsed->mode == MODE_DIVE))
+        	{
+        		t3_handleAutofocus();
+        	}
 #ifdef SIM_WRITES_LOGBOOK
         if(stateUsed == stateSimGetPointer())
             logbook_InitAndWrite(stateUsed);
--- a/Discovery/Src/t3.c	Sun Dec 17 21:14:17 2023 +0100
+++ b/Discovery/Src/t3.c	Sun Dec 17 21:49:02 2023 +0100
@@ -40,6 +40,7 @@
 #include "unit.h"
 #include "motion.h"
 #include "logbook_miniLive.h"
+#include "tMenuEditCustom.h"
 
 
 #define CV_PROFILE_WIDTH		(600U)
@@ -1987,3 +1988,26 @@
         return snprintf(text, size, "%c%u\016\016%%\017", colour, currentTimerMinutes * 100 / settingsGetPointer()->scrubberData[settings->scubberActiveId].TimerMax);
     }
 }
+void t3_handleAutofocus(void)
+{
+	static uint8_t returnView = CVIEW_T3_END;
+
+	if(stateUsed->diveSettings.activeAFViews & (1 << CVIEW_T3_Navigation))
+	{
+		switch(HandleAFCompass())
+		{
+			case AF_VIEW_ACTIVATED:	returnView = t3_selection_customview;
+									t3_select_customview(CVIEW_T3_Navigation);
+
+				break;
+			case AF_VIEW_DEACTIVATED: if((returnView != CVIEW_T3_END) && (t3_selection_customview == CVIEW_T3_Navigation))
+										{
+											t3_select_customview(returnView);
+											returnView = CVIEW_T3_END;
+										}
+				break;
+			default:
+				break;
+		}
+	}
+}
--- a/Discovery/Src/tMenuEditCustom.c	Sun Dec 17 21:14:17 2023 +0100
+++ b/Discovery/Src/tMenuEditCustom.c	Sun Dec 17 21:49:02 2023 +0100
@@ -48,6 +48,10 @@
 
 #define MAX_FOCUS_LIMITER	(2u)	/* max number for reducing the spot used for focus detection */
 
+/* defines for autofocus of compass */
+#define AF_COMPASS_ACTIVATION_ANGLE	(5.0f)	/* angle for pitch and roll. Compass gets activated in case the value is smaller (OSTC4 hold in horitontal position */
+#define AF_COMPASS_DEBOUNCE			(10u)	/* debouncing value to avoid compass activation during normal movement */
+
 static uint8_t customviewsSubpage = 0;
 static uint8_t customviewsSubpageMax = 0;	/* number of pages needed to display all selectable views */
 static const uint8_t*	pcv_curchangelist;
@@ -1093,20 +1097,19 @@
 uint8_t HandleAFCompass()
 {
 	static uint8_t debounce = 0;
-	static uint8_t lastState = 0;
-	uint8_t detectionState = 0;
+	static uint8_t lastState = AF_VIEW_NOCHANGE;
+	uint8_t detectionState = AF_VIEW_NOCHANGE;
 
 	float pitch = stateRealGetPointer()->lifeData.compass_pitch;
 	float roll = stateRealGetPointer()->lifeData.compass_roll;
 
-	if((pitch > -5.0) && (pitch < 5.0) && (roll > -5.0) && (roll < 5.0))		/* OSTC in horizontal position */
+	/* OSTC in horizontal position ?*/
+	if((pitch > -AF_COMPASS_ACTIVATION_ANGLE) && (pitch < AF_COMPASS_ACTIVATION_ANGLE) && (roll > -AF_COMPASS_ACTIVATION_ANGLE) && (roll < AF_COMPASS_ACTIVATION_ANGLE))
 	{
-		if(debounce < 10) debounce++;
-		if(debounce == 10)
+		if(debounce < AF_COMPASS_DEBOUNCE) debounce++;
+		if(debounce == AF_COMPASS_DEBOUNCE)
 		{
-			detectionState = 1;
-		//	debounce = 0;
-		//	t3_select_customview(CVIEW_T3_Navigation);
+			detectionState = AF_VIEW_ACTIVATED;
 		}
 	}
 	else
@@ -1114,14 +1117,14 @@
 		if(debounce > 0) debounce--;
 		if(debounce == 0)
 		{
-			detectionState = 2;
+			detectionState = AF_VIEW_DEACTIVATED;
 		}
 	}
 	if(detectionState)	/* no state change => return 0 */
 	{
 		if((detectionState == lastState))
 		{
-			detectionState = 0;
+			detectionState = AF_VIEW_NOCHANGE;
 		}
 		else
 		{