From 200870e7a0dfd7b7d1fb2825910835e856b94f4a Mon Sep 17 00:00:00 2001 From: Michael du Breuil Date: Tue, 19 Mar 2019 02:35:15 +0000 Subject: [PATCH] AP_Notify: Add singleton, expose string message player --- libraries/AP_Notify/AP_Notify.cpp | 18 ++++++++++++++++++ libraries/AP_Notify/AP_Notify.h | 7 +++++++ libraries/AP_Notify/NotifyDevice.h | 3 +++ libraries/AP_Notify/ToneAlarm.cpp | 6 +++--- libraries/AP_Notify/ToneAlarm.h | 6 +++--- 5 files changed, 34 insertions(+), 6 deletions(-) diff --git a/libraries/AP_Notify/AP_Notify.cpp b/libraries/AP_Notify/AP_Notify.cpp index 3596ae8533..d5d458199a 100644 --- a/libraries/AP_Notify/AP_Notify.cpp +++ b/libraries/AP_Notify/AP_Notify.cpp @@ -346,6 +346,15 @@ void AP_Notify::handle_play_tune(mavlink_message_t *msg) } } +void AP_Notify::play_tune(const char *tune) +{ + for (uint8_t i = 0; i < _num_devices; i++) { + if (_devices[i] != nullptr) { + _devices[i]->play_tune(tune); + } + } +} + // set flight mode string void AP_Notify::set_flight_mode_str(const char *str) { @@ -359,3 +368,12 @@ void AP_Notify::send_text(const char *str) _send_text[sizeof(_send_text)-1] = 0; _send_text_updated_millis = AP_HAL::millis(); } + +namespace AP { + +AP_Notify ¬ify() +{ + return *AP_Notify::get_singleton(); +} + +}; diff --git a/libraries/AP_Notify/AP_Notify.h b/libraries/AP_Notify/AP_Notify.h index f587290362..c81e86bb92 100644 --- a/libraries/AP_Notify/AP_Notify.h +++ b/libraries/AP_Notify/AP_Notify.h @@ -139,6 +139,9 @@ public: // handle a PLAY_TUNE message static void handle_play_tune(mavlink_message_t* msg); + // play a tune string + static void play_tune(const char *tune); + bool buzzer_enabled() const { return _buzzer_enable; } // set flight mode string @@ -180,3 +183,7 @@ private: static NotifyDevice* _devices[]; static uint8_t _num_devices; }; + +namespace AP { + AP_Notify ¬ify(); +}; diff --git a/libraries/AP_Notify/NotifyDevice.h b/libraries/AP_Notify/NotifyDevice.h index 9d350f6a57..05dfd91688 100644 --- a/libraries/AP_Notify/NotifyDevice.h +++ b/libraries/AP_Notify/NotifyDevice.h @@ -19,6 +19,9 @@ public: // handle a PLAY_TUNE message, by default device ignore message virtual void handle_play_tune(mavlink_message_t *msg) {} + + // play a MML tune + virtual void play_tune(const char *tune) {} // this pointer is used to read the parameters relative to devices const AP_Notify *pNotify; diff --git a/libraries/AP_Notify/ToneAlarm.cpp b/libraries/AP_Notify/ToneAlarm.cpp index e1daf1f2d1..103cf9bcaf 100644 --- a/libraries/AP_Notify/ToneAlarm.cpp +++ b/libraries/AP_Notify/ToneAlarm.cpp @@ -125,7 +125,7 @@ void AP_ToneAlarm::play_tone(const uint8_t tone_index) _tone_playing = tone_index; _tone_beginning_ms = tnow_ms; - play_string(tone_requested.str); + play_tune(tone_requested.str); } void AP_ToneAlarm::_timer_task() @@ -134,7 +134,7 @@ void AP_ToneAlarm::_timer_task() _mml_player.update(); } -void AP_ToneAlarm::play_string(const char *str) +void AP_ToneAlarm::play_tune(const char *str) { WITH_SEMAPHORE(_sem); @@ -147,7 +147,7 @@ void AP_ToneAlarm::play_string(const char *str) void AP_ToneAlarm::stop_cont_tone() { if (_cont_tone_playing == _tone_playing) { - play_string(""); + play_tune(""); _tone_playing = -1; } _cont_tone_playing = -1; diff --git a/libraries/AP_Notify/ToneAlarm.h b/libraries/AP_Notify/ToneAlarm.h index 044badf4af..8dcde19b74 100644 --- a/libraries/AP_Notify/ToneAlarm.h +++ b/libraries/AP_Notify/ToneAlarm.h @@ -35,13 +35,13 @@ public: // handle a PLAY_TUNE message void handle_play_tune(mavlink_message_t *msg) override; + // play_tune - play tone specified by the provided string of notes + void play_tune(const char *tune) override; + private: /// play_tune - play one of the pre-defined tunes void play_tone(const uint8_t tone_index); - // play_string - play tone specified by the provided string of notes - void play_string(const char *str); - // stop_cont_tone - stop playing the currently playing continuous tone void stop_cont_tone();