2013-11-28 00:28:14 -04:00
|
|
|
/*
|
|
|
|
Buzzer driver
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
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/>.
|
|
|
|
*/
|
2016-01-29 00:38:21 -04:00
|
|
|
#pragma once
|
2013-11-28 00:28:14 -04:00
|
|
|
|
2014-11-14 10:14:40 -04:00
|
|
|
#include "NotifyDevice.h"
|
|
|
|
|
|
|
|
class Buzzer: public NotifyDevice
|
2013-11-28 00:28:14 -04:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
/// Constructor
|
2018-06-26 14:05:10 -03:00
|
|
|
Buzzer() {}
|
2013-11-28 00:28:14 -04:00
|
|
|
|
|
|
|
/// init - initialise the buzzer
|
2018-11-07 07:01:17 -04:00
|
|
|
bool init(void) override;
|
2013-11-28 00:28:14 -04:00
|
|
|
|
|
|
|
/// update - updates buzzer according to timed_updated. Should be called at 50Hz
|
2018-11-07 07:01:17 -04:00
|
|
|
void update() override;
|
2013-11-28 00:28:14 -04:00
|
|
|
|
2018-10-09 03:05:23 -03:00
|
|
|
private:
|
|
|
|
|
2013-11-28 00:28:14 -04:00
|
|
|
/// on - turns the buzzer on or off
|
|
|
|
void on(bool on_off);
|
|
|
|
|
2018-10-09 03:05:23 -03:00
|
|
|
// Patterns - how many beeps will be played; read from
|
|
|
|
// left-to-right, each bit represents 100ms
|
|
|
|
static const uint32_t SINGLE_BUZZ = 0b10000000000000000000000000000000UL;
|
|
|
|
static const uint32_t DOUBLE_BUZZ = 0b10100000000000000000000000000000UL;
|
|
|
|
static const uint32_t ARMING_BUZZ = 0b11111111111111111111111111111100UL; // 3s
|
|
|
|
static const uint32_t BARO_BUZZ = 0b10101010100000000000000000000000UL;
|
|
|
|
static const uint32_t EKF_BAD = 0b11101101010000000000000000000000UL;
|
2013-11-28 00:28:14 -04:00
|
|
|
|
|
|
|
/// play_pattern - plays the defined buzzer pattern
|
2018-10-09 03:05:23 -03:00
|
|
|
void play_pattern(const uint32_t pattern);
|
2013-11-28 00:28:14 -04:00
|
|
|
|
|
|
|
/// buzzer_flag_type - bitmask of current state and ap_notify states we track
|
|
|
|
struct buzzer_flag_type {
|
|
|
|
uint8_t on : 1; // 1 if the buzzer is currently on
|
|
|
|
uint8_t arming : 1; // 1 if we are beginning the arming process
|
|
|
|
uint8_t armed : 1; // 0 = disarmed, 1 = armed
|
|
|
|
uint8_t failsafe_battery : 1; // 1 if battery failsafe has triggered
|
2016-05-04 23:48:44 -03:00
|
|
|
uint8_t ekf_bad : 1; // 1 if ekf position has gone bad
|
2013-11-28 00:28:14 -04:00
|
|
|
} _flags;
|
|
|
|
|
2018-10-09 03:05:23 -03:00
|
|
|
uint32_t _pattern; // current pattern
|
2023-04-20 21:16:33 -03:00
|
|
|
int8_t _pin;
|
2018-10-09 03:05:23 -03:00
|
|
|
uint32_t _pattern_start_time;
|
|
|
|
|
|
|
|
// enforce minumum 100ms interval between patterns:
|
|
|
|
const uint16_t _pattern_start_interval_time_ms = 32*100 + 100;
|
|
|
|
|
|
|
|
void update_playing_pattern();
|
|
|
|
void update_pattern_to_play();
|
|
|
|
|
2013-11-28 00:28:14 -04:00
|
|
|
};
|