mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-05-28 02:36:37 +08:00
lib/tunes: never play tunes if circuit breaker is set
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
############################################################################
|
############################################################################
|
||||||
#
|
#
|
||||||
# Copyright (c) 2017 PX4 Development Team. All rights reserved.
|
# Copyright (c) 2017-2021 PX4 Development Team. All rights reserved.
|
||||||
#
|
#
|
||||||
# Redistribution and use in source and binary forms, with or without
|
# Redistribution and use in source and binary forms, with or without
|
||||||
# modification, are permitted provided that the following conditions
|
# modification, are permitted provided that the following conditions
|
||||||
@@ -32,6 +32,9 @@
|
|||||||
############################################################################
|
############################################################################
|
||||||
|
|
||||||
px4_add_library(tunes
|
px4_add_library(tunes
|
||||||
tunes.cpp
|
|
||||||
default_tunes.cpp
|
default_tunes.cpp
|
||||||
)
|
tune_definition.h
|
||||||
|
tunes.cpp
|
||||||
|
tunes.h
|
||||||
|
)
|
||||||
|
target_link_libraries(tunes PRIVATE circuit_breaker)
|
||||||
|
|||||||
@@ -38,6 +38,9 @@
|
|||||||
#include "tunes.h"
|
#include "tunes.h"
|
||||||
|
|
||||||
#include <px4_platform_common/log.h>
|
#include <px4_platform_common/log.h>
|
||||||
|
|
||||||
|
#include <lib/circuit_breaker/circuit_breaker.h>
|
||||||
|
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
@@ -56,6 +59,10 @@ Tunes::Tunes(unsigned default_note_length, NoteMode default_note_mode,
|
|||||||
_default_octave(default_octave),
|
_default_octave(default_octave),
|
||||||
_default_tempo(default_tempo)
|
_default_tempo(default_tempo)
|
||||||
{
|
{
|
||||||
|
if (circuit_breaker_enabled("CBRK_BUZZER", CBRK_BUZZER_KEY)) {
|
||||||
|
_tunes_disabled = true;
|
||||||
|
}
|
||||||
|
|
||||||
reset(false);
|
reset(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -152,6 +159,14 @@ void Tunes::set_string(const char *const string, uint8_t volume)
|
|||||||
|
|
||||||
Tunes::Status Tunes::get_next_note(unsigned &frequency, unsigned &duration, unsigned &silence, uint8_t &volume)
|
Tunes::Status Tunes::get_next_note(unsigned &frequency, unsigned &duration, unsigned &silence, uint8_t &volume)
|
||||||
{
|
{
|
||||||
|
if (_tunes_disabled) {
|
||||||
|
frequency = 0;
|
||||||
|
duration = 0;
|
||||||
|
silence = 0;
|
||||||
|
volume = 0;
|
||||||
|
return Tunes::Status::Stop;
|
||||||
|
}
|
||||||
|
|
||||||
Tunes::Status ret = get_next_note(frequency, duration, silence);
|
Tunes::Status ret = get_next_note(frequency, duration, silence);
|
||||||
|
|
||||||
// Check if note should not be heard -> adjust volume to 0 to be safe.
|
// 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
|
|||||||
|
|
||||||
Tunes::Status Tunes::get_next_note(unsigned &frequency, unsigned &duration, unsigned &silence)
|
Tunes::Status Tunes::get_next_note(unsigned &frequency, unsigned &duration, unsigned &silence)
|
||||||
{
|
{
|
||||||
|
if (_tunes_disabled) {
|
||||||
|
frequency = 0;
|
||||||
|
duration = 0;
|
||||||
|
silence = 0;
|
||||||
|
return Tunes::Status::Stop;
|
||||||
|
}
|
||||||
|
|
||||||
// Return the values for frequency and duration if the custom msg was received.
|
// Return the values for frequency and duration if the custom msg was received.
|
||||||
if (_using_custom_msg) {
|
if (_using_custom_msg) {
|
||||||
_using_custom_msg = false;
|
_using_custom_msg = false;
|
||||||
@@ -350,6 +372,10 @@ Tunes::Status Tunes::get_next_note(unsigned &frequency, unsigned &duration, unsi
|
|||||||
|
|
||||||
Tunes::Status Tunes::tune_end()
|
Tunes::Status Tunes::tune_end()
|
||||||
{
|
{
|
||||||
|
if (_tunes_disabled) {
|
||||||
|
return Tunes::Status::Stop;
|
||||||
|
}
|
||||||
|
|
||||||
// Restore intial parameters.
|
// Restore intial parameters.
|
||||||
reset(_repeat);
|
reset(_repeat);
|
||||||
|
|
||||||
@@ -364,6 +390,10 @@ Tunes::Status Tunes::tune_end()
|
|||||||
|
|
||||||
Tunes::Status Tunes::tune_error()
|
Tunes::Status Tunes::tune_error()
|
||||||
{
|
{
|
||||||
|
if (_tunes_disabled) {
|
||||||
|
return Tunes::Status::Stop;
|
||||||
|
}
|
||||||
|
|
||||||
// The tune appears to be bad (unexpected EOF, bad character, etc.).
|
// The tune appears to be bad (unexpected EOF, bad character, etc.).
|
||||||
_repeat = false; // Don't loop on error.
|
_repeat = false; // Don't loop on error.
|
||||||
reset(_repeat);
|
reset(_repeat);
|
||||||
|
|||||||
@@ -232,4 +232,6 @@ private:
|
|||||||
uint8_t _volume = 0;
|
uint8_t _volume = 0;
|
||||||
|
|
||||||
bool _using_custom_msg = false;
|
bool _using_custom_msg = false;
|
||||||
|
|
||||||
|
bool _tunes_disabled{false};
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user