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