2013-09-15 05:24:00 -03:00
|
|
|
/*
|
2018-07-25 13:53:33 -03:00
|
|
|
* AP_ToneAlarm driver
|
2018-07-24 22:30:05 -03:00
|
|
|
*/
|
2013-09-15 05:24:00 -03:00
|
|
|
/*
|
2018-07-24 22:30:05 -03:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2013-09-15 05:24:00 -03:00
|
|
|
*/
|
|
|
|
|
2015-08-11 03:28:44 -03:00
|
|
|
#include <AP_HAL/AP_HAL.h>
|
2018-07-24 23:24:53 -03:00
|
|
|
#include <AP_Math/AP_Math.h>
|
2013-09-15 05:24:00 -03:00
|
|
|
|
2018-07-24 22:30:05 -03:00
|
|
|
#include "ToneAlarm.h"
|
2013-09-15 05:24:00 -03:00
|
|
|
#include "AP_Notify.h"
|
|
|
|
|
2014-10-23 09:04:34 -03:00
|
|
|
#include <string.h>
|
2013-09-15 05:24:00 -03:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2019-08-01 02:14:11 -03:00
|
|
|
#include <AP_Filesystem/AP_Filesystem.h>
|
2019-07-11 00:41:06 -03:00
|
|
|
|
2013-09-15 05:24:00 -03:00
|
|
|
extern const AP_HAL::HAL& hal;
|
|
|
|
|
2019-07-03 03:15:54 -03:00
|
|
|
// Tunes follow the syntax of the Microsoft GWBasic/QBasic PLAY
|
|
|
|
// statement, with some exceptions and extensions.
|
2019-12-07 16:43:52 -04:00
|
|
|
// See https://firmware.ardupilot.org/Tools/ToneTester/
|
2018-07-25 13:53:33 -03:00
|
|
|
const AP_ToneAlarm::Tone AP_ToneAlarm::_tones[] {
|
2018-07-24 23:00:24 -03:00
|
|
|
#define AP_NOTIFY_TONE_QUIET_NEG_FEEDBACK 0
|
2014-10-23 09:04:34 -03:00
|
|
|
{ "MFT200L4<<<B#A#2", false },
|
2018-07-24 23:00:24 -03:00
|
|
|
#define AP_NOTIFY_TONE_LOUD_NEG_FEEDBACK 1
|
2014-10-23 09:04:34 -03:00
|
|
|
{ "MFT100L4>B#A#2P8B#A#2", false },
|
2018-07-24 23:00:24 -03:00
|
|
|
#define AP_NOTIFY_TONE_QUIET_NEU_FEEDBACK 2
|
2014-10-23 09:04:34 -03:00
|
|
|
{ "MFT200L4<B#", false },
|
2018-07-24 23:00:24 -03:00
|
|
|
#define AP_NOTIFY_TONE_LOUD_NEU_FEEDBACK 3
|
2014-10-23 09:04:34 -03:00
|
|
|
{ "MFT100L4>B#", false },
|
2018-07-24 23:00:24 -03:00
|
|
|
#define AP_NOTIFY_TONE_QUIET_POS_FEEDBACK 4
|
2014-10-23 09:04:34 -03:00
|
|
|
{ "MFT200L4<A#B#", false },
|
2018-07-24 23:00:24 -03:00
|
|
|
#define AP_NOTIFY_TONE_LOUD_POS_FEEDBACK 5
|
2014-10-23 09:04:34 -03:00
|
|
|
{ "MFT100L4>A#B#", false },
|
2018-07-24 23:00:24 -03:00
|
|
|
#define AP_NOTIFY_TONE_LOUD_READY_OR_FINISHED 6
|
2014-10-23 09:04:34 -03:00
|
|
|
{ "MFT100L4>G#6A#6B#4", false },
|
2018-07-24 23:00:24 -03:00
|
|
|
#define AP_NOTIFY_TONE_QUIET_READY_OR_FINISHED 7
|
2014-10-23 09:04:34 -03:00
|
|
|
{ "MFT200L4<G#6A#6B#4", false },
|
2018-07-24 23:00:24 -03:00
|
|
|
#define AP_NOTIFY_TONE_LOUD_ATTENTION_NEEDED 8
|
2017-01-31 01:04:03 -04:00
|
|
|
{ "MFT100L4>A#A#A#A#", false },
|
2018-07-24 23:00:24 -03:00
|
|
|
#define AP_NOTIFY_TONE_QUIET_ARMING_WARNING 9
|
2014-10-23 09:04:34 -03:00
|
|
|
{ "MNT75L1O2G", false },
|
2018-07-24 23:00:24 -03:00
|
|
|
#define AP_NOTIFY_TONE_LOUD_WP_COMPLETE 10
|
2014-10-23 09:04:34 -03:00
|
|
|
{ "MFT200L8G>C3", false },
|
2018-07-24 23:00:24 -03:00
|
|
|
#define AP_NOTIFY_TONE_LOUD_LAND_WARNING_CTS 11
|
2014-10-23 09:04:34 -03:00
|
|
|
{ "MBT200L2A-G-A-G-A-G-", true },
|
2018-07-24 23:00:24 -03:00
|
|
|
#define AP_NOTIFY_TONE_LOUD_VEHICLE_LOST_CTS 12
|
2017-01-31 01:04:03 -04:00
|
|
|
{ "MBT200>A#1", true },
|
2018-07-24 23:00:24 -03:00
|
|
|
#define AP_NOTIFY_TONE_LOUD_BATTERY_ALERT_CTS 13
|
2017-01-31 01:04:03 -04:00
|
|
|
{ "MBNT255>A#8A#8A#8A#8A#8A#8A#8A#8A#8A#8A#8A#8A#8A#8A#8A#8", true },
|
2021-01-10 16:09:44 -04:00
|
|
|
#define AP_NOTIFY_TONE_QUIET_CALIBRATING_CTS 14
|
2015-03-09 23:01:29 -03:00
|
|
|
{ "MBNT255<C16P2", true },
|
2018-07-24 23:00:24 -03:00
|
|
|
#define AP_NOTIFY_TONE_WAITING_FOR_THROW 15
|
2015-12-19 07:19:51 -04:00
|
|
|
{ "MBNT90L4O2A#O3DFN0N0N0", true},
|
2018-07-24 23:00:24 -03:00
|
|
|
#define AP_NOTIFY_TONE_LOUD_1 16
|
2016-05-09 04:24:38 -03:00
|
|
|
{ "MFT100L8>B", false},
|
2018-07-24 23:00:24 -03:00
|
|
|
#define AP_NOTIFY_TONE_LOUD_2 17
|
2016-05-09 04:24:38 -03:00
|
|
|
{ "MFT100L8>BB", false},
|
2018-07-24 23:00:24 -03:00
|
|
|
#define AP_NOTIFY_TONE_LOUD_3 18
|
2016-05-09 04:24:38 -03:00
|
|
|
{ "MFT100L8>BBB", false},
|
2018-07-24 23:00:24 -03:00
|
|
|
#define AP_NOTIFY_TONE_LOUD_4 19
|
2016-05-09 04:24:38 -03:00
|
|
|
{ "MFT100L8>BBBB", false},
|
2018-07-24 23:00:24 -03:00
|
|
|
#define AP_NOTIFY_TONE_LOUD_5 20
|
2016-05-09 04:24:38 -03:00
|
|
|
{ "MFT100L8>BBBBB", false},
|
2018-07-24 23:00:24 -03:00
|
|
|
#define AP_NOTIFY_TONE_LOUD_6 21
|
2016-05-09 04:24:38 -03:00
|
|
|
{ "MFT100L8>BBBBBB", false},
|
2018-07-24 23:00:24 -03:00
|
|
|
#define AP_NOTIFY_TONE_LOUD_7 22
|
2016-05-09 04:24:38 -03:00
|
|
|
{ "MFT100L8>BBBBBBB", false},
|
2018-07-24 23:00:24 -03:00
|
|
|
#define AP_NOTIFY_TONE_TUNING_START 23
|
2016-05-09 04:24:38 -03:00
|
|
|
{ "MFT100L20>C#D#", false},
|
2018-07-24 23:00:24 -03:00
|
|
|
#define AP_NOTIFY_TONE_TUNING_SAVE 24
|
2016-05-09 04:24:38 -03:00
|
|
|
{ "MFT100L10DBDB>", false},
|
2018-07-24 23:00:24 -03:00
|
|
|
#define AP_NOTIFY_TONE_TUNING_ERROR 25
|
2016-05-27 01:16:25 -03:00
|
|
|
{ "MFT100L10>BBBBBBBB", false},
|
2018-07-24 23:00:24 -03:00
|
|
|
#define AP_NOTIFY_TONE_LEAK_DETECTED 26
|
2017-02-07 14:54:57 -04:00
|
|
|
{ "MBT255L8>A+AA-", true},
|
2018-07-24 23:00:24 -03:00
|
|
|
#define AP_NOTIFY_TONE_QUIET_SHUTDOWN 27
|
2017-05-29 09:17:02 -03:00
|
|
|
{ "MFMST200L32O3ceP32cdP32ceP32c<c>c<cccP8L32>c>c<P32<c<c", false },
|
2018-07-24 23:00:24 -03:00
|
|
|
#define AP_NOTIFY_TONE_QUIET_NOT_READY_OR_NOT_FINISHED 28
|
2017-09-03 23:11:30 -03:00
|
|
|
{ "MFT200L4<B#4A#6G#6", false },
|
2018-07-24 23:00:24 -03:00
|
|
|
#define AP_NOTIFY_TONE_STARTUP 29
|
2018-07-24 22:30:05 -03:00
|
|
|
{ "MFT240L8O4aO5dcO4aO5dcO4aO5dcL16dcdcdcdc", false },
|
2019-07-11 00:41:06 -03:00
|
|
|
#define AP_NOTIFY_TONE_NO_SDCARD 30
|
|
|
|
{ "MNBGG", false },
|
2020-09-18 04:38:54 -03:00
|
|
|
#define AP_NOTIFY_TONE_EKF_ALERT 31
|
|
|
|
{ "MBNT255>A#8A#8A#8A#8P8A#8A#8A#8A#8P8A#8A#8A#8A#8P8A#8A#8A#8A#8", true },
|
2014-10-23 09:04:34 -03:00
|
|
|
};
|
|
|
|
|
2018-07-25 13:53:33 -03:00
|
|
|
bool AP_ToneAlarm::init()
|
2013-09-15 05:24:00 -03:00
|
|
|
{
|
2018-07-30 01:36:27 -03:00
|
|
|
if (pNotify->buzzer_enabled() == false) {
|
|
|
|
return false;
|
|
|
|
}
|
2023-04-20 22:35:37 -03:00
|
|
|
#if AP_NOTIFY_TONEALARM_ENABLED
|
2021-04-03 19:01:55 -03:00
|
|
|
if (!hal.util->toneAlarm_init(pNotify->get_buzzer_types())) {
|
2013-09-15 05:24:00 -03:00
|
|
|
return false;
|
|
|
|
}
|
2021-05-26 12:48:48 -03:00
|
|
|
#endif
|
|
|
|
|
2018-07-24 22:30:05 -03:00
|
|
|
|
2014-12-14 23:17:09 -04:00
|
|
|
// set initial boot states. This prevents us issuing a arming
|
2013-09-17 21:55:42 -03:00
|
|
|
// warning in plane and rover on every boot
|
|
|
|
flags.armed = AP_Notify::flags.armed;
|
|
|
|
flags.failsafe_battery = AP_Notify::flags.failsafe_battery;
|
2014-10-23 09:04:34 -03:00
|
|
|
flags.pre_arm_check = 1;
|
|
|
|
_cont_tone_playing = -1;
|
2018-07-25 13:53:33 -03:00
|
|
|
hal.scheduler->register_timer_process(FUNCTOR_BIND(this, &AP_ToneAlarm::_timer_task, void));
|
2019-07-11 00:41:06 -03:00
|
|
|
|
2023-05-14 22:44:22 -03:00
|
|
|
#if (AP_FILESYSTEM_POSIX_ENABLED || AP_FILESYSTEM_FATFS_ENABLED) && CONFIG_HAL_BOARD != HAL_BOARD_LINUX
|
2019-07-11 00:41:06 -03:00
|
|
|
// if we don't have a SDcard then play a failure tone instead of
|
|
|
|
// normal startup tone. This gives the user a chance to fix it
|
|
|
|
// before they try to arm. We don't do this on Linux as Linux
|
|
|
|
// flight controllers don't usually have removable storage
|
|
|
|
struct stat st;
|
2019-08-01 02:14:11 -03:00
|
|
|
if (AP::FS().stat(HAL_BOARD_STORAGE_DIRECTORY, &st) != 0) {
|
2019-07-11 00:41:06 -03:00
|
|
|
play_tone(AP_NOTIFY_TONE_NO_SDCARD);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2021-01-12 22:49:52 -04:00
|
|
|
#ifndef HAL_BUILD_AP_PERIPH
|
2018-07-24 22:30:05 -03:00
|
|
|
play_tone(AP_NOTIFY_TONE_STARTUP);
|
2021-01-12 22:49:52 -04:00
|
|
|
#endif
|
2013-09-15 05:24:00 -03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// play_tune - play one of the pre-defined tunes
|
2018-07-25 13:53:33 -03:00
|
|
|
void AP_ToneAlarm::play_tone(const uint8_t tone_index)
|
2013-09-15 05:24:00 -03:00
|
|
|
{
|
2015-11-19 23:13:24 -04:00
|
|
|
uint32_t tnow_ms = AP_HAL::millis();
|
2014-10-23 09:04:34 -03:00
|
|
|
const Tone &tone_requested = _tones[tone_index];
|
|
|
|
|
2018-07-24 23:00:24 -03:00
|
|
|
if (tone_requested.continuous) {
|
2014-10-23 09:04:34 -03:00
|
|
|
_cont_tone_playing = tone_index;
|
|
|
|
}
|
|
|
|
|
|
|
|
_tone_playing = tone_index;
|
|
|
|
_tone_beginning_ms = tnow_ms;
|
|
|
|
|
2019-03-18 23:35:15 -03:00
|
|
|
play_tune(tone_requested.str);
|
2014-10-23 09:04:34 -03:00
|
|
|
}
|
|
|
|
|
2018-07-25 13:53:33 -03:00
|
|
|
void AP_ToneAlarm::_timer_task()
|
2018-07-24 23:00:24 -03:00
|
|
|
{
|
2018-10-11 20:35:04 -03:00
|
|
|
WITH_SEMAPHORE(_sem);
|
|
|
|
_mml_player.update();
|
2014-10-23 09:04:34 -03:00
|
|
|
}
|
|
|
|
|
2019-03-18 23:35:15 -03:00
|
|
|
void AP_ToneAlarm::play_tune(const char *str)
|
2018-07-24 23:00:24 -03:00
|
|
|
{
|
2018-10-11 20:35:04 -03:00
|
|
|
WITH_SEMAPHORE(_sem);
|
|
|
|
|
|
|
|
_mml_player.stop();
|
|
|
|
strncpy(_tone_buf, str, AP_NOTIFY_TONEALARM_TONE_BUF_SIZE);
|
|
|
|
_tone_buf[AP_NOTIFY_TONEALARM_TONE_BUF_SIZE-1] = 0;
|
|
|
|
_mml_player.play(_tone_buf);
|
2018-07-24 22:30:05 -03:00
|
|
|
}
|
|
|
|
|
2018-07-25 13:53:33 -03:00
|
|
|
void AP_ToneAlarm::stop_cont_tone()
|
2018-07-24 23:00:24 -03:00
|
|
|
{
|
|
|
|
if (_cont_tone_playing == _tone_playing) {
|
2019-03-18 23:35:15 -03:00
|
|
|
play_tune("");
|
2014-10-23 09:04:34 -03:00
|
|
|
_tone_playing = -1;
|
|
|
|
}
|
|
|
|
_cont_tone_playing = -1;
|
2013-09-15 05:24:00 -03:00
|
|
|
}
|
|
|
|
|
2018-07-25 13:53:33 -03:00
|
|
|
void AP_ToneAlarm::check_cont_tone()
|
2018-07-24 23:00:24 -03:00
|
|
|
{
|
2015-11-19 23:13:24 -04:00
|
|
|
uint32_t tnow_ms = AP_HAL::millis();
|
2014-10-23 09:04:34 -03:00
|
|
|
// if we are supposed to be playing a continuous tone,
|
|
|
|
// and it was interrupted, and the interrupting tone has timed out,
|
|
|
|
// resume the continuous tone
|
|
|
|
|
2018-07-25 13:53:33 -03:00
|
|
|
if (_cont_tone_playing != -1 && _tone_playing != _cont_tone_playing && tnow_ms-_tone_beginning_ms > AP_NOTIFY_TONEALARM_MAX_TONE_LENGTH_MS) {
|
2014-10-23 09:04:34 -03:00
|
|
|
play_tone(_cont_tone_playing);
|
|
|
|
}
|
|
|
|
}
|
2013-09-15 05:24:00 -03:00
|
|
|
|
|
|
|
// update - updates led according to timed_updated. Should be called at 50Hz
|
2018-07-25 13:53:33 -03:00
|
|
|
void AP_ToneAlarm::update()
|
2013-09-15 05:24:00 -03:00
|
|
|
{
|
2016-03-31 15:19:52 -03:00
|
|
|
// exit if buzzer is not enabled
|
|
|
|
if (pNotify->buzzer_enabled() == false) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-10-23 09:04:34 -03:00
|
|
|
check_cont_tone();
|
2018-07-24 22:30:05 -03:00
|
|
|
|
2017-05-29 09:17:02 -03:00
|
|
|
if (AP_Notify::flags.powering_off) {
|
|
|
|
if (!flags.powering_off) {
|
2018-07-24 22:30:05 -03:00
|
|
|
play_tone(AP_NOTIFY_TONE_QUIET_SHUTDOWN);
|
2017-05-29 09:17:02 -03:00
|
|
|
}
|
|
|
|
flags.powering_off = AP_Notify::flags.powering_off;
|
|
|
|
return;
|
|
|
|
}
|
2014-10-23 09:04:34 -03:00
|
|
|
|
2015-03-09 23:01:29 -03:00
|
|
|
if (AP_Notify::flags.compass_cal_running != flags.compass_cal_running) {
|
2018-07-24 23:00:24 -03:00
|
|
|
if (AP_Notify::flags.compass_cal_running) {
|
2021-01-10 16:09:44 -04:00
|
|
|
play_tone(AP_NOTIFY_TONE_QUIET_CALIBRATING_CTS);
|
2018-07-24 22:30:05 -03:00
|
|
|
play_tone(AP_NOTIFY_TONE_QUIET_POS_FEEDBACK);
|
2015-03-09 23:01:29 -03:00
|
|
|
} else {
|
2021-01-10 16:09:44 -04:00
|
|
|
if (_cont_tone_playing == AP_NOTIFY_TONE_QUIET_CALIBRATING_CTS) {
|
2015-03-09 23:01:29 -03:00
|
|
|
stop_cont_tone();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
flags.compass_cal_running = AP_Notify::flags.compass_cal_running;
|
|
|
|
|
2015-03-11 22:41:01 -03:00
|
|
|
if (AP_Notify::events.compass_cal_canceled) {
|
2018-07-24 22:30:05 -03:00
|
|
|
play_tone(AP_NOTIFY_TONE_QUIET_NEU_FEEDBACK);
|
2015-03-11 22:41:01 -03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-03-09 23:01:29 -03:00
|
|
|
if (AP_Notify::events.initiated_compass_cal) {
|
2018-07-24 22:30:05 -03:00
|
|
|
play_tone(AP_NOTIFY_TONE_QUIET_NEU_FEEDBACK);
|
2015-03-09 23:01:29 -03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-01-10 16:09:44 -04:00
|
|
|
if (AP_Notify::events.compass_cal_saved ||
|
|
|
|
AP_Notify::events.temp_cal_saved) {
|
2018-07-24 22:30:05 -03:00
|
|
|
play_tone(AP_NOTIFY_TONE_QUIET_READY_OR_FINISHED);
|
2015-03-09 23:01:29 -03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-01-10 16:09:44 -04:00
|
|
|
if (AP_Notify::events.compass_cal_failed ||
|
|
|
|
AP_Notify::events.temp_cal_failed) {
|
2018-07-24 22:30:05 -03:00
|
|
|
play_tone(AP_NOTIFY_TONE_QUIET_NEG_FEEDBACK);
|
2015-03-09 23:01:29 -03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-01-10 16:09:44 -04:00
|
|
|
if (AP_Notify::events.initiated_temp_cal) {
|
|
|
|
play_tone(AP_NOTIFY_TONE_QUIET_NEU_FEEDBACK);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (AP_Notify::flags.temp_cal_running != flags.temp_cal_running) {
|
|
|
|
if (AP_Notify::flags.temp_cal_running) {
|
|
|
|
play_tone(AP_NOTIFY_TONE_QUIET_CALIBRATING_CTS);
|
|
|
|
play_tone(AP_NOTIFY_TONE_QUIET_POS_FEEDBACK);
|
|
|
|
} else {
|
|
|
|
if (_cont_tone_playing == AP_NOTIFY_TONE_QUIET_CALIBRATING_CTS) {
|
|
|
|
stop_cont_tone();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
flags.temp_cal_running = AP_Notify::flags.temp_cal_running;
|
|
|
|
|
|
|
|
// don't play other tones if cal is running
|
|
|
|
if (AP_Notify::flags.compass_cal_running ||
|
|
|
|
AP_Notify::flags.temp_cal_running) {
|
2015-03-09 23:01:29 -03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-10-23 09:04:34 -03:00
|
|
|
// notify the user when autotune or mission completes
|
|
|
|
if (AP_Notify::flags.armed && (AP_Notify::events.autotune_complete || AP_Notify::events.mission_complete)) {
|
2018-07-24 22:30:05 -03:00
|
|
|
play_tone(AP_NOTIFY_TONE_LOUD_READY_OR_FINISHED);
|
2014-10-23 09:04:34 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
//notify the user when autotune fails
|
|
|
|
if (AP_Notify::flags.armed && (AP_Notify::events.autotune_failed)) {
|
2018-07-24 22:30:05 -03:00
|
|
|
play_tone(AP_NOTIFY_TONE_LOUD_NEG_FEEDBACK);
|
2014-10-23 09:04:34 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
// notify the user when a waypoint completes
|
|
|
|
if (AP_Notify::events.waypoint_complete) {
|
2018-07-24 22:30:05 -03:00
|
|
|
play_tone(AP_NOTIFY_TONE_LOUD_WP_COMPLETE);
|
2014-10-23 09:04:34 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
// notify the user when their mode change was successful
|
2014-12-15 00:40:21 -04:00
|
|
|
if (AP_Notify::events.user_mode_change) {
|
2014-10-23 09:04:34 -03:00
|
|
|
if (AP_Notify::flags.armed) {
|
2018-07-24 22:30:05 -03:00
|
|
|
play_tone(AP_NOTIFY_TONE_LOUD_NEU_FEEDBACK);
|
2014-10-23 09:04:34 -03:00
|
|
|
} else {
|
2018-07-24 22:30:05 -03:00
|
|
|
play_tone(AP_NOTIFY_TONE_QUIET_NEU_FEEDBACK);
|
2014-10-23 09:04:34 -03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// notify the user when their mode change failed
|
2014-12-15 00:40:21 -04:00
|
|
|
if (AP_Notify::events.user_mode_change_failed) {
|
2014-10-23 09:04:34 -03:00
|
|
|
if (AP_Notify::flags.armed) {
|
2018-07-24 22:30:05 -03:00
|
|
|
play_tone(AP_NOTIFY_TONE_LOUD_NEG_FEEDBACK);
|
2014-10-23 09:04:34 -03:00
|
|
|
} else {
|
2018-07-24 22:30:05 -03:00
|
|
|
play_tone(AP_NOTIFY_TONE_QUIET_NEG_FEEDBACK);
|
2014-10-23 09:04:34 -03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-14 23:44:38 -04:00
|
|
|
// failsafe initiated mode change
|
2018-07-24 23:00:24 -03:00
|
|
|
if (AP_Notify::events.failsafe_mode_change) {
|
2018-07-24 22:30:05 -03:00
|
|
|
play_tone(AP_NOTIFY_TONE_LOUD_ATTENTION_NEEDED);
|
2014-10-23 09:04:34 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
// notify the user when arming fails
|
2015-02-02 16:57:51 -04:00
|
|
|
if (AP_Notify::events.arming_failed) {
|
2018-07-24 22:30:05 -03:00
|
|
|
play_tone(AP_NOTIFY_TONE_QUIET_NEG_FEEDBACK);
|
2014-10-23 09:04:34 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
// notify the user when RC contact is lost
|
|
|
|
if (flags.failsafe_radio != AP_Notify::flags.failsafe_radio) {
|
|
|
|
flags.failsafe_radio = AP_Notify::flags.failsafe_radio;
|
|
|
|
if (flags.failsafe_radio) {
|
2014-12-14 23:44:38 -04:00
|
|
|
// armed case handled by events.failsafe_mode_change
|
2014-10-23 09:04:34 -03:00
|
|
|
if (!AP_Notify::flags.armed) {
|
2018-07-24 22:30:05 -03:00
|
|
|
play_tone(AP_NOTIFY_TONE_QUIET_NEG_FEEDBACK);
|
2014-10-23 09:04:34 -03:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (AP_Notify::flags.armed) {
|
2018-07-24 22:30:05 -03:00
|
|
|
play_tone(AP_NOTIFY_TONE_LOUD_POS_FEEDBACK);
|
2019-10-31 19:10:36 -03:00
|
|
|
} else {
|
|
|
|
play_tone(AP_NOTIFY_TONE_QUIET_POS_FEEDBACK);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// notify the user when GCS failsafe is triggered
|
|
|
|
if (flags.failsafe_gcs != AP_Notify::flags.failsafe_gcs) {
|
|
|
|
flags.failsafe_gcs = AP_Notify::flags.failsafe_gcs;
|
|
|
|
if (flags.failsafe_gcs) {
|
|
|
|
// armed case handled by events.failsafe_mode_change
|
|
|
|
if (!AP_Notify::flags.armed) {
|
|
|
|
play_tone(AP_NOTIFY_TONE_QUIET_NEG_FEEDBACK);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (AP_Notify::flags.armed) {
|
|
|
|
play_tone(AP_NOTIFY_TONE_LOUD_POS_FEEDBACK);
|
2014-10-23 09:04:34 -03:00
|
|
|
} else {
|
2018-07-24 22:30:05 -03:00
|
|
|
play_tone(AP_NOTIFY_TONE_QUIET_POS_FEEDBACK);
|
2014-10-23 09:04:34 -03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// notify the user when pre_arm checks are passing
|
|
|
|
if (flags.pre_arm_check != AP_Notify::flags.pre_arm_check) {
|
|
|
|
flags.pre_arm_check = AP_Notify::flags.pre_arm_check;
|
|
|
|
if (flags.pre_arm_check) {
|
2018-07-24 22:30:05 -03:00
|
|
|
play_tone(AP_NOTIFY_TONE_QUIET_READY_OR_FINISHED);
|
2017-10-27 08:08:43 -03:00
|
|
|
_have_played_ready_tone = true;
|
2017-09-03 23:11:30 -03:00
|
|
|
} else {
|
2017-10-27 08:08:43 -03:00
|
|
|
// only play sad tone if we've ever played happy tone:
|
|
|
|
if (_have_played_ready_tone) {
|
2018-07-24 22:30:05 -03:00
|
|
|
play_tone(AP_NOTIFY_TONE_QUIET_NOT_READY_OR_NOT_FINISHED);
|
2017-10-27 08:08:43 -03:00
|
|
|
}
|
2014-03-31 05:55:14 -03:00
|
|
|
}
|
|
|
|
}
|
2013-09-15 05:24:00 -03:00
|
|
|
|
|
|
|
// check if arming status has changed
|
|
|
|
if (flags.armed != AP_Notify::flags.armed) {
|
|
|
|
flags.armed = AP_Notify::flags.armed;
|
|
|
|
if (flags.armed) {
|
|
|
|
// arming tune
|
2018-07-24 22:30:05 -03:00
|
|
|
play_tone(AP_NOTIFY_TONE_QUIET_ARMING_WARNING);
|
2018-07-24 23:00:24 -03:00
|
|
|
} else {
|
2013-09-15 05:24:00 -03:00
|
|
|
// disarming tune
|
2018-07-24 22:30:05 -03:00
|
|
|
play_tone(AP_NOTIFY_TONE_QUIET_NEU_FEEDBACK);
|
2017-02-07 14:54:57 -04:00
|
|
|
if (!flags.leak_detected) {
|
2018-07-24 22:30:05 -03:00
|
|
|
stop_cont_tone();
|
2017-02-07 14:54:57 -04:00
|
|
|
}
|
2013-09-15 05:24:00 -03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// check if battery status has changed
|
|
|
|
if (flags.failsafe_battery != AP_Notify::flags.failsafe_battery) {
|
|
|
|
flags.failsafe_battery = AP_Notify::flags.failsafe_battery;
|
|
|
|
if (flags.failsafe_battery) {
|
2014-10-23 09:04:34 -03:00
|
|
|
// battery warning tune
|
2018-07-24 22:30:05 -03:00
|
|
|
play_tone(AP_NOTIFY_TONE_LOUD_BATTERY_ALERT_CTS);
|
2014-07-28 08:41:30 -03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-03 10:03:12 -03:00
|
|
|
// check parachute release
|
|
|
|
if (flags.parachute_release != AP_Notify::flags.parachute_release) {
|
|
|
|
flags.parachute_release = AP_Notify::flags.parachute_release;
|
|
|
|
if (flags.parachute_release) {
|
|
|
|
// parachute release warning tune
|
2018-07-24 22:30:05 -03:00
|
|
|
play_tone(AP_NOTIFY_TONE_LOUD_ATTENTION_NEEDED);
|
2014-07-21 07:12:53 -03:00
|
|
|
}
|
|
|
|
}
|
2015-04-11 17:20:02 -03:00
|
|
|
|
2015-04-13 05:29:57 -03:00
|
|
|
// lost vehicle tone
|
|
|
|
if (flags.vehicle_lost != AP_Notify::flags.vehicle_lost) {
|
|
|
|
flags.vehicle_lost = AP_Notify::flags.vehicle_lost;
|
|
|
|
if (flags.vehicle_lost) {
|
2018-07-24 22:30:05 -03:00
|
|
|
play_tone(AP_NOTIFY_TONE_LOUD_VEHICLE_LOST_CTS);
|
2015-04-13 05:29:57 -03:00
|
|
|
} else {
|
2015-04-11 17:20:02 -03:00
|
|
|
stop_cont_tone();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-19 07:19:51 -04:00
|
|
|
// waiting to be thrown vehicle tone
|
|
|
|
if (flags.waiting_for_throw != AP_Notify::flags.waiting_for_throw) {
|
|
|
|
flags.waiting_for_throw = AP_Notify::flags.waiting_for_throw;
|
|
|
|
if (flags.waiting_for_throw) {
|
2018-07-24 22:30:05 -03:00
|
|
|
play_tone(AP_NOTIFY_TONE_WAITING_FOR_THROW);
|
2017-02-07 14:54:57 -04:00
|
|
|
} else {
|
|
|
|
stop_cont_tone();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flags.leak_detected != AP_Notify::flags.leak_detected) {
|
|
|
|
flags.leak_detected = AP_Notify::flags.leak_detected;
|
|
|
|
if (flags.leak_detected) {
|
2018-07-24 22:30:05 -03:00
|
|
|
play_tone(AP_NOTIFY_TONE_LEAK_DETECTED);
|
2015-12-19 07:19:51 -04:00
|
|
|
} else {
|
|
|
|
stop_cont_tone();
|
|
|
|
}
|
|
|
|
}
|
2016-05-06 04:06:11 -03:00
|
|
|
|
|
|
|
if (AP_Notify::events.tune_started) {
|
2018-07-24 22:30:05 -03:00
|
|
|
play_tone(AP_NOTIFY_TONE_TUNING_START);
|
|
|
|
AP_Notify::events.tune_started = 0;
|
2016-05-06 04:06:11 -03:00
|
|
|
}
|
|
|
|
if (AP_Notify::events.tune_next) {
|
2016-05-09 04:24:38 -03:00
|
|
|
// signify which parameter in the set is starting
|
2018-07-24 22:30:05 -03:00
|
|
|
play_tone(AP_NOTIFY_TONE_LOUD_1 + (AP_Notify::events.tune_next-1));
|
|
|
|
AP_Notify::events.tune_next = 0;
|
2016-05-06 04:06:11 -03:00
|
|
|
}
|
|
|
|
if (AP_Notify::events.tune_save) {
|
2018-07-24 22:30:05 -03:00
|
|
|
play_tone(AP_NOTIFY_TONE_TUNING_SAVE);
|
2016-05-06 04:06:11 -03:00
|
|
|
AP_Notify::events.tune_save = 0;
|
|
|
|
}
|
2016-05-27 01:16:25 -03:00
|
|
|
if (AP_Notify::events.tune_error) {
|
2018-07-24 22:30:05 -03:00
|
|
|
play_tone(AP_NOTIFY_TONE_TUNING_ERROR);
|
2016-05-27 01:16:25 -03:00
|
|
|
AP_Notify::events.tune_error = 0;
|
|
|
|
}
|
2020-09-18 04:38:54 -03:00
|
|
|
|
|
|
|
// notify the user when ekf failsafe is triggered
|
|
|
|
if (flags.failsafe_ekf != AP_Notify::flags.failsafe_ekf) {
|
|
|
|
flags.failsafe_ekf = AP_Notify::flags.failsafe_ekf;
|
|
|
|
if (flags.failsafe_ekf) {
|
|
|
|
play_tone(AP_NOTIFY_TONE_EKF_ALERT);
|
|
|
|
}
|
|
|
|
}
|
2013-09-15 05:24:00 -03:00
|
|
|
}
|
|
|
|
|
2016-07-22 00:37:25 -03:00
|
|
|
|
2022-10-20 03:40:41 -03:00
|
|
|
#if AP_NOTIFY_MAVLINK_PLAY_TUNE_SUPPORT_ENABLED
|
2016-07-22 00:37:25 -03:00
|
|
|
/*
|
2018-07-24 22:30:05 -03:00
|
|
|
* handle a PLAY_TUNE message
|
|
|
|
*/
|
2022-10-20 03:40:41 -03:00
|
|
|
void AP_Notify::handle_play_tune(const mavlink_message_t &msg)
|
2016-07-22 00:37:25 -03:00
|
|
|
{
|
|
|
|
// decode mavlink message
|
|
|
|
mavlink_play_tune_t packet;
|
2018-07-24 22:30:05 -03:00
|
|
|
|
2019-04-30 07:22:48 -03:00
|
|
|
mavlink_msg_play_tune_decode(&msg, &packet);
|
2016-07-22 00:37:25 -03:00
|
|
|
|
2022-10-20 03:40:41 -03:00
|
|
|
char _tone_buf[AP_NOTIFY_TONEALARM_TONE_BUF_SIZE] {}; // ~100 bytes
|
2018-10-11 20:35:04 -03:00
|
|
|
strncpy(_tone_buf, packet.tune, MIN(sizeof(packet.tune), sizeof(_tone_buf)-1));
|
|
|
|
uint8_t len = strlen(_tone_buf);
|
|
|
|
uint8_t len2 = strnlen(packet.tune2, sizeof(packet.tune2));
|
|
|
|
len2 = MIN((sizeof(_tone_buf)-1)-len, len2);
|
2022-10-20 03:40:41 -03:00
|
|
|
memcpy(_tone_buf+len, packet.tune2, len2); // not strncpy to avoid truncation warning
|
2018-10-11 20:35:04 -03:00
|
|
|
_tone_buf[sizeof(_tone_buf)-1] = 0;
|
2022-10-20 03:40:41 -03:00
|
|
|
|
|
|
|
play_tune(_tone_buf);
|
2016-07-22 00:37:25 -03:00
|
|
|
}
|
2022-10-20 03:40:41 -03:00
|
|
|
#endif
|