AP_Notify: Add singleton, expose string message player

This commit is contained in:
Michael du Breuil 2019-03-19 02:35:15 +00:00 committed by WickedShell
parent e7d59514d9
commit 200870e7a0
5 changed files with 34 additions and 6 deletions

View File

@ -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 &notify()
{
return *AP_Notify::get_singleton();
}
};

View File

@ -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 &notify();
};

View File

@ -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;

View File

@ -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;

View File

@ -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();