From 76920171c771539d5bb6a03593d4cfbcbea342b6 Mon Sep 17 00:00:00 2001 From: Julian Oes Date: Tue, 28 Sep 2021 09:12:22 +0200 Subject: [PATCH] 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. --- src/drivers/tap_esc/TAP_ESC.cpp | 12 +++--------- src/drivers/tap_esc/TAP_ESC.hpp | 1 - 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/src/drivers/tap_esc/TAP_ESC.cpp b/src/drivers/tap_esc/TAP_ESC.cpp index cca2219384..b059ffd346 100644 --- a/src/drivers/tap_esc/TAP_ESC.cpp +++ b/src/drivers/tap_esc/TAP_ESC.cpp @@ -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; } } diff --git a/src/drivers/tap_esc/TAP_ESC.hpp b/src/drivers/tap_esc/TAP_ESC.hpp index 4d7b26f687..1bff40eb8e 100644 --- a/src/drivers/tap_esc/TAP_ESC.hpp +++ b/src/drivers/tap_esc/TAP_ESC.hpp @@ -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};