Don't interrupt a playing tune unless its a repeated one

This commit is contained in:
Julian Oes 2013-06-25 13:11:15 +02:00
parent 794a2248f0
commit 2096da2d4d
1 changed files with 25 additions and 4 deletions

View File

@ -1,6 +1,6 @@
/**************************************************************************** /****************************************************************************
* *
* Copyright (C) 2012 PX4 Development Team. All rights reserved. * Copyright (C) 2013 PX4 Development Team. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
@ -241,6 +241,8 @@ private:
static const unsigned _default_ntunes; 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)
const char *_user_tune; const char *_user_tune;
const char *_tune; // current tune string const char *_tune; // current tune string
@ -456,6 +458,11 @@ const char * const ToneAlarm::_default_tunes[] = {
"O1B8O2G+8E8B8G+8O3E8O2B8O3E8O2B8O3G+8E8B8" "O1B8O2G+8E8B8G+8O3E8O2B8O3E8O2B8O3G+8E8B8"
"O3G+8O4E4P8E16E16E8E8E8E8E4P8E16E4P8O2E16" "O3G+8O4E4P8E16E16E8E8E8E8E4P8E16E4P8O2E16"
"O2E2P64", "O2E2P64",
"MNT75L1O2G", //arming warning
"MBNT100a8", //battery warning slow
"MBNT255a8a8a8a8a8a8a8a8a8a8a8a8a8a8a8a8"
"a8a8a8a8a8a8a8a8a8a8a8a8a8a8a8a8"
"a8a8a8a8a8a8a8a8a8a8a8a8a8a8a8a8", //battery warning fast // XXX why is there a break before a repetition
}; };
const unsigned ToneAlarm::_default_ntunes = sizeof(_default_tunes) / sizeof(_default_tunes[0]); const unsigned ToneAlarm::_default_ntunes = sizeof(_default_tunes) / sizeof(_default_tunes[0]);
@ -471,6 +478,7 @@ extern "C" __EXPORT int tone_alarm_main(int argc, char *argv[]);
ToneAlarm::ToneAlarm() : ToneAlarm::ToneAlarm() :
CDev("tone_alarm", "/dev/tone_alarm"), CDev("tone_alarm", "/dev/tone_alarm"),
_default_tune_number(0),
_user_tune(nullptr), _user_tune(nullptr),
_tune(nullptr), _tune(nullptr),
_next(nullptr) _next(nullptr)
@ -803,8 +811,12 @@ tune_error:
// stop (and potentially restart) the tune // stop (and potentially restart) the tune
tune_end: tune_end:
stop_note(); stop_note();
if (_repeat) if (_repeat) {
start_tune(_tune); start_tune(_tune);
} else {
_tune = nullptr;
_default_tune_number = 0;
}
return; return;
} }
@ -872,10 +884,19 @@ ToneAlarm::ioctl(file *filp, int cmd, unsigned long arg)
// stop the tune // stop the tune
_tune = nullptr; _tune = nullptr;
_next = nullptr; _next = nullptr;
} else {
/* don't interrupt alarms unless they are repeated */
if (_tune != nullptr && !_repeat) {
/* abort and let the current tune finish */
result = -EBUSY;
} else if (_repeat && _default_tune_number == arg) {
/* requested repeating tune already playing */
} else { } else {
// play the selected tune // play the selected tune
_default_tune_number = arg;
start_tune(_default_tunes[arg - 1]); start_tune(_default_tunes[arg - 1]);
} }
}
} else { } else {
result = -EINVAL; result = -EINVAL;
} }