changeset 996:8507a87f6401 GasConsumption

Improve buzzer opreation: In the previous version the buzzer was operated in case warning events. In the new version the buzzer is inactive in surface mode in order to prevent annoying warning just because e.g. the sensors are not connected. In addition it is now possible to request a short activation only e.g. in case of the activation of the buzzer via the menu.
author Ideenmodellierer
date Mon, 21 Apr 2025 21:00:34 +0200
parents 768ed327ee69
children 2f7531a8e922
files Common/Inc/data_central.h Discovery/Inc/check_warning.h Discovery/Src/check_warning.c Discovery/Src/t3.c Discovery/Src/t7.c Discovery/Src/tMenu.c Discovery/Src/tMenuEditCustom.c
diffstat 7 files changed, 70 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/Common/Inc/data_central.h	Sun Apr 27 10:14:25 2025 +0200
+++ b/Common/Inc/data_central.h	Mon Apr 21 21:00:34 2025 +0200
@@ -44,7 +44,8 @@
 #define EXT_INTERFACE_SENSOR_CNT	(8u)		/* 1 MUX + 7 sensors may be connected to the external interface (1 MUX + 3 ADC + 4 UART) */
 #define EXT_INTERFACE_MUX_OFFSET	(3u)		/* the sensor struct starts with 3 ADC sensors */
 
-#define EXT_INTERFACE_BUZZER_ON_TIME_MS (2000u)		/* max time the buzzer should be active without break */
+#define EXT_INTERFACE_BUZZER_ON_TIME_MS (2000u)		/* max time the buzzer should be active without break (continuous Operation) */
+#define EXT_INTERFACE_BUZZER_PING_TIME_MS (1000u)	/* max time the buzzer should be active for single ping */
 #define EXT_INTERFACE_BUZZER_STABLE_TIME_MS (500u)	/* min time a state (ON / OFF) should be stable before it may be changed */
 
 
--- a/Discovery/Inc/check_warning.h	Sun Apr 27 10:14:25 2025 +0200
+++ b/Discovery/Inc/check_warning.h	Mon Apr 21 21:00:34 2025 +0200
@@ -30,6 +30,12 @@
 #include <stdint.h>
 #include "data_central.h"
 
+
+#define REQUEST_BUZZER_OFF			(0u)
+#define REQUEST_BUZZER_ONCE			(1u)
+#define REQUEST_BUZZER_CONTINUOUS	(2u)
+
+
 /* Exported function prototypes ----------------------------------------------*/
 void check_warning(void);
 void check_warning2(SDiveState *pDiveState);
@@ -46,5 +52,7 @@
 uint8_t getSetpointLowId(void);
 uint8_t getSetpointDecoId(void);
 void requestBuzzerActivation(uint8_t active);
+uint8_t getBuzzerActivationRequest();
 uint8_t getBuzzerActivationState();
+void deactivateBuzzer();
 #endif // CHECK_WARNING_H
--- a/Discovery/Src/check_warning.c	Sun Apr 27 10:14:25 2025 +0200
+++ b/Discovery/Src/check_warning.c	Mon Apr 21 21:00:34 2025 +0200
@@ -79,7 +79,7 @@
 #endif
 static uint8_t buzzerOn = 0;			/* current state of the buzzer */
 
-static void setBuzzer(int8_t warningActive);
+static void handleBuzzer(int8_t warningActive);
 /* Exported functions --------------------------------------------------------*/
 
 void requestBuzzerActivation(uint8_t active)
@@ -87,22 +87,39 @@
 	buzzerRequestActive = active;
 }
 
+uint8_t getBuzzerActivationRequest()
+{
+	return buzzerRequestActive;
+}
+
 uint8_t getBuzzerActivationState()
 {
 	return buzzerOn;
 }
 
