Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AP_Notify: remove recursive call to play in next_action #13874

Merged
merged 1 commit into from Mar 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 12 additions & 2 deletions libraries/AP_Notify/MMLPlayer.cpp
Expand Up @@ -21,7 +21,7 @@ void MMLPlayer::update()
}
}

void MMLPlayer::play(const char* string)
void MMLPlayer::prepare_to_play_string(const char* string)
{
stop();

Expand All @@ -36,6 +36,12 @@ void MMLPlayer::play(const char* string)
_repeat = false;

_playing = true;
_note_duration_us = 0;
}

void MMLPlayer::play(const char* string)
{
prepare_to_play_string(string);
next_action();
}

Expand Down Expand Up @@ -133,7 +139,11 @@ void MMLPlayer::next_action()
char c = next_char();
if (c == '\0') {
if (_repeat) {
play(_string);
// don't "play" here, as we may have been called from
// there, and it turns out infinite recursion on
// invalid strings is suboptimal. The next call to
// update() will push things out as appropriate.
prepare_to_play_string(_string);
} else {
stop();
}
Expand Down
4 changes: 4 additions & 0 deletions libraries/AP_Notify/MMLPlayer.h
Expand Up @@ -10,6 +10,10 @@ class MMLPlayer {
void stop();

private:

// initialise ready to play string
void prepare_to_play_string(const char* string);

bool _playing;

uint32_t _note_duration_us;
Expand Down