From 82a98ef95dbc8f953a372208ac6fffbaf53ef89f Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 3 Sep 2019 11:25:18 +1000 Subject: [PATCH] AP_Notify: added NTZ_BUZZ_VOLUME parameter it is fairly non-linear, but does work --- libraries/AP_Notify/AP_Notify.cpp | 7 +++++++ libraries/AP_Notify/AP_Notify.h | 2 ++ libraries/AP_Notify/MMLPlayer.cpp | 3 +++ 3 files changed, 12 insertions(+) diff --git a/libraries/AP_Notify/AP_Notify.cpp b/libraries/AP_Notify/AP_Notify.cpp index eb506e29df..ac0d4b7448 100644 --- a/libraries/AP_Notify/AP_Notify.cpp +++ b/libraries/AP_Notify/AP_Notify.cpp @@ -158,6 +158,13 @@ const AP_Param::GroupInfo AP_Notify::var_info[] = { AP_GROUPINFO("BUZZ_ON_LVL", 7, AP_Notify, _buzzer_level, 1), #endif + // @Param: BUZZ_VOLUME + // @DisplayName: Buzzer volume + // @Description: Enable or disable the buzzer. + // @Range: 0 100 + // @Units: % + AP_GROUPINFO("BUZZ_VOLUME", 8, AP_Notify, _buzzer_volume, 100), + AP_GROUPEND }; diff --git a/libraries/AP_Notify/AP_Notify.h b/libraries/AP_Notify/AP_Notify.h index 4c8e885218..a1fd98c1b2 100644 --- a/libraries/AP_Notify/AP_Notify.h +++ b/libraries/AP_Notify/AP_Notify.h @@ -158,6 +158,7 @@ public: static const struct AP_Param::GroupInfo var_info[]; uint8_t get_buzz_pin() const { return _buzzer_pin; } uint8_t get_buzz_level() const { return _buzzer_level; } + uint8_t get_buzz_volume() const { return _buzzer_volume; } #if CONFIG_HAL_BOARD == HAL_BOARD_SITL HAL_Semaphore sf_window_mutex; @@ -181,6 +182,7 @@ private: AP_Int8 _buzzer_pin; AP_Int32 _led_type; AP_Int8 _buzzer_level; + AP_Int8 _buzzer_volume; char _send_text[NOTIFY_TEXT_BUFFER_SIZE]; uint32_t _send_text_updated_millis; // last time text changed diff --git a/libraries/AP_Notify/MMLPlayer.cpp b/libraries/AP_Notify/MMLPlayer.cpp index 918c29bc54..359a7b9da9 100644 --- a/libraries/AP_Notify/MMLPlayer.cpp +++ b/libraries/AP_Notify/MMLPlayer.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #if HAL_WITH_UAVCAN #include @@ -297,6 +298,8 @@ void MMLPlayer::next_action() float note_frequency = 880.0f * expf(logf(2.0f) * ((int)note - 46) / 12.0f); float note_volume = _volume/255.0f; + note_volume *= AP::notify().get_buzz_volume() * 0.01; + note_volume = constrain_float(note_volume, 0, 1); note_frequency = constrain_float(note_frequency, 10, 22000);