-static void setBuzzer(int8_t warningActive)
+static void handleBuzzer(int8_t warningActive)
 {
 	static uint32_t guiTimeoutCnt = 0;		/* max delay till buzzer will be activated independend from gui request */
 	static uint32_t stateTick = 0;			/* activation tick of current state */
 	static uint8_t lastWarningState = 0;	/* the parameter value of the last call*/
+	static uint8_t lastBuzzerRequest = 0;
+	static uint8_t guiTrigger = 0;
 
 	uint32_t tick =  HAL_GetTick();
 
-	if(warningActive)
+	if(stateUsed->mode == MODE_SURFACE)
 	{
-		if(!lastWarningState)				/* init structures */
+		warningActive = 0;					/* no warning buzzer in surface mode => overwrite value */
+	}
+
+	/* There are two sources for buzzer activation: the warning detection and activation by gui => both need to be merged */
+	if((buzzerRequestActive != REQUEST_BUZZER_OFF) &&  (lastBuzzerRequest == REQUEST_BUZZER_OFF))
+	{
+		guiTrigger = 1;
+	}
+	if((warningActive) || (buzzerRequestActive != REQUEST_BUZZER_OFF))
+	{
+		if((lastWarningState == 0) && (lastBuzzerRequest == REQUEST_BUZZER_OFF))			/* init structures */
 		{
 			guiTimeoutCnt = tick;
 			stateTick = tick;
@@ -111,22 +128,38 @@
 		{
 			if(time_elapsed_ms(stateTick, tick) > EXT_INTERFACE_BUZZER_STABLE_TIME_MS)	/* buzzer has to be on for a certain time */
 			{
-				if((!buzzerRequestActive) || (time_elapsed_ms(stateTick, tick) > EXT_INTERFACE_BUZZER_ON_TIME_MS))
+				if((buzzerRequestActive == REQUEST_BUZZER_OFF)
+						|| ((buzzerRequestActive == REQUEST_BUZZER_ONCE) && (time_elapsed_ms(stateTick, tick) > EXT_INTERFACE_BUZZER_PING_TIME_MS))
+						||  (time_elapsed_ms(stateTick, tick) > EXT_INTERFACE_BUZZER_ON_TIME_MS))
 				{
 					buzzerOn = 0;
 					stateTick = tick;
 					guiTimeoutCnt = tick;
+					buzzerRequestActive = REQUEST_BUZZER_OFF;
 				}
 			}
 		}
 		else
 		{
-			if(time_elapsed_ms(stateTick, tick) > EXT_INTERFACE_BUZZER_STABLE_TIME_MS)	/* buzzer has to be off for a certain time */
+			if((time_elapsed_ms(stateTick, tick) > EXT_INTERFACE_BUZZER_STABLE_TIME_MS) || ( guiTrigger))	/* buzzer has to be off for a certain time */
 			{
-				if((buzzerRequestActive) || (time_elapsed_ms(guiTimeoutCnt, tick) > EXT_INTERFACE_BUZZER_ON_TIME_MS + GUI_BUZZER_TIMEOUT_MS))
+				if((warningActive) || (buzzerRequestActive != REQUEST_BUZZER_OFF))
 				{
-					buzzerOn = 1;
-					stateTick = tick;
+					if(((stateUsed->mode != MODE_SURFACE) && (time_elapsed_ms(guiTimeoutCnt, tick)) > (EXT_INTERFACE_BUZZER_ON_TIME_MS + GUI_BUZZER_TIMEOUT_MS))
+						|| ( guiTrigger))
+					{
+						buzzerOn = 1;
+						stateTick = tick;
+						guiTrigger = 0;
+						if(buzzerRequestActive == REQUEST_BUZZER_ONCE)
+						{
+							buzzerRequestActive = REQUEST_BUZZER_OFF;
+						}
+					}
+					if((time_elapsed_ms(guiTimeoutCnt, tick)) > (EXT_INTERFACE_BUZZER_ON_TIME_MS + EXT_INTERFACE_BUZZER_STABLE_TIME_MS))  /* timeout request */
+					{
+						buzzerRequestActive = REQUEST_BUZZER_OFF;
+					}
 				}
 			}
 		}
@@ -135,9 +168,16 @@
 	{
 		buzzerOn = 0;
 	}
+	lastBuzzerRequest = buzzerRequestActive;
 	lastWarningState = warningActive;
 }
 
+void deactivateBuzzer()
+{
+	buzzerRequestActive = REQUEST_BUZZER_OFF;
+	buzzerOn = 0;
+}
+
 void check_warning(void)
 {
   check_warning2(stateUsedWrite);
@@ -160,7 +200,7 @@
 
 	if(settingsGetPointer()->warningBuzzer)
 	{
-		setBuzzer(pDiveState->warnings.numWarnings);
+		handleBuzzer(pDiveState->warnings.numWarnings);
 	}
 
 /* Warnings checked after this line will not cause activation of the buzzer */
--- a/Discovery/Src/t3.c	Sun Apr 27 10:14:25 2025 +0200
+++ b/Discovery/Src/t3.c	Mon Apr 21 21:00:34 2025 +0200
@@ -769,7 +769,7 @@
     else
     {
         t3_refresh_customview(depth_meter);
-        requestBuzzerActivation(0);
+        requestBuzzerActivation(REQUEST_BUZZER_OFF);
     }
     if(stateUsed->warnings.lowBattery)
         t3_basics_battery_low_customview_extra(&t3r1); //t3c1);
@@ -1687,7 +1687,7 @@
     {
         GFX_write_string(&FontT48,&t3c2,text,0);
     }
-    requestBuzzerActivation(1);
+    requestBuzzerActivation(REQUEST_BUZZER_CONTINUOUS);
 }
 
 uint8_t t3_customview_disabled(uint8_t view)
--- a/Discovery/Src/t7.c	Sun Apr 27 10:14:25 2025 +0200
+++ b/Discovery/Src/t7.c	Mon Apr 21 21:00:34 2025 +0200
@@ -1622,7 +1622,7 @@
     }
 */
     GFX_write_string(&FontT48,&t7cW,text,1);
-    requestBuzzerActivation(1);
+   	requestBuzzerActivation(REQUEST_BUZZER_CONTINUOUS);
 }
 
 
