-
Notifications
You must be signed in to change notification settings - Fork 13.6k
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
libtunes: Various bugfixes and improvements #9117
Conversation
Custom msg tune can override any tune playing, regardless of the tune_override flag.
Bugfix: This fixes a bug where libtunes might indicate that there are more tones to play even after the last note of a tune.
Override flag must still be set to true!
Otherwise the only way of interrupting a repeated tune would be with the override flag, which should only be used rarely. Now repeating tunes have lowest priority, followed by one-shot tunes, followed by anything with an override flag.
Since the tune library also contains logic how tunes can be overriden, a user of the tunes library cannot know the strength of the current tune without replicating some logic. Easy solution is to add strength to the output of Tunes::get_next_tune().
8ba9e9a
to
0c09ff8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good.
It's probably the most intuitive solution, but I'd like your input before I code it up with all its corner cases.
I agree, but I don't think we need to go super fancy here - except you want to of course.
src/lib/tunes/tunes.cpp
Outdated
bool reset_playing_tune = false; | ||
// Sanity check | ||
if (tune_control.tune_id >= _default_tunes_size) { | ||
PX4_WARN("Tune ID not recognized."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd remove the printf and just return the EINVAL. Reduces the amount of strings.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good thinking
src/lib/tunes/tunes.h
Outdated
@@ -62,42 +73,66 @@ class Tunes | |||
*/ | |||
Tunes(unsigned default_tempo, unsigned default_octave, unsigned default_note_length, NoteMode default_mode); | |||
|
|||
/** | |||
* Default destructor |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment is a bit redundant
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I figured that the documentation looks more complete if there is a comment above every function. But you are right, it is redundant.
@bkueng Thanks for the review. I made the changes in the last commit. Regarding the repeated tune interruption, I'll keep that in mind for a time in the future when I feel more inspired 😛 |
These are additions for the upstream PR #9117 that are specific to Yuneec's tap_esc driver.
@bkueng Could you take a look? This is part 2/2 of my libtunes additions, part 1/2 being #9096.
Bugfixes
override
flag in the tune message is for.https://github.com/PX4/Firmware/blob/d87b7ac7f4f3a86b49b64a976e982e469d361bd0/src/lib/tunes/tunes.cpp#L101-L106
_repeat
was uninitialized and most compilers would set it to 0 then, but not all I guess).tune_control play -m "<melody_string>"
for example)Improvements
In the current implementation this means, that repeated tunes have lowest priority, followed by normal tunes, followed by tunes with hard-coded high-priority, followed by tunes with the
tune_override
flag set. In the future I assume that the hard-coded priorities will be removed and the override flag correctly used instead.int Tunes::get_next_tune()
. This way the code playing back the tunes does not need to store the strength separately. Also, when tunes are interrupted or overridden, a player would not know that it might have to adjust the strength for a new tune. With this change, libtunes keeps track of the tune strength.tunes.cpp
and replaced it with an if-statement for better code readability.Tested on a pixracer (
px4fmu-v4_default
) with a piezo buzzer and thetune_control
system command.