mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-06-04 21:23:57 +08:00
Remove unused tones and save about 6K flash space
- Comment out unused tones - Create symbolic tone numbers rather than hardcoded
This commit is contained in:
@@ -125,4 +125,24 @@ enum tone_pitch {
|
|||||||
TONE_NOTE_MAX
|
TONE_NOTE_MAX
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum {
|
||||||
|
TONE_STOP_TUNE = 0,
|
||||||
|
TONE_STARTUP_TUNE,
|
||||||
|
TONE_ERROR_TUNE,
|
||||||
|
TONE_NOTIFY_POSITIVE_TUNE,
|
||||||
|
TONE_NOTIFY_NEUTRAL_TUNE,
|
||||||
|
TONE_NOTIFY_NEGATIVE_TUNE,
|
||||||
|
TONE_CHARGE_TUNE,
|
||||||
|
/* Do not include these unused tunes
|
||||||
|
TONE_DIXIE_TUNE,
|
||||||
|
TONE_CUCURACHA_TUNE,
|
||||||
|
TONE_YANKEE_TUNE,
|
||||||
|
TONE_DAISY_TUNE,
|
||||||
|
TONE_WILLIAM_TELL_TUNE, */
|
||||||
|
TONE_ARMING_WARNING_TUNE,
|
||||||
|
TONE_BATTERY_WARNING_SLOW_TUNE,
|
||||||
|
TONE_BATTERY_WARNING_FAST_TUNE,
|
||||||
|
TONE_NUMBER_OF_TUNES
|
||||||
|
};
|
||||||
|
|
||||||
#endif /* DRV_TONE_ALARM_H_ */
|
#endif /* DRV_TONE_ALARM_H_ */
|
||||||
|
|||||||
@@ -233,8 +233,7 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
static const unsigned _tune_max = 1024; // be reasonable about user tunes
|
static const unsigned _tune_max = 1024; // be reasonable about user tunes
|
||||||
static const char * const _default_tunes[];
|
static const char * _default_tunes[TONE_NUMBER_OF_TUNES - 1];
|
||||||
static const unsigned _default_ntunes;
|
|
||||||
static const uint8_t _note_tab[];
|
static const uint8_t _note_tab[];
|
||||||
|
|
||||||
unsigned _default_tune_number; // number of currently playing default tune (0 for none)
|
unsigned _default_tune_number; // number of currently playing default tune (0 for none)
|
||||||
@@ -305,17 +304,40 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
// predefined tune array
|
// predefined tune array
|
||||||
const char * const ToneAlarm::_default_tunes[] = {
|
const char * ToneAlarm::_default_tunes[TONE_NUMBER_OF_TUNES - 1];
|
||||||
"MFT240L8 O4aO5dc O4aO5dc O4aO5dc L16dcdcdcdc", // startup tune
|
|
||||||
"MBT200a8a8a8PaaaP", // ERROR tone
|
// semitone offsets from C for the characters 'A'-'G'
|
||||||
"MFT200e8a8a", // NotifyPositive tone
|
const uint8_t ToneAlarm::_note_tab[] = {9, 11, 0, 2, 4, 5, 7};
|
||||||
"MFT200e8e", // NotifyNeutral tone
|
|
||||||
"MFT200e8c8e8c8e8c8", // NotifyNegative tone
|
/*
|
||||||
"MFT90O3C16.C32C16.C32C16.C32G16.E32G16.E32G16.E32C16.C32C16.C32C16.C32G16.E32G16.E32G16.E32C4", // charge!
|
* Driver 'main' command.
|
||||||
"MFT60O3C32O2A32F16F16F32G32A32A+32O3C16C16C16O2A16", // dixie
|
*/
|
||||||
"MFT90O2C16C16C16F8.A8C16C16C16F8.A4P16P8", // cucuracha
|
extern "C" __EXPORT int tone_alarm_main(int argc, char *argv[]);
|
||||||
"MNT150L8O2GGABGBADGGABL4GL8F+", // yankee
|
|
||||||
"MFT200O3C4.O2A4.G4.F4.D8E8F8D4F8C2.O2G4.O3C4.O2A4.F4.D8E8F8G4A8G2P8", // daisy
|
|
||||||
|
ToneAlarm::ToneAlarm() :
|
||||||
|
CDev("tone_alarm", "/dev/tone_alarm"),
|
||||||
|
_default_tune_number(0),
|
||||||
|
_user_tune(nullptr),
|
||||||
|
_tune(nullptr),
|
||||||
|
_next(nullptr)
|
||||||
|
{
|
||||||
|
// enable debug() calls
|
||||||
|
//_debug_enabled = true;
|
||||||
|
_default_tunes[TONE_STARTUP_TUNE - 1] = "MFT240L8 O4aO5dc O4aO5dc O4aO5dc L16dcdcdcdc"; // startup tune
|
||||||
|
_default_tunes[TONE_ERROR_TUNE - 1] = "MBT200a8a8a8PaaaP"; // ERROR tone
|
||||||
|
_default_tunes[TONE_NOTIFY_POSITIVE_TUNE - 1] = "MFT200e8a8a"; // NotifyPositive tone
|
||||||
|
_default_tunes[TONE_NOTIFY_NEUTRAL_TUNE - 1] = "MFT200e8e"; // NotifyNeutral tone
|
||||||
|
_default_tunes[TONE_NOTIFY_NEGATIVE_TUNE - 1] = "MFT200e8c8e8c8e8c8"; // NotifyNegative tone
|
||||||
|
_default_tunes[TONE_CHARGE_TUNE - 1] =
|
||||||
|
"MFT90O3C16.C32C16.C32C16.C32G16.E32G16.E32G16.E32C16.C32C16.C32C16.C32G16.E32G16.E32G16.E32C4"; // charge!
|
||||||
|
#if 0 // don't include unused tunes... but keep them for nostalgic reason
|
||||||
|
_default_tunes[TONE_DIXIE_TUNE - 1] = "MFT60O3C32O2A32F16F16F32G32A32A+32O3C16C16C16O2A16"; // dixie
|
||||||
|
_default_tunes[TONE_CUCURACHA_TUNE - 1] = "MFT90O2C16C16C16F8.A8C16C16C16F8.A4P16P8"; // cucuracha
|
||||||
|
_default_tunes[TONE_YANKEE_TUNE - 1] = "MNT150L8O2GGABGBADGGABL4GL8F+"; // yankee
|
||||||
|
_default_tunes[TONE_DAISY_TUNE - 1] =
|
||||||
|
"MFT200O3C4.O2A4.G4.F4.D8E8F8D4F8C2.O2G4.O3C4.O2A4.F4.D8E8F8G4A8G2P8"; // daisy
|
||||||
|
_default_tunes[TONE_WILLIAM_TELL_TUNE - 1] =
|
||||||
"T200O2B4P8B16B16B4P8B16B16B8G+8E8G+8B8G+8B8O3E8" // william tell
|
"T200O2B4P8B16B16B4P8B16B16B8G+8E8G+8B8G+8B8O3E8" // william tell
|
||||||
"O2B8G+8E8G+8B8G+8B8O3E8O2B4P8B16B16B4P8B16"
|
"O2B8G+8E8G+8B8G+8B8O3E8O2B4P8B16B16B4P8B16"
|
||||||
"O2B16B4P8B16B16B4P8B16B16B8B16B16B8B8B8B16"
|
"O2B16B4P8B16B16B4P8B16B16B8B16B16B8B8B8B16"
|
||||||
@@ -453,32 +475,11 @@ const char * const ToneAlarm::_default_tunes[] = {
|
|||||||
"O2B8B8G+16G+16G+8G+8G+8E16E16E8E8E8O1B8O2E8"
|
"O2B8B8G+16G+16G+8G+8G+8E16E16E8E8E8O1B8O2E8"
|
||||||
"O1B8O2G+8E8B8G+8O3E8O2B8O3E8O2B8O3G+8E8B8"
|
"O1B8O2G+8E8B8G+8O3E8O2B8O3E8O2B8O3G+8E8B8"
|
||||||
"O3G+8O4E4P8E16E16E8E8E8E8E4P8E16E4P8O2E16"
|
"O3G+8O4E4P8E16E16E8E8E8E8E4P8E16E4P8O2E16"
|
||||||
"O2E2P64",
|
"O2E2P64";
|
||||||
"MNT75L1O2G", //arming warning
|
#endif
|
||||||
"MBNT100a8", //battery warning slow
|
_default_tunes[TONE_ARMING_WARNING_TUNE - 1] = "MNT75L1O2G"; //arming warning
|
||||||
"MBNT255a8a8a8a8a8a8a8a8a8a8a8a8a8a8a8a8" //battery warning fast // XXX why is there a break before a repetition
|
_default_tunes[TONE_BATTERY_WARNING_SLOW_TUNE - 1] = "MBNT100a8"; //battery warning slow
|
||||||
};
|
_default_tunes[TONE_BATTERY_WARNING_FAST_TUNE - 1] = "MBNT255a8a8a8a8a8a8a8a8a8a8a8a8a8a8a8a8"; //battery warning fast
|
||||||
|
|
||||||
const unsigned ToneAlarm::_default_ntunes = sizeof(_default_tunes) / sizeof(_default_tunes[0]);
|
|
||||||
|
|
||||||
// semitone offsets from C for the characters 'A'-'G'
|
|
||||||
const uint8_t ToneAlarm::_note_tab[] = {9, 11, 0, 2, 4, 5, 7};
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Driver 'main' command.
|
|
||||||
*/
|
|
||||||
extern "C" __EXPORT int tone_alarm_main(int argc, char *argv[]);
|
|
||||||
|
|
||||||
|
|
||||||
ToneAlarm::ToneAlarm() :
|
|
||||||
CDev("tone_alarm", "/dev/tone_alarm"),
|
|
||||||
_default_tune_number(0),
|
|
||||||
_user_tune(nullptr),
|
|
||||||
_tune(nullptr),
|
|
||||||
_next(nullptr)
|
|
||||||
{
|
|
||||||
// enable debug() calls
|
|
||||||
//_debug_enabled = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ToneAlarm::~ToneAlarm()
|
ToneAlarm::~ToneAlarm()
|
||||||
@@ -873,7 +874,7 @@ ToneAlarm::ioctl(file *filp, int cmd, unsigned long arg)
|
|||||||
case TONE_SET_ALARM:
|
case TONE_SET_ALARM:
|
||||||
debug("TONE_SET_ALARM %u", arg);
|
debug("TONE_SET_ALARM %u", arg);
|
||||||
|
|
||||||
if (arg <= _default_ntunes) {
|
if (arg <= TONE_NUMBER_OF_TUNES) {
|
||||||
if (arg == 0) {
|
if (arg == 0) {
|
||||||
// stop the tune
|
// stop the tune
|
||||||
_tune = nullptr;
|
_tune = nullptr;
|
||||||
@@ -1008,10 +1009,10 @@ tone_alarm_main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ((argc > 1) && !strcmp(argv[1], "start"))
|
if ((argc > 1) && !strcmp(argv[1], "start"))
|
||||||
play_tune(1);
|
play_tune(TONE_STARTUP_TUNE);
|
||||||
|
|
||||||
if ((argc > 1) && !strcmp(argv[1], "stop"))
|
if ((argc > 1) && !strcmp(argv[1], "stop"))
|
||||||
play_tune(0);
|
play_tune(TONE_STOP_TUNE);
|
||||||
|
|
||||||
if ((tune = strtol(argv[1], nullptr, 10)) != 0)
|
if ((tune = strtol(argv[1], nullptr, 10)) != 0)
|
||||||
play_tune(tune);
|
play_tune(tune);
|
||||||
|
|||||||
@@ -99,44 +99,44 @@ void buzzer_deinit()
|
|||||||
|
|
||||||
void tune_error()
|
void tune_error()
|
||||||
{
|
{
|
||||||
ioctl(buzzer, TONE_SET_ALARM, 2);
|
ioctl(buzzer, TONE_SET_ALARM, TONE_ERROR_TUNE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void tune_positive()
|
void tune_positive()
|
||||||
{
|
{
|
||||||
ioctl(buzzer, TONE_SET_ALARM, 3);
|
ioctl(buzzer, TONE_SET_ALARM, TONE_NOTIFY_POSITIVE_TUNE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void tune_neutral()
|
void tune_neutral()
|
||||||
{
|
{
|
||||||
ioctl(buzzer, TONE_SET_ALARM, 4);
|
ioctl(buzzer, TONE_SET_ALARM, TONE_NOTIFY_NEUTRAL_TUNE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void tune_negative()
|
void tune_negative()
|
||||||
{
|
{
|
||||||
ioctl(buzzer, TONE_SET_ALARM, 5);
|
ioctl(buzzer, TONE_SET_ALARM, TONE_NOTIFY_NEGATIVE_TUNE);
|
||||||
}
|
}
|
||||||
|
|
||||||
int tune_arm()
|
int tune_arm()
|
||||||
{
|
{
|
||||||
return ioctl(buzzer, TONE_SET_ALARM, 12);
|
return ioctl(buzzer, TONE_SET_ALARM, TONE_ARMING_WARNING_TUNE);
|
||||||
}
|
}
|
||||||
|
|
||||||
int tune_low_bat()
|
int tune_low_bat()
|
||||||
{
|
{
|
||||||
return ioctl(buzzer, TONE_SET_ALARM, 13);
|
return ioctl(buzzer, TONE_SET_ALARM, TONE_BATTERY_WARNING_SLOW_TUNE);
|
||||||
}
|
}
|
||||||
|
|
||||||
int tune_critical_bat()
|
int tune_critical_bat()
|
||||||
{
|
{
|
||||||
return ioctl(buzzer, TONE_SET_ALARM, 14);
|
return ioctl(buzzer, TONE_SET_ALARM, TONE_BATTERY_WARNING_FAST_TUNE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void tune_stop()
|
void tune_stop()
|
||||||
{
|
{
|
||||||
ioctl(buzzer, TONE_SET_ALARM, 0);
|
ioctl(buzzer, TONE_SET_ALARM, TONE_STOP_TUNE);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int leds;
|
static int leds;
|
||||||
|
|||||||
@@ -176,15 +176,15 @@ system_eval:
|
|||||||
led_toggle(leds, LED_AMBER);
|
led_toggle(leds, LED_AMBER);
|
||||||
|
|
||||||
if (i % 10 == 0) {
|
if (i % 10 == 0) {
|
||||||
ioctl(buzzer, TONE_SET_ALARM, 4);
|
ioctl(buzzer, TONE_SET_ALARM, TONE_NOTIFY_NEUTRAL_TUNE);
|
||||||
} else if (i % 5 == 0) {
|
} else if (i % 5 == 0) {
|
||||||
ioctl(buzzer, TONE_SET_ALARM, 2);
|
ioctl(buzzer, TONE_SET_ALARM, TONE_ERROR_TUNE);
|
||||||
}
|
}
|
||||||
usleep(100000);
|
usleep(100000);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* stop alarm */
|
/* stop alarm */
|
||||||
ioctl(buzzer, TONE_SET_ALARM, 0);
|
ioctl(buzzer, TONE_SET_ALARM, TONE_STOP_TUNE);
|
||||||
|
|
||||||
/* switch on leds */
|
/* switch on leds */
|
||||||
led_on(leds, LED_BLUE);
|
led_on(leds, LED_BLUE);
|
||||||
|
|||||||
@@ -137,7 +137,7 @@ int test_tone(int argc, char *argv[])
|
|||||||
tone = atoi(argv[1]);
|
tone = atoi(argv[1]);
|
||||||
|
|
||||||
if (tone == 0) {
|
if (tone == 0) {
|
||||||
result = ioctl(fd, TONE_SET_ALARM, 0);
|
result = ioctl(fd, TONE_SET_ALARM, TONE_STOP_TUNE);
|
||||||
|
|
||||||
if (result < 0) {
|
if (result < 0) {
|
||||||
printf("failed clearing alarms\n");
|
printf("failed clearing alarms\n");
|
||||||
@@ -148,7 +148,7 @@ int test_tone(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
result = ioctl(fd, TONE_SET_ALARM, 0);
|
result = ioctl(fd, TONE_SET_ALARM, TONE_STOP_TUNE);
|
||||||
|
|
||||||
if (result < 0) {
|
if (result < 0) {
|
||||||
printf("failed clearing alarms\n");
|
printf("failed clearing alarms\n");
|
||||||
|
|||||||
Reference in New Issue
Block a user