diff --git a/libraries/AP_Notify/AP_Notify.cpp b/libraries/AP_Notify/AP_Notify.cpp index 29252c1525..1499d2236f 100644 --- a/libraries/AP_Notify/AP_Notify.cpp +++ b/libraries/AP_Notify/AP_Notify.cpp @@ -442,16 +442,6 @@ void AP_Notify::handle_rgb_id(uint8_t r, uint8_t g, uint8_t b, uint8_t id) } } -// handle a PLAY_TUNE message -void AP_Notify::handle_play_tune(const mavlink_message_t &msg) -{ - for (uint8_t i = 0; i < _num_devices; i++) { - if (_devices[i] != nullptr) { - _devices[i]->handle_play_tune(msg); - } - } -} - void AP_Notify::play_tune(const char *tune) { for (uint8_t i = 0; i < _num_devices; i++) { diff --git a/libraries/AP_Notify/AP_Notify.h b/libraries/AP_Notify/AP_Notify.h index 0a0e0f370d..0355a93bd2 100644 --- a/libraries/AP_Notify/AP_Notify.h +++ b/libraries/AP_Notify/AP_Notify.h @@ -16,7 +16,7 @@ #include #include -#include +#include "AP_Notify_config.h" #include "NotifyDevice.h" @@ -160,8 +160,10 @@ public: // handle RGB from Scripting static void handle_rgb_id(uint8_t r, uint8_t g, uint8_t b, uint8_t id); +#if AP_NOTIFY_MAVLINK_PLAY_TUNE_SUPPORT_ENABLED // handle a PLAY_TUNE message static void handle_play_tune(const mavlink_message_t &msg); +#endif // play a tune string static void play_tune(const char *tune); diff --git a/libraries/AP_Notify/AP_Notify_config.h b/libraries/AP_Notify/AP_Notify_config.h new file mode 100644 index 0000000000..5133cdc082 --- /dev/null +++ b/libraries/AP_Notify/AP_Notify_config.h @@ -0,0 +1,10 @@ +#pragma once + +#include +#if HAL_GCS_ENABLED +#include +#endif + +#ifndef AP_NOTIFY_MAVLINK_PLAY_TUNE_SUPPORT_ENABLED +#define AP_NOTIFY_MAVLINK_PLAY_TUNE_SUPPORT_ENABLED HAL_GCS_ENABLED +#endif diff --git a/libraries/AP_Notify/NotifyDevice.h b/libraries/AP_Notify/NotifyDevice.h index 6a8a4b5695..06ab832f4f 100644 --- a/libraries/AP_Notify/NotifyDevice.h +++ b/libraries/AP_Notify/NotifyDevice.h @@ -1,7 +1,7 @@ #pragma once #include -#include +#include "AP_Notify_config.h" class AP_Notify; @@ -17,9 +17,6 @@ public: // handle a LED_CONTROL message, by default device ignore message virtual void handle_led_control(const mavlink_message_t &msg) {} - // handle a PLAY_TUNE message, by default device ignore message - virtual void handle_play_tune(const mavlink_message_t &msg) {} - // play a MML tune virtual void play_tune(const char *tune) {} diff --git a/libraries/AP_Notify/ToneAlarm.cpp b/libraries/AP_Notify/ToneAlarm.cpp index 6ffa1aa396..64721f7c54 100644 --- a/libraries/AP_Notify/ToneAlarm.cpp +++ b/libraries/AP_Notify/ToneAlarm.cpp @@ -449,26 +449,25 @@ void AP_ToneAlarm::update() } +#if AP_NOTIFY_MAVLINK_PLAY_TUNE_SUPPORT_ENABLED /* * handle a PLAY_TUNE message */ -void AP_ToneAlarm::handle_play_tune(const mavlink_message_t &msg) +void AP_Notify::handle_play_tune(const mavlink_message_t &msg) { // decode mavlink message mavlink_play_tune_t packet; mavlink_msg_play_tune_decode(&msg, &packet); - WITH_SEMAPHORE(_sem); - - _mml_player.stop(); - + char _tone_buf[AP_NOTIFY_TONEALARM_TONE_BUF_SIZE] {}; // ~100 bytes strncpy(_tone_buf, packet.tune, MIN(sizeof(packet.tune), sizeof(_tone_buf)-1)); - _tone_buf[sizeof(_tone_buf)-1] = 0; uint8_t len = strlen(_tone_buf); uint8_t len2 = strnlen(packet.tune2, sizeof(packet.tune2)); len2 = MIN((sizeof(_tone_buf)-1)-len, len2); - strncpy(_tone_buf+len, packet.tune2, len2); + memcpy(_tone_buf+len, packet.tune2, len2); // not strncpy to avoid truncation warning _tone_buf[sizeof(_tone_buf)-1] = 0; - _mml_player.play(_tone_buf); + + play_tune(_tone_buf); } +#endif diff --git a/libraries/AP_Notify/ToneAlarm.h b/libraries/AP_Notify/ToneAlarm.h index 27fc86fb9a..4df68d8765 100644 --- a/libraries/AP_Notify/ToneAlarm.h +++ b/libraries/AP_Notify/ToneAlarm.h @@ -32,9 +32,6 @@ public: /// update - updates led according to timed_updated. Should be called at 50Hz void update() override; - // handle a PLAY_TUNE message - void handle_play_tune(const mavlink_message_t &msg) override; - // play_tune - play tone specified by the provided string of notes void play_tune(const char *tune) override;