APM:Libraries
Buzzer.h
Go to the documentation of this file.
1 /*
2  Buzzer driver
3 */
4 /*
5  This program is free software: you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 3 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 #pragma once
19 
20 #include <AP_HAL/AP_HAL.h>
21 
22 #define BUZZER_ARMING_BUZZ_MS 3000 // arming buzz length in milliseconds (i.e. 3 seconds)
23 
24 #include "NotifyDevice.h"
25 
26 class Buzzer: public NotifyDevice
27 {
28 public:
30  Buzzer() :
31  _counter(0),
32  _pattern(NONE),
35  {}
36 
38  bool init(void);
39 
41  void update();
42 
44  void on(bool on_off);
45 
46  // Patterns - how many beeps will be played
48  NONE = 0,
51  GPS_GLITCH = 3, // not used
54  EKF_BAD = 6
55  };
56 
58  void play_pattern(BuzzerPattern pattern_id);
59 
60 private:
61 
64  uint8_t on : 1; // 1 if the buzzer is currently on
65  uint8_t arming : 1; // 1 if we are beginning the arming process
66  uint8_t armed : 1; // 0 = disarmed, 1 = armed
67  uint8_t failsafe_battery : 1; // 1 if battery failsafe has triggered
68  uint8_t ekf_bad : 1; // 1 if ekf position has gone bad
69  } _flags;
70 
71  uint8_t _counter; // reduces 50hz update down to 10hz for internal processing
72  BuzzerPattern _pattern; // current pattern
73  uint8_t _pattern_counter; // used to time on/off of current patter
74  uint32_t _arming_buzz_start_ms; // arming_buzz start time in milliseconds
75  uint8_t _pin;
76 };
BuzzerPattern
Definition: Buzzer.h:47
Buzzer()
Constructor.
Definition: Buzzer.h:30
uint8_t _pattern_counter
Definition: Buzzer.h:73
uint8_t _pin
Definition: Buzzer.h:75
Definition: Buzzer.h:26
uint32_t _arming_buzz_start_ms
Definition: Buzzer.h:74
bool init(void)
init - initialise the buzzer
Definition: Buzzer.cpp:34
void update()
update - updates buzzer according to timed_updated. Should be called at 50Hz
Definition: Buzzer.cpp:55
BuzzerPattern _pattern
Definition: Buzzer.h:72
struct Buzzer::buzzer_flag_type _flags
buzzer_flag_type - bitmask of current state and ap_notify states we track
Definition: Buzzer.h:63
void play_pattern(BuzzerPattern pattern_id)
play_pattern - plays the defined buzzer pattern
Definition: Buzzer.cpp:225
uint8_t _counter
Definition: Buzzer.h:71
uint8_t failsafe_battery
Definition: Buzzer.h:67
void on(bool on_off)
on - turns the buzzer on or off
Definition: Buzzer.cpp:210