# HG changeset patch # User Ideenmodellierer # Date 1745262034 -7200 # Node ID 8507a87f640139a145d21e7a903f09549c791fd2 # Parent 768ed327ee698a3e55a0656ad9c947725c0d4c5c 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. diff -r 768ed327ee69 -r 8507a87f6401 Common/Inc/data_central.h --- 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 */ diff -r 768ed327ee69 -r 8507a87f6401 Discovery/Inc/check_warning.h --- 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 #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 diff -r 768ed327ee69 -r 8507a87f6401 Discovery/Src/check_warning.c --- 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 */ diff -r 768ed327ee69 -r 8507a87f6401 Discovery/Src/t3.c --- 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) diff -r 768ed327ee69 -r 8507a87f6401 Discovery/Src/t7.c --- 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 */ diff -r 768ed327ee69 -r 8507a87f6401 Discovery/Src/tMenu.c --- 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 */ diff -r 768ed327ee69 -r 8507a87f6401 Discovery/Src/tMenuEditCustom.c --- 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(); }