tap_esc: fix tunes

This removes the redundant _play_tone flag and instead just polls the
next_note() interface to check if there is something to play.
This commit is contained in:
Julian Oes 2021-09-28 09:12:22 +02:00 committed by Daniel Agar
parent de1849167d
commit 76920171c7
2 changed files with 3 additions and 10 deletions

View File

@ -365,31 +365,26 @@ void TAP_ESC::Run()
if (_tune_control_sub.copy(&tune)) {
if (tune.timestamp > 0) {
Tunes::ControlResult result = _tunes.set_control(tune);
_play_tone = (result == Tunes::ControlResult::Success) || (result == Tunes::ControlResult::AlreadyPlaying);
PX4_DEBUG("new tune id: %d, result: %d, play: %d", tune.tune_id, (int)result, _play_tone);
PX4_DEBUG("new tune id: %d, result: %d, duration: %lu", tune.tune_id, (int)result, tune.duration);
}
}
}
const hrt_abstime timestamp_now = hrt_absolute_time();
if ((timestamp_now - _interval_timestamp <= _duration) || !_play_tone) {
//return;
} else {
if ((timestamp_now - _interval_timestamp > _duration)) {
_interval_timestamp = timestamp_now;
if (_silence_length > 0) {
_duration = _silence_length;
_silence_length = 0;
} else if (_play_tone) {
} else {
uint8_t strength = 0;
Tunes::Status parse_ret_val = _tunes.get_next_note(_frequency, _duration, _silence_length, strength);
if (parse_ret_val == Tunes::Status::Continue) {
// Continue playing.
_play_tone = true;
if (_frequency > 0) {
// Start playing the note.
EscbusTunePacket esc_tune_packet{};
@ -400,7 +395,6 @@ void TAP_ESC::Run()
}
} else {
_play_tone = false;
_silence_length = 0;
}
}

View File

@ -134,7 +134,6 @@ private:
Tunes _tunes{};
uORB::Subscription _tune_control_sub{ORB_ID(tune_control)};
hrt_abstime _interval_timestamp{0};
bool _play_tone{false};
unsigned int _silence_length{0}; ///< If nonzero, silence before next note.
unsigned int _frequency{0};
unsigned int _duration{0};