diff options
author | px4dev <px4@purgatory.org> | 2013-03-10 00:29:19 -0800 |
---|---|---|
committer | px4dev <px4@purgatory.org> | 2013-03-10 00:29:19 -0800 |
commit | 02fc6812d4dcc06ba8eb64d24a21aff35af241aa (patch) | |
tree | 432da96a2cd0b7c893cd4d21c7d9c56f32db8404 | |
parent | 0d9d009961d9c276328cacff188837dc5f4f35ac (diff) | |
download | px4-firmware-02fc6812d4dcc06ba8eb64d24a21aff35af241aa.tar.gz px4-firmware-02fc6812d4dcc06ba8eb64d24a21aff35af241aa.tar.bz2 px4-firmware-02fc6812d4dcc06ba8eb64d24a21aff35af241aa.zip |
Add support for arbitrary user tunes on the commandline.
-rw-r--r-- | apps/drivers/stm32/tone_alarm/tone_alarm.cpp | 39 |
1 files changed, 34 insertions, 5 deletions
diff --git a/apps/drivers/stm32/tone_alarm/tone_alarm.cpp b/apps/drivers/stm32/tone_alarm/tone_alarm.cpp index a43bcf38f..4db2fcd02 100644 --- a/apps/drivers/stm32/tone_alarm/tone_alarm.cpp +++ b/apps/drivers/stm32/tone_alarm/tone_alarm.cpp @@ -307,11 +307,11 @@ private: // predefined tune array const char *ToneAlarm::_default_tunes[] = { - "MFT240L8 O4aO5dc O4aO5dc O4aO5dc L16dcdcdcdc", // startup tune - "MBMLA", // continuous 440Hz A - "MFO4T32c1c1c1c1c1c1c1c1", // 1second c4 - "MFO4T32d1d1d1d1d1d1d1d1", // 1second d4 - "MFO4T32e1e1e1e1e1e1e1e1", // 1second e4 + "MFT240L8 O4aO5dc O4aO5dc O4aO5dc L16dcdcdcdc", // startup tune + "MBMLA", // continuous A + "MFO4TML60c", // 1second c4 (placeholder) + "MFO4TML60d", // 1second d4 (placeholder) + "MFO4TML60e", // 1second e4 (placeholder) "MFT90O3C16.C32C16.C32C16.C32G16.E32G16.E32G16.E32C16.C32C16.C32C16.C32G16.E32G16.E32G16.E32C4", // charge! "MFT60O3C32O2A32F16F16F32G32A32A+32O3C16C16C16O2A16", // dixie "MFT90O2C16C16C16F8.A8C16C16C16F8.A4P16P8", // cucuracha @@ -402,6 +402,8 @@ ToneAlarm::note_duration(unsigned &silence, unsigned note_length, unsigned dots) { unsigned whole_note_period = (60 * 1000000 * 4) / _tempo; + if (note_length == 0) + note_length = 1; unsigned note_period = whole_note_period / note_length; switch (_note_mode) { @@ -794,6 +796,7 @@ play_tune(unsigned tune) err(1, "/dev/tone_alarm"); ret = ioctl(fd, TONE_SET_ALARM, tune); + close(fd); if (ret != 0) err(1, "TONE_SET_ALARM"); @@ -801,6 +804,24 @@ play_tune(unsigned tune) exit(0); } +int +play_string(const char *str) +{ + int fd, ret; + + fd = open("/dev/tone_alarm", O_WRONLY); + + if (fd < 0) + err(1, "/dev/tone_alarm"); + + ret = write(fd, str, strlen(str) + 1); + close(fd); + + if (ret < 0) + err(1, "play tune"); + exit(0); +} + } // namespace int @@ -830,5 +851,13 @@ tone_alarm_main(int argc, char *argv[]) if ((tune = strtol(argv[1], nullptr, 10)) != 0) play_tune(tune); + /* if it looks like a PLAY string... */ + if (strlen(argv[1]) > 2) { + const char *str = argv[1]; + if ((str[0] == 'M') && (str[1] == 'F')) { + play_string(str); + } + } + errx(1, "unrecognised command, try 'start', 'stop' or an alarm number"); } |