Mercurial > public > ostc4
comparison Discovery/Src/check_warning.c @ 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 | 33e24b77cc6c |
| children |
comparison
equal
deleted
inserted
replaced
| 995:768ed327ee69 | 996:8507a87f6401 |
|---|---|
| 77 #ifdef HAVE_DEBUG_WARNINGS | 77 #ifdef HAVE_DEBUG_WARNINGS |
| 78 static int8_t check_debug(SDiveState * pDiveState); | 78 static int8_t check_debug(SDiveState * pDiveState); |
| 79 #endif | 79 #endif |
| 80 static uint8_t buzzerOn = 0; /* current state of the buzzer */ | 80 static uint8_t buzzerOn = 0; /* current state of the buzzer */ |
| 81 | 81 |
| 82 static void setBuzzer(int8_t warningActive); | 82 static void handleBuzzer(int8_t warningActive); |
| 83 /* Exported functions --------------------------------------------------------*/ | 83 /* Exported functions --------------------------------------------------------*/ |
| 84 | 84 |
| 85 void requestBuzzerActivation(uint8_t active) | 85 void requestBuzzerActivation(uint8_t active) |
| 86 { | 86 { |
| 87 buzzerRequestActive = active; | 87 buzzerRequestActive = active; |
| 88 } | 88 } |
| 89 | 89 |
| 90 uint8_t getBuzzerActivationRequest() | |
| 91 { | |
| 92 return buzzerRequestActive; | |
| 93 } | |
| 94 | |
| 90 uint8_t getBuzzerActivationState() | 95 uint8_t getBuzzerActivationState() |
| 91 { | 96 { |
| 92 return buzzerOn; | 97 return buzzerOn; |
| 93 } | 98 } |
| 94 | 99 |
| 95 static void setBuzzer(int8_t warningActive) | 100 static void handleBuzzer(int8_t warningActive) |
| 96 { | 101 { |
| 97 static uint32_t guiTimeoutCnt = 0; /* max delay till buzzer will be activated independend from gui request */ | 102 static uint32_t guiTimeoutCnt = 0; /* max delay till buzzer will be activated independend from gui request */ |
| 98 static uint32_t stateTick = 0; /* activation tick of current state */ | 103 static uint32_t stateTick = 0; /* activation tick of current state */ |
| 99 static uint8_t lastWarningState = 0; /* the parameter value of the last call*/ | 104 static uint8_t lastWarningState = 0; /* the parameter value of the last call*/ |
| 105 static uint8_t lastBuzzerRequest = 0; | |
| 106 static uint8_t guiTrigger = 0; | |
| 100 | 107 |
| 101 uint32_t tick = HAL_GetTick(); | 108 uint32_t tick = HAL_GetTick(); |
| 102 | 109 |
| 103 if(warningActive) | 110 if(stateUsed->mode == MODE_SURFACE) |
| 104 { | 111 { |
| 105 if(!lastWarningState) /* init structures */ | 112 warningActive = 0; /* no warning buzzer in surface mode => overwrite value */ |
| 113 } | |
| 114 | |
| 115 /* There are two sources for buzzer activation: the warning detection and activation by gui => both need to be merged */ | |
| 116 if((buzzerRequestActive != REQUEST_BUZZER_OFF) && (lastBuzzerRequest == REQUEST_BUZZER_OFF)) | |
| 117 { | |
| 118 guiTrigger = 1; | |
| 119 } | |
| 120 if((warningActive) || (buzzerRequestActive != REQUEST_BUZZER_OFF)) | |
| 121 { | |
| 122 if((lastWarningState == 0) && (lastBuzzerRequest == REQUEST_BUZZER_OFF)) /* init structures */ | |
| 106 { | 123 { |
| 107 guiTimeoutCnt = tick; | 124 guiTimeoutCnt = tick; |
| 108 stateTick = tick; | 125 stateTick = tick; |
| 109 } | 126 } |
| 110 if(buzzerOn) | 127 if(buzzerOn) |
| 111 { | 128 { |
| 112 if(time_elapsed_ms(stateTick, tick) > EXT_INTERFACE_BUZZER_STABLE_TIME_MS) /* buzzer has to be on for a certain time */ | 129 if(time_elapsed_ms(stateTick, tick) > EXT_INTERFACE_BUZZER_STABLE_TIME_MS) /* buzzer has to be on for a certain time */ |
| 113 { | 130 { |
| 114 if((!buzzerRequestActive) || (time_elapsed_ms(stateTick, tick) > EXT_INTERFACE_BUZZER_ON_TIME_MS)) | 131 if((buzzerRequestActive == REQUEST_BUZZER_OFF) |
| 132 || ((buzzerRequestActive == REQUEST_BUZZER_ONCE) && (time_elapsed_ms(stateTick, tick) > EXT_INTERFACE_BUZZER_PING_TIME_MS)) | |
| 133 || (time_elapsed_ms(stateTick, tick) > EXT_INTERFACE_BUZZER_ON_TIME_MS)) | |
| 115 { | 134 { |
| 116 buzzerOn = 0; | 135 buzzerOn = 0; |
| 117 stateTick = tick; | 136 stateTick = tick; |
| 118 guiTimeoutCnt = tick; | 137 guiTimeoutCnt = tick; |
| 138 buzzerRequestActive = REQUEST_BUZZER_OFF; | |
| 119 } | 139 } |
| 120 } | 140 } |
| 121 } | 141 } |
| 122 else | 142 else |
| 123 { | 143 { |
| 124 if(time_elapsed_ms(stateTick, tick) > EXT_INTERFACE_BUZZER_STABLE_TIME_MS) /* buzzer has to be off for a certain time */ | 144 if((time_elapsed_ms(stateTick, tick) > EXT_INTERFACE_BUZZER_STABLE_TIME_MS) || ( guiTrigger)) /* buzzer has to be off for a certain time */ |
| 125 { | 145 { |
| 126 if((buzzerRequestActive) || (time_elapsed_ms(guiTimeoutCnt, tick) > EXT_INTERFACE_BUZZER_ON_TIME_MS + GUI_BUZZER_TIMEOUT_MS)) | 146 if((warningActive) || (buzzerRequestActive != REQUEST_BUZZER_OFF)) |
| 127 { | 147 { |
| 128 buzzerOn = 1; | 148 if(((stateUsed->mode != MODE_SURFACE) && (time_elapsed_ms(guiTimeoutCnt, tick)) > (EXT_INTERFACE_BUZZER_ON_TIME_MS + GUI_BUZZER_TIMEOUT_MS)) |
| 129 stateTick = tick; | 149 || ( guiTrigger)) |
| 150 { | |
| 151 buzzerOn = 1; | |
| 152 stateTick = tick; | |
| 153 guiTrigger = 0; | |
| 154 if(buzzerRequestActive == REQUEST_BUZZER_ONCE) | |
| 155 { | |
| 156 buzzerRequestActive = REQUEST_BUZZER_OFF; | |
| 157 } | |
| 158 } | |
| 159 if((time_elapsed_ms(guiTimeoutCnt, tick)) > (EXT_INTERFACE_BUZZER_ON_TIME_MS + EXT_INTERFACE_BUZZER_STABLE_TIME_MS)) /* timeout request */ | |
| 160 { | |
| 161 buzzerRequestActive = REQUEST_BUZZER_OFF; | |
| 162 } | |
| 130 } | 163 } |
| 131 } | 164 } |
| 132 } | 165 } |
| 133 } | 166 } |
| 134 else | 167 else |
| 135 { | 168 { |
| 136 buzzerOn = 0; | 169 buzzerOn = 0; |
| 137 } | 170 } |
| 171 lastBuzzerRequest = buzzerRequestActive; | |
| 138 lastWarningState = warningActive; | 172 lastWarningState = warningActive; |
| 173 } | |
| 174 | |
| 175 void deactivateBuzzer() | |
| 176 { | |
| 177 buzzerRequestActive = REQUEST_BUZZER_OFF; | |
| 178 buzzerOn = 0; | |
| 139 } | 179 } |
| 140 | 180 |
| 141 void check_warning(void) | 181 void check_warning(void) |
| 142 { | 182 { |
| 143 check_warning2(stateUsedWrite); | 183 check_warning2(stateUsedWrite); |
| 158 pDiveState->warnings.numWarnings += check_co2(pDiveState); | 198 pDiveState->warnings.numWarnings += check_co2(pDiveState); |
| 159 #endif | 199 #endif |
| 160 | 200 |
| 161 if(settingsGetPointer()->warningBuzzer) | 201 if(settingsGetPointer()->warningBuzzer) |
| 162 { | 202 { |
| 163 setBuzzer(pDiveState->warnings.numWarnings); | 203 handleBuzzer(pDiveState->warnings.numWarnings); |
| 164 } | 204 } |
| 165 | 205 |
| 166 /* Warnings checked after this line will not cause activation of the buzzer */ | 206 /* Warnings checked after this line will not cause activation of the buzzer */ |
| 167 pDiveState->warnings.numWarnings += check_aGF(pDiveState); | 207 pDiveState->warnings.numWarnings += check_aGF(pDiveState); |
| 168 pDiveState->warnings.numWarnings += check_CNS(pDiveState); | 208 pDiveState->warnings.numWarnings += check_CNS(pDiveState); |
