mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-31 01:21:36 +08:00
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:
@@ -365,31 +365,26 @@ void TAP_ESC::Run()
|
|||||||
if (_tune_control_sub.copy(&tune)) {
|
if (_tune_control_sub.copy(&tune)) {
|
||||||
if (tune.timestamp > 0) {
|
if (tune.timestamp > 0) {
|
||||||
Tunes::ControlResult result = _tunes.set_control(tune);
|
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, duration: %lu", tune.tune_id, (int)result, tune.duration);
|
||||||
PX4_DEBUG("new tune id: %d, result: %d, play: %d", tune.tune_id, (int)result, _play_tone);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const hrt_abstime timestamp_now = hrt_absolute_time();
|
const hrt_abstime timestamp_now = hrt_absolute_time();
|
||||||
|
|
||||||
if ((timestamp_now - _interval_timestamp <= _duration) || !_play_tone) {
|
if ((timestamp_now - _interval_timestamp > _duration)) {
|
||||||
//return;
|
|
||||||
} else {
|
|
||||||
_interval_timestamp = timestamp_now;
|
_interval_timestamp = timestamp_now;
|
||||||
|
|
||||||
if (_silence_length > 0) {
|
if (_silence_length > 0) {
|
||||||
_duration = _silence_length;
|
_duration = _silence_length;
|
||||||
_silence_length = 0;
|
_silence_length = 0;
|
||||||
|
|
||||||
} else if (_play_tone) {
|
} else {
|
||||||
uint8_t strength = 0;
|
uint8_t strength = 0;
|
||||||
Tunes::Status parse_ret_val = _tunes.get_next_note(_frequency, _duration, _silence_length, strength);
|
Tunes::Status parse_ret_val = _tunes.get_next_note(_frequency, _duration, _silence_length, strength);
|
||||||
|
|
||||||
if (parse_ret_val == Tunes::Status::Continue) {
|
if (parse_ret_val == Tunes::Status::Continue) {
|
||||||
// Continue playing.
|
// Continue playing.
|
||||||
_play_tone = true;
|
|
||||||
|
|
||||||
if (_frequency > 0) {
|
if (_frequency > 0) {
|
||||||
// Start playing the note.
|
// Start playing the note.
|
||||||
EscbusTunePacket esc_tune_packet{};
|
EscbusTunePacket esc_tune_packet{};
|
||||||
@@ -400,7 +395,6 @@ void TAP_ESC::Run()
|
|||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
_play_tone = false;
|
|
||||||
_silence_length = 0;
|
_silence_length = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -134,7 +134,6 @@ private:
|
|||||||
Tunes _tunes{};
|
Tunes _tunes{};
|
||||||
uORB::Subscription _tune_control_sub{ORB_ID(tune_control)};
|
uORB::Subscription _tune_control_sub{ORB_ID(tune_control)};
|
||||||
hrt_abstime _interval_timestamp{0};
|
hrt_abstime _interval_timestamp{0};
|
||||||
bool _play_tone{false};
|
|
||||||
unsigned int _silence_length{0}; ///< If nonzero, silence before next note.
|
unsigned int _silence_length{0}; ///< If nonzero, silence before next note.
|
||||||
unsigned int _frequency{0};
|
unsigned int _frequency{0};
|
||||||
unsigned int _duration{0};
|
unsigned int _duration{0};
|
||||||
|
|||||||
Reference in New Issue
Block a user