mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-05-27 10:17:45 +08:00
Dronecan fix beep driver
This commit is contained in:
+12
-19
@@ -45,7 +45,7 @@ UavcanBeep::UavcanBeep(uavcan::INode &node) :
|
|||||||
_beep_pub(node),
|
_beep_pub(node),
|
||||||
_timer(node)
|
_timer(node)
|
||||||
{
|
{
|
||||||
_beep_pub.setPriority(uavcan::TransferPriority::Default);
|
_beep_pub.setPriority(uavcan::TransferPriority::MiddleLower);
|
||||||
}
|
}
|
||||||
|
|
||||||
int UavcanBeep::init()
|
int UavcanBeep::init()
|
||||||
@@ -73,7 +73,10 @@ void UavcanBeep::periodic_update(const uavcan::TimerEvent &)
|
|||||||
|
|
||||||
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);
|
|
||||||
|
if (result == Tunes::ControlResult::Success) {
|
||||||
|
_play_tone = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -89,23 +92,13 @@ void UavcanBeep::periodic_update(const uavcan::TimerEvent &)
|
|||||||
_duration = _silence_length;
|
_duration = _silence_length;
|
||||||
_silence_length = 0;
|
_silence_length = 0;
|
||||||
|
|
||||||
} else if (_play_tone) {
|
} else if (_play_tone && (_tunes.get_next_note(_frequency, _duration, _silence_length) == Tunes::Status::Continue)) {
|
||||||
Tunes::Status parse_ret_val = _tunes.get_next_note(_frequency, _duration, _silence_length);
|
|
||||||
|
|
||||||
if (parse_ret_val == Tunes::Status::Continue) {
|
// Start playing the note.
|
||||||
// Continue playing.
|
// A frequency of 0 corresponds to ToneAlarmInterface::stop_note()
|
||||||
_play_tone = true;
|
uavcan::equipment::indication::BeepCommand cmd{};
|
||||||
|
cmd.frequency = _frequency;
|
||||||
if (_frequency > 0) {
|
cmd.duration = _duration / 1000000.f;
|
||||||
// Start playing the note.
|
_beep_pub.broadcast(cmd);
|
||||||
uavcan::equipment::indication::BeepCommand cmd{};
|
|
||||||
cmd.frequency = _frequency;
|
|
||||||
cmd.duration = _duration / 1000000.f;
|
|
||||||
_beep_pub.broadcast(cmd);
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
_play_tone = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user