APM:Libraries
ToneAlarm.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <AP_HAL/AP_HAL.h>
4 
5 #define OCTAVE_OFFSET 0
6 
7 #define NOTE_B0 31
8 #define NOTE_C1 33
9 #define NOTE_CS1 35
10 #define NOTE_D1 37
11 #define NOTE_DS1 39
12 #define NOTE_E1 41
13 #define NOTE_F1 44
14 #define NOTE_FS1 46
15 #define NOTE_G1 49
16 #define NOTE_GS1 52
17 #define NOTE_A1 55
18 #define NOTE_AS1 58
19 #define NOTE_B1 62
20 #define NOTE_C2 65
21 #define NOTE_CS2 69
22 #define NOTE_D2 73
23 #define NOTE_DS2 78
24 #define NOTE_E2 82
25 #define NOTE_F2 87
26 #define NOTE_FS2 93
27 #define NOTE_G2 98
28 #define NOTE_GS2 104
29 #define NOTE_A2 110
30 #define NOTE_AS2 117
31 #define NOTE_B2 123
32 #define NOTE_C3 131
33 #define NOTE_CS3 139
34 #define NOTE_D3 147
35 #define NOTE_DS3 156
36 #define NOTE_E3 165
37 #define NOTE_F3 175
38 #define NOTE_FS3 185
39 #define NOTE_G3 196
40 #define NOTE_GS3 208
41 #define NOTE_A3 220
42 #define NOTE_AS3 233
43 #define NOTE_B3 247
44 #define NOTE_C4 262
45 #define NOTE_CS4 277
46 #define NOTE_D4 294
47 #define NOTE_DS4 311
48 #define NOTE_E4 330
49 #define NOTE_F4 349
50 #define NOTE_FS4 370
51 #define NOTE_G4 392
52 #define NOTE_GS4 415
53 #define NOTE_A4 440
54 #define NOTE_AS4 466
55 #define NOTE_B4 494
56 #define NOTE_C5 523
57 #define NOTE_CS5 554
58 #define NOTE_D5 587
59 #define NOTE_DS5 622
60 #define NOTE_E5 659
61 #define NOTE_F5 698
62 #define NOTE_FS5 740
63 #define NOTE_G5 784
64 #define NOTE_GS5 831
65 #define NOTE_A5 880
66 #define NOTE_AS5 932
67 #define NOTE_B5 988
68 #define NOTE_C6 1047
69 #define NOTE_CS6 1109
70 #define NOTE_D6 1175
71 #define NOTE_DS6 1245
72 #define NOTE_E6 1319
73 #define NOTE_F6 1397
74 #define NOTE_FS6 1480
75 #define NOTE_G6 1568
76 #define NOTE_GS6 1661
77 #define NOTE_A6 1760
78 #define NOTE_AS6 1865
79 #define NOTE_B6 1976
80 #define NOTE_C7 2093
81 #define NOTE_CS7 2217
82 #define NOTE_D7 2349
83 #define NOTE_DS7 2489
84 #define NOTE_E7 2637
85 #define NOTE_F7 2794
86 #define NOTE_FS7 2960
87 #define NOTE_G7 3136
88 #define NOTE_GS7 3322
89 #define NOTE_A7 3520
90 #define NOTE_AS7 3729
91 #define NOTE_B7 3951
92 #define NOTE_C8 4186
93 #define NOTE_CS8 4435
94 #define NOTE_D8 4699
95 #define NOTE_DS8 4978
96 
97 #define TONE_STARTUP_TUNE 0
98 #define TONE_ERROR_TUNE 1
99 #define TONE_NOTIFY_POSITIVE_TUNE 2
100 #define TONE_NOTIFY_NEUTRAL_TUNE 3
101 #define TONE_NOTIFY_NEGATIVE_TUNE 4
102 #define TONE_ARMING_WARNING_TUNE 5
103 #define TONE_BATTERY_WARNING_SLOW_TUNE 6
104 #define TONE_BATTERY_WARNING_FAST_TUNE 7
105 #define TONE_GPS_WARNING_TUNE 8
106 #define TONE_ARMING_FAILURE_TUNE 9
107 #define TONE_PARACHUTE_RELEASE_TUNE 10
108 
109 #define TONE_NUMBER_OF_TUNES 11
110 
111 namespace Linux {
112 
113 class ToneAlarm {
114 public:
115  ToneAlarm();
116  void set_tune(uint8_t tone);
117  virtual bool init();
118  virtual void stop();
119  virtual bool play();
120  bool is_tune_comp();
121  bool set_note();
122  bool init_tune();
123 
124 protected:
125  bool tune_comp;
126  static const char *tune[TONE_NUMBER_OF_TUNES];
129  uint8_t default_oct;
130  uint8_t default_dur;
131  uint16_t bpm;
132  uint16_t wholenote;
133  uint16_t cur_note;
134  uint16_t duration;
135  int32_t prev_tune_num;
136  uint32_t prev_time;
137  int8_t tune_num;
138  uint8_t tune_pos;
139 
140 private:
141  int32_t period_fd;
142  int32_t duty_fd;
143  int32_t run_fd;
144 };
145 
146 }
uint8_t default_dur
Definition: ToneAlarm.h:130
int32_t prev_tune_num
Definition: ToneAlarm.h:135
uint16_t wholenote
Definition: ToneAlarm.h:132
uint16_t duration
Definition: ToneAlarm.h:134
static bool tune_repeat[TONE_NUMBER_OF_TUNES]
Definition: ToneAlarm.h:127
bool is_tune_comp()
Definition: ToneAlarm.cpp:72
virtual bool play()
Definition: ToneAlarm.cpp:82
uint8_t default_oct
Definition: ToneAlarm.h:129
void set_tune(uint8_t tone)
Definition: ToneAlarm.cpp:67
uint8_t tune_pos
Definition: ToneAlarm.h:138
uint16_t cur_note
Definition: ToneAlarm.h:133
uint16_t bpm
Definition: ToneAlarm.h:131
virtual bool init()
Definition: ToneAlarm.cpp:53
static const char * tune[TONE_NUMBER_OF_TUNES]
Definition: ToneAlarm.h:126
uint32_t prev_time
Definition: ToneAlarm.h:136
int32_t run_fd
Definition: ToneAlarm.h:143
int32_t period_fd
Definition: ToneAlarm.h:141
#define TONE_NUMBER_OF_TUNES
Definition: ToneAlarm.h:109
int32_t duty_fd
Definition: ToneAlarm.h:142
virtual void stop()
Definition: ToneAlarm.cpp:77