Skip to content

Commit

Permalink
AP_Notify: Add singleton, expose string message player
Browse files Browse the repository at this point in the history
  • Loading branch information
WickedShell committed Apr 12, 2019
1 parent e7d5951 commit 200870e
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 6 deletions.
18 changes: 18 additions & 0 deletions libraries/AP_Notify/AP_Notify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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();
}

};
7 changes: 7 additions & 0 deletions libraries/AP_Notify/AP_Notify.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ class AP_Notify
// 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
Expand Down Expand Up @@ -180,3 +183,7 @@ class AP_Notify
static NotifyDevice* _devices[];
static uint8_t _num_devices;
};

namespace AP {
AP_Notify &notify();
};
3 changes: 3 additions & 0 deletions libraries/AP_Notify/NotifyDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ class NotifyDevice {

// 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;
Expand Down
6 changes: 3 additions & 3 deletions libraries/AP_Notify/ToneAlarm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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);

Expand All @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions libraries/AP_Notify/ToneAlarm.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ class AP_ToneAlarm: public NotifyDevice {
// 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();

Expand Down

0 comments on commit 200870e

Please sign in to comment.