@@ -3233,7 +3233,7 @@
     else
     {
         t7_refresh_customview();
-        requestBuzzerActivation(0);
+        requestBuzzerActivation(REQUEST_BUZZER_OFF);
     }
 
     /* the frame */
--- a/Discovery/Src/tMenu.c	Sun Apr 27 10:14:25 2025 +0200
+++ b/Discovery/Src/tMenu.c	Mon Apr 21 21:00:34 2025 +0200
@@ -864,7 +864,10 @@
     if((page == 0) || (line == 0))
         return;
 
-    requestBuzzerActivation(0);
+    if( getBuzzerActivationRequest() != REQUEST_BUZZER_ONCE)
+    {
+    	requestBuzzerActivation(REQUEST_BUZZER_OFF);
+    }
 
     menu.pageMemoryForNavigation = page;
     /* new test for 3button design */
--- a/Discovery/Src/tMenuEditCustom.c	Sun Apr 27 10:14:25 2025 +0200
+++ b/Discovery/Src/tMenuEditCustom.c	Mon Apr 21 21:00:34 2025 +0200
@@ -482,11 +482,12 @@
     if(pSettings->warningBuzzer == 0)
     {
         pSettings->warningBuzzer = 1;
-        requestBuzzerActivation(1);
+        requestBuzzerActivation(REQUEST_BUZZER_ONCE);
     }
     else
     {
         pSettings->warningBuzzer = 0;
+        deactivateBuzzer();
     }
     exitMenuEdit_to_Menu_with_Menu_Update_do_not_write_settings_for_this_only();
 }