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

libtunes: Various bugfixes and improvements #9117

Merged
merged 12 commits into from
Mar 26, 2018
Merged

Conversation

potaito
Copy link
Contributor

@potaito potaito commented Mar 20, 2018

@bkueng Could you take a look? This is part 2/2 of my libtunes additions, part 1/2 being #9096.

Bugfixes

  • Custom messages (id 0) would always override everything. In my opinion, this is what the override flag in the tune message is for.
  • Repeated tunes (for example the battery warning) could not be interrupted except with other high-priority tunes, which are:
    https://github.com/PX4/Firmware/blob/d87b7ac7f4f3a86b49b64a976e982e469d361bd0/src/lib/tunes/tunes.cpp#L101-L106
  • Occasionally, repeated tunes would not be played back repeatedly (_repeat was uninitialized and most compilers would set it to 0 then, but not all I guess).
  • Fixed playback of string melodies (when calling tune_control play -m "<melody_string>" for example)

Improvements

  • New rule / open for discussion: repeated tunes can be interrupted by any other tune without the override flag. I also experimented with a version where repeated tunes could be interrupted by non-repeated tunes. Once the latter are finished being played, the repeated tune would be resumed. It's probably the most intuitive solution, but I'd like your input before I code it up with all its corner cases.
    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.
  • General cleanup / type fixes
  • Added tune strength to output 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.
  • Removed the switch-case statement in 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 the tune_control system command.

potaito added 11 commits March 20, 2018 15:11
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.
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().
@potaito potaito force-pushed the pr-libtunes-various-fixes branch from 8ba9e9a to 0c09ff8 Compare March 20, 2018 14:13
Copy link
Member

@bkueng bkueng left a 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.

bool reset_playing_tune = false;
// Sanity check
if (tune_control.tune_id >= _default_tunes_size) {
PX4_WARN("Tune ID not recognized.");
Copy link
Member

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.

Copy link
Contributor Author

@potaito potaito Mar 26, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good thinking

@@ -62,42 +73,66 @@ class Tunes
*/
Tunes(unsigned default_tempo, unsigned default_octave, unsigned default_note_length, NoteMode default_mode);

/**
* Default destructor
Copy link
Member

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

Copy link
Contributor Author

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.

@potaito
Copy link
Contributor Author

potaito commented Mar 26, 2018

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

@bkueng bkueng merged commit 9d3dfb7 into master Mar 26, 2018
@bkueng bkueng deleted the pr-libtunes-various-fixes branch March 26, 2018 12:54
MaEtUgR pushed a commit that referenced this pull request Jul 17, 2018
MaEtUgR pushed a commit that referenced this pull request Jul 17, 2018
These are additions for the upstream PR #9117 that are specific to Yuneec's tap_esc driver.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants