2013-09-15 05:24:00 -03:00
|
|
|
/*
|
2019-01-19 04:22:27 -04:00
|
|
|
* 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
|
|
|
*/
|
2016-01-29 00:38:21 -04:00
|
|
|
#pragma once
|
2013-09-15 05:24:00 -03:00
|
|
|
|
2014-11-14 10:14:40 -04:00
|
|
|
#include "NotifyDevice.h"
|
2018-07-24 22:30:05 -03:00
|
|
|
#include "MMLPlayer.h"
|
2013-09-15 05:24:00 -03:00
|
|
|
|
2014-10-23 09:04:34 -03:00
|
|
|
// wait 2 seconds before assuming a tone is done and continuing the continuous tone
|
2018-07-25 13:53:33 -03:00
|
|
|
#define AP_NOTIFY_TONEALARM_MAX_TONE_LENGTH_MS 2000
|
2018-07-30 00:58:11 -03:00
|
|
|
#define AP_NOTIFY_TONEALARM_TONE_BUF_SIZE 100
|
2014-10-23 09:04:34 -03:00
|
|
|
|
2018-07-25 13:53:33 -03:00
|
|
|
class AP_ToneAlarm: public NotifyDevice {
|
2013-09-15 05:24:00 -03:00
|
|
|
public:
|
|
|
|
/// init - initialised the tone alarm
|
2018-07-25 13:53:33 -03:00
|
|
|
bool init(void) override;
|
2013-09-15 05:24:00 -03:00
|
|
|
|
|
|
|
/// update - updates led according to timed_updated. Should be called at 50Hz
|
2018-11-07 07:01:17 -04:00
|
|
|
void update() override;
|
2013-09-15 05:24:00 -03:00
|
|
|
|
2016-07-22 00:37:25 -03:00
|
|
|
// handle a PLAY_TUNE message
|
2018-11-07 07:01:17 -04:00
|
|
|
void handle_play_tune(mavlink_message_t *msg) override;
|
2018-07-24 22:30:05 -03:00
|
|
|
|
2019-03-18 23:35:15 -03:00
|
|
|
// play_tune - play tone specified by the provided string of notes
|
|
|
|
void play_tune(const char *tune) override;
|
|
|
|
|
2013-09-15 05:24:00 -03:00
|
|
|
private:
|
2013-09-17 21:55:42 -03:00
|
|
|
/// play_tune - play one of the pre-defined tunes
|
2014-10-23 09:04:34 -03:00
|
|
|
void play_tone(const uint8_t tone_index);
|
|
|
|
|
2014-12-14 23:17:09 -04:00
|
|
|
// stop_cont_tone - stop playing the currently playing continuous tone
|
2014-10-23 09:04:34 -03:00
|
|
|
void stop_cont_tone();
|
2014-12-14 23:17:09 -04:00
|
|
|
|
|
|
|
// check_cont_tone - check if we should begin playing a continuous tone
|
2014-10-23 09:04:34 -03:00
|
|
|
void check_cont_tone();
|
2013-09-17 21:55:42 -03:00
|
|
|
|
2018-07-24 22:30:05 -03:00
|
|
|
// timer task - runs at 1khz
|
|
|
|
void _timer_task();
|
2013-09-15 05:24:00 -03:00
|
|
|
|
|
|
|
/// tonealarm_type - bitmask of states we track
|
|
|
|
struct tonealarm_type {
|
2017-02-07 14:54:57 -04:00
|
|
|
uint16_t armed : 1; // 0 = disarmed, 1 = armed
|
|
|
|
uint16_t failsafe_battery : 1; // 1 if battery failsafe
|
|
|
|
uint16_t parachute_release : 1; // 1 if parachute is being released
|
|
|
|
uint16_t pre_arm_check : 1; // 0 = failing checks, 1 = passed
|
|
|
|
uint16_t failsafe_radio : 1; // 1 if radio failsafe
|
|
|
|
uint16_t vehicle_lost : 1; // 1 if lost copter tone requested
|
|
|
|
uint16_t compass_cal_running : 1; // 1 if compass calibration is running
|
|
|
|
uint16_t waiting_for_throw : 1; // 1 if waiting for copter throw launch
|
|
|
|
uint16_t leak_detected : 1; // 1 if leak detected
|
2017-05-29 09:17:02 -03:00
|
|
|
uint16_t powering_off : 1; // 1 if smart battery is powering off
|
2013-09-15 05:24:00 -03:00
|
|
|
} flags;
|
2017-10-27 08:08:43 -03:00
|
|
|
bool _have_played_ready_tone : 1;
|
2014-10-23 09:04:34 -03:00
|
|
|
|
|
|
|
int8_t _cont_tone_playing;
|
|
|
|
int8_t _tone_playing;
|
|
|
|
uint32_t _tone_beginning_ms;
|
|
|
|
|
|
|
|
struct Tone {
|
|
|
|
const char *str;
|
|
|
|
const uint8_t continuous : 1;
|
2018-07-25 13:53:33 -03:00
|
|
|
};
|
2014-10-23 09:04:34 -03:00
|
|
|
|
2018-07-25 13:53:33 -03:00
|
|
|
const static Tone _tones[];
|
2018-07-24 22:30:05 -03:00
|
|
|
|
2018-10-11 20:35:04 -03:00
|
|
|
HAL_Semaphore _sem;
|
2018-07-25 13:53:33 -03:00
|
|
|
MMLPlayer _mml_player;
|
|
|
|
char _tone_buf[AP_NOTIFY_TONEALARM_TONE_BUF_SIZE];
|
|
|
|
};
|