mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-05-31 18:47:21 +08:00
drivers/tone_alarm and tune_control small improvements/cleanup
- drivers/tone_alarm: move to ModuleBase and purge CDev (/dev/tone_alarm0) - drivers/tone_alarm: only run on tune_control publication (or scheduled note) rather than continuously - drivers/tone_alarm: use HRT to schedule tone stop (prevents potential disruption) - msg/tune_control: add tune_id numbering - systemcmds/tune_control: add "error" special case tune_id - move all tune_control publication to new uORB::PublicationQueued<> - start tone_alarm immediately after board defaults are loaded to fix potential startup issues - for SITL (or other boards with no TONE output) print common messages (startup, error, etc)
This commit is contained in:
@@ -49,6 +49,8 @@
|
||||
* CIRCUIT BREAKERS ARE NOT PART OF THE STANDARD OPERATION PROCEDURE
|
||||
* AND MAY DISABLE CHECKS THAT ARE VITAL FOR SAFE FLIGHT.
|
||||
*/
|
||||
|
||||
#define CBRK_BUZZER_KEY 782097
|
||||
#define CBRK_SUPPLY_CHK_KEY 894281
|
||||
#define CBRK_RATE_CTRL_KEY 140253
|
||||
#define CBRK_IO_SAFETY_KEY 22027
|
||||
|
||||
@@ -97,12 +97,10 @@ PX4_DEFINE_TUNE(8, BATTERY_WARNING_FAST, "MBNT255a8a8a8a8a8a8a8a8a8a8a8a8a8a8a
|
||||
PX4_DEFINE_TUNE(9, GPS_WARNING, "MFT255L4AAAL1F#", false /* gps warning slow */)
|
||||
PX4_DEFINE_TUNE(10, ARMING_FAILURE, "MFT255L4<<<BAP", false /* arming failure tune */)
|
||||
PX4_DEFINE_TUNE(11, PARACHUTE_RELEASE, "MFT255L16agagagag", false /* parachute release */)
|
||||
PX4_DEFINE_TUNE(12, EKF_WARNING, "MFT255L8ddd#d#eeff", false /* ekf warning */)
|
||||
PX4_DEFINE_TUNE(13, BARO_WARNING, "MFT255L4gf#fed#d", false /* baro warning */)
|
||||
PX4_DEFINE_TUNE(14, SINGLE_BEEP, "MFT100a8", false /* single beep */)
|
||||
PX4_DEFINE_TUNE(15, HOME_SET, "MFT100L4>G#6A#6B#4", false /* home set tune */)
|
||||
PX4_DEFINE_TUNE(16, SD_INIT, "MFAGPAG", false /* Make FS */)
|
||||
PX4_DEFINE_TUNE(17, SD_ERROR, "MNBG", false /* format failed */)
|
||||
PX4_DEFINE_TUNE(18, PROG_PX4IO, "MLL32CP8MB", false /* Program PX4IO */)
|
||||
PX4_DEFINE_TUNE(19, PROG_PX4IO_OK, "MLL8CDE", false /* Program PX4IO success */)
|
||||
PX4_DEFINE_TUNE(20, PROG_PX4IO_ERR, "ML<<CP4CP4CP4CP4CP4", true /* Program PX4IO fail */)
|
||||
PX4_DEFINE_TUNE(12, SINGLE_BEEP, "MFT100a8", false /* single beep */)
|
||||
PX4_DEFINE_TUNE(13, HOME_SET, "MFT100L4>G#6A#6B#4", false /* home set tune */)
|
||||
PX4_DEFINE_TUNE(14, SD_INIT, "MFAGPAG", false /* Make FS */)
|
||||
PX4_DEFINE_TUNE(15, SD_ERROR, "MNBG", false /* format failed */)
|
||||
PX4_DEFINE_TUNE(16, PROG_PX4IO, "MLL32CP8MB", false /* Program PX4IO */)
|
||||
PX4_DEFINE_TUNE(17, PROG_PX4IO_OK, "MLL8CDE", false /* Program PX4IO success */)
|
||||
PX4_DEFINE_TUNE(18, PROG_PX4IO_ERR, "ML<<CP4CP4CP4CP4CP4", true /* Program PX4IO fail */)
|
||||
|
||||
+12
-18
@@ -42,10 +42,6 @@
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
|
||||
#define TUNE_CONTINUE 1
|
||||
#define TUNE_ERROR -1
|
||||
#define TUNE_STOP 0
|
||||
|
||||
#define BEAT_TIME_CONVERSION_MS (60 * 1000 * 4)
|
||||
#define BEAT_TIME_CONVERSION_US BEAT_TIME_CONVERSION_MS * 1000
|
||||
#define BEAT_TIME_CONVERSION BEAT_TIME_CONVERSION_US
|
||||
@@ -153,10 +149,9 @@ void Tunes::set_string(const char *const string, uint8_t volume)
|
||||
}
|
||||
}
|
||||
|
||||
int Tunes::get_next_note(unsigned &frequency, unsigned &duration,
|
||||
unsigned &silence, uint8_t &volume)
|
||||
Tunes::Status Tunes::get_next_note(unsigned &frequency, unsigned &duration, unsigned &silence, uint8_t &volume)
|
||||
{
|
||||
int ret = get_next_note(frequency, duration, silence);
|
||||
Tunes::Status ret = get_next_note(frequency, duration, silence);
|
||||
|
||||
// Check if note should not be heard -> adjust volume to 0 to be safe.
|
||||
if (frequency == 0 || duration == 0) {
|
||||
@@ -169,8 +164,7 @@ int Tunes::get_next_note(unsigned &frequency, unsigned &duration,
|
||||
return ret;
|
||||
}
|
||||
|
||||
int Tunes::get_next_note(unsigned &frequency, unsigned &duration,
|
||||
unsigned &silence)
|
||||
Tunes::Status Tunes::get_next_note(unsigned &frequency, unsigned &duration, unsigned &silence)
|
||||
{
|
||||
// Return the values for frequency and duration if the custom msg was received.
|
||||
if (_using_custom_msg) {
|
||||
@@ -178,7 +172,7 @@ int Tunes::get_next_note(unsigned &frequency, unsigned &duration,
|
||||
duration = _duration;
|
||||
frequency = _frequency;
|
||||
silence = _silence;
|
||||
return TUNE_CONTINUE;
|
||||
return Tunes::Status::Continue;
|
||||
}
|
||||
|
||||
// Make sure we still have a tune.
|
||||
@@ -274,7 +268,7 @@ int Tunes::get_next_note(unsigned &frequency, unsigned &duration,
|
||||
frequency = 0;
|
||||
duration = 0;
|
||||
silence = rest_duration(next_number(), next_dots());
|
||||
return TUNE_CONTINUE;
|
||||
return Tunes::Status::Continue;
|
||||
|
||||
case 'T': { // Change tempo.
|
||||
unsigned nt = next_number();
|
||||
@@ -299,7 +293,7 @@ int Tunes::get_next_note(unsigned &frequency, unsigned &duration,
|
||||
if (note == 0) {
|
||||
// This is a rest - pause for the current note length.
|
||||
silence = rest_duration(_note_length, next_dots());
|
||||
return TUNE_CONTINUE;
|
||||
return Tunes::Status::Continue;
|
||||
}
|
||||
|
||||
break;
|
||||
@@ -350,29 +344,29 @@ int Tunes::get_next_note(unsigned &frequency, unsigned &duration,
|
||||
|
||||
// Compute the note frequency.
|
||||
frequency = note_to_frequency(note);
|
||||
return TUNE_CONTINUE;
|
||||
return Tunes::Status::Continue;
|
||||
}
|
||||
|
||||
int Tunes::tune_end()
|
||||
Tunes::Status Tunes::tune_end()
|
||||
{
|
||||
// Restore intial parameters.
|
||||
reset(_repeat);
|
||||
|
||||
// Stop or restart the tune.
|
||||
if (_repeat) {
|
||||
return TUNE_CONTINUE;
|
||||
return Tunes::Status::Continue;
|
||||
|
||||
} else {
|
||||
return TUNE_STOP;
|
||||
return Tunes::Status::Stop;
|
||||
}
|
||||
}
|
||||
|
||||
int Tunes::tune_error()
|
||||
Tunes::Status Tunes::tune_error()
|
||||
{
|
||||
// The tune appears to be bad (unexpected EOF, bad character, etc.).
|
||||
_repeat = false; // Don't loop on error.
|
||||
reset(_repeat);
|
||||
return TUNE_ERROR;
|
||||
return Tunes::Status::Error;
|
||||
}
|
||||
|
||||
uint32_t Tunes::note_to_frequency(unsigned note) const
|
||||
|
||||
+11
-5
@@ -58,6 +58,12 @@ class Tunes
|
||||
public:
|
||||
enum class NoteMode {NORMAL, LEGATO, STACCATO};
|
||||
|
||||
enum class Status {
|
||||
Continue = 1,
|
||||
Stop = 0,
|
||||
Error = -1,
|
||||
};
|
||||
|
||||
/**
|
||||
* Constructor with the default parameters set to:
|
||||
* default_tempo: TUNE_DEFAULT_TEMPO
|
||||
@@ -99,7 +105,7 @@ public:
|
||||
* @param silence return silence duration (us)
|
||||
* @return -1 for error, 0 for play one tone and 1 for continue a sequence
|
||||
*/
|
||||
int get_next_note(unsigned &frequency, unsigned &duration, unsigned &silence);
|
||||
Tunes::Status get_next_note(unsigned &frequency, unsigned &duration, unsigned &silence);
|
||||
|
||||
/**
|
||||
* Get next note in the current tune, which has been provided by either
|
||||
@@ -110,8 +116,8 @@ public:
|
||||
* @param volume return the volume level of the note (between 0-100)
|
||||
* @return -1 for no tune available/error, 0 to not play anything and 1 to play
|
||||
*/
|
||||
int get_next_note(unsigned &frequency, unsigned &duration,
|
||||
unsigned &silence, uint8_t &volume);
|
||||
Tunes::Status get_next_note(unsigned &frequency, unsigned &duration,
|
||||
unsigned &silence, uint8_t &volume);
|
||||
|
||||
/**
|
||||
* Get the number of default tunes. This is useful for when a tune is
|
||||
@@ -182,9 +188,9 @@ private:
|
||||
*/
|
||||
void reset(bool repeat_flag);
|
||||
|
||||
int tune_end();
|
||||
Tunes::Status tune_end();
|
||||
|
||||
int tune_error();
|
||||
Tunes::Status tune_error();
|
||||
|
||||
static const char *const _default_tunes[];
|
||||
static const bool _default_tunes_interruptable[];
|
||||
|
||||
Reference in New Issue
Block a user