38
38
#include " tunes.h"
39
39
40
40
#include < px4_platform_common/log.h>
41
+
42
+ #include < lib/circuit_breaker/circuit_breaker.h>
43
+
41
44
#include < math.h>
42
45
#include < ctype.h>
43
46
#include < errno.h>
@@ -56,6 +59,10 @@ Tunes::Tunes(unsigned default_note_length, NoteMode default_note_mode,
56
59
_default_octave(default_octave),
57
60
_default_tempo(default_tempo)
58
61
{
62
+ if (circuit_breaker_enabled (" CBRK_BUZZER" , CBRK_BUZZER_KEY)) {
63
+ _tunes_disabled = true ;
64
+ }
65
+
59
66
reset (false );
60
67
}
61
68
@@ -152,6 +159,14 @@ void Tunes::set_string(const char *const string, uint8_t volume)
152
159
153
160
Tunes::Status Tunes::get_next_note (unsigned &frequency, unsigned &duration, unsigned &silence, uint8_t &volume)
154
161
{
162
+ if (_tunes_disabled) {
163
+ frequency = 0 ;
164
+ duration = 0 ;
165
+ silence = 0 ;
166
+ volume = 0 ;
167
+ return Tunes::Status::Stop;
168
+ }
169
+
155
170
Tunes::Status ret = get_next_note (frequency, duration, silence);
156
171
157
172
// Check if note should not be heard -> adjust volume to 0 to be safe.
@@ -167,6 +182,13 @@ Tunes::Status Tunes::get_next_note(unsigned &frequency, unsigned &duration, unsi
167
182
168
183
Tunes::Status Tunes::get_next_note (unsigned &frequency, unsigned &duration, unsigned &silence)
169
184
{
185
+ if (_tunes_disabled) {
186
+ frequency = 0 ;
187
+ duration = 0 ;
188
+ silence = 0 ;
189
+ return Tunes::Status::Stop;
190
+ }
191
+
170
192
// Return the values for frequency and duration if the custom msg was received.
171
193
if (_using_custom_msg) {
172
194
_using_custom_msg = false ;
@@ -350,6 +372,10 @@ Tunes::Status Tunes::get_next_note(unsigned &frequency, unsigned &duration, unsi
350
372
351
373
Tunes::Status Tunes::tune_end ()
352
374
{
375
+ if (_tunes_disabled) {
376
+ return Tunes::Status::Stop;
377
+ }
378
+
353
379
// Restore intial parameters.
354
380
reset (_repeat);
355
381
@@ -364,6 +390,10 @@ Tunes::Status Tunes::tune_end()
364
390
365
391
Tunes::Status Tunes::tune_error ()
366
392
{
393
+ if (_tunes_disabled) {
394
+ return Tunes::Status::Stop;
395
+ }
396
+
367
397
// The tune appears to be bad (unexpected EOF, bad character, etc.).
368
398
_repeat = false ; // Don't loop on error.
369
399
reset (_repeat);
0 commit comments