-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbeepfunc.cpp
More file actions
293 lines (263 loc) · 7.11 KB
/
beepfunc.cpp
File metadata and controls
293 lines (263 loc) · 7.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
//================================================================
// beeping functions
//================================================================
#include "beepfunc.h"
boolean noContinuity = false;
boolean NoBeep = false;
#ifdef ALTIMULTIV2
const int pinSpeaker = 13;
#endif
#ifdef ALTIMULTI
const int pinSpeaker = 12;
#endif
#ifdef ALTIMULTISTM32
const int pinSpeaker = PA0;
#endif
#if defined ALTIMULTIESP32 || defined ALTIMULTIESP32_ACCELERO || defined ALTIMULTIESP32_ACCELERO_375 || defined ALTIMULTIESP32_ACCELERO_345
const int pinSpeaker = 16;
#endif
#ifdef ALTIDUOESP32
const int pinSpeaker = -1;
#endif
int beepingFrequency;
int lastPin = -1;
int currentPinPos = 0;
int currentPin = -1;
int pos = -1;
long tempo = 0;
long startTempo = 0;
long tempo2 = 0;
long startTempo2 = 0 ;
long bigdelay = 0;
long savedDelay =0;
/*
*
* void beepAltitude(long altitude)
*
*
*/
void beepAltitude(long altitude)
{
int i;
int nbrLongBeep = 0;
int nbrShortBeep = 0;
// this is the last thing that I need to write, some code to beep the altitude
//altitude is in meters
//find how many digits
if (altitude > 99)
{
// 1 long beep per hundred meter
nbrLongBeep = int(altitude / 100);
//then calculate the number of short beep
nbrShortBeep = (altitude - (nbrLongBeep * 100)) / 10;
}
else
{
nbrLongBeep = 0;
nbrShortBeep = (altitude / 10);
}
if (nbrLongBeep > 0)
for (i = 1; i < nbrLongBeep + 1 ; i++)
{
longBeep();
delay(50);
}
if (nbrShortBeep > 0)
for (i = 1; i < nbrShortBeep + 1 ; i++)
{
shortBeep();
delay(50);
}
delay(5000);
}
void beginBeepSeq()
{
int i = 0;
if (NoBeep == false)
{
for (i = 0; i < 10; i++)
{
//#ifndef ALTIMULTIESP32
#if not defined ALTIMULTIESP32 && not defined ALTIMULTIESP32_ACCELERO && not defined ALTIMULTIESP32_ACCELERO_375 && not defined ALTIMULTIESP32_ACCELERO_345
tone(pinSpeaker, 1600, 1000);
delay(50);
noTone(pinSpeaker);
#endif
//#ifdef ALTIMULTIESP32
#if defined ALTIMULTIESP32 || defined ALTIMULTIESP32_ACCELERO || defined ALTIMULTIESP32_ACCELERO_375 || defined ALTIMULTIESP32_ACCELERO_345
tone(pinSpeaker, 1600, 50);
noTone(pinSpeaker);
delay(50);
#endif
}
delay(1000);
}
}
void longBeep()
{
if (NoBeep == false)
{
//#ifndef ALTIMULTIESP32
#if not defined ALTIMULTIESP32 && not defined ALTIMULTIESP32_ACCELERO && not defined ALTIMULTIESP32_ACCELERO_375 && not defined ALTIMULTIESP32_ACCELERO_345
tone(pinSpeaker, beepingFrequency, 1000);
delay(1500);
noTone(pinSpeaker);
#endif
//#ifdef ALTIMULTIESP32
#if defined ALTIMULTIESP32 || defined ALTIMULTIESP32_ACCELERO || defined ALTIMULTIESP32_ACCELERO_375 || defined ALTIMULTIESP32_ACCELERO_345
tone(pinSpeaker, beepingFrequency, 1000);
delay(1000);
noTone(pinSpeaker);
#endif
}
}
void shortBeep()
{
if (NoBeep == false)
{
//#ifndef ALTIMULTIESP32
#if not defined ALTIMULTIESP32 && not defined ALTIMULTIESP32_ACCELERO && not defined ALTIMULTIESP32_ACCELERO_375 && not defined ALTIMULTIESP32_ACCELERO_345
tone(pinSpeaker, beepingFrequency, 25);
delay(300);
noTone(pinSpeaker);
#endif
//#ifdef ALTIMULTIESP32
#if defined ALTIMULTIESP32 || defined ALTIMULTIESP32_ACCELERO || defined ALTIMULTIESP32_ACCELERO_375 || defined ALTIMULTIESP32_ACCELERO_345
tone(pinSpeaker, beepingFrequency, 25);
noTone(pinSpeaker);
delay(300);
#endif
}
}
void beepAltiVersion (int majorNbr, int minorNbr)
{
int i;
for (i = 0; i < majorNbr; i++)
{
longBeep();
}
for (i = 0; i < minorNbr; i++)
{
shortBeep();
}
}
//================================================================
// The following is some Code written by Leo Nutz and modified so that it works
// Output the maximum achieved altitude (apogee) via flashing LED / Buzzer
//================================================================
void longBeepRepeat( int digit ) {
#ifdef DEBUG
SerialCom.println("longBeepRepeat: " );
SerialCom.println( digit);
#endif
int i;
for ( i = 0; i < digit; i++ ) {
if ( i > 0 ) {
delay(250);
}
longBeep();
}
}
void shortBeepRepeat( int digit ) {
#ifdef DEBUG
SerialCom.println("shortBeepRepeat: " );
SerialCom.println( digit);
#endif
int i;
for ( i = 0; i < digit; i++ ) {
if ( i > 0 ) {
delay(250);
}
shortBeep();
}
}
void beepAltitudeNew( long value)
{
char Apogee_String[5]; // Create an array with a buffer of 5 digits
ultoa(value, Apogee_String, 10); // Convert unsigned long to string array, radix 10 for decimal
//sprintf(Apogee_String,"%l", value);
uint8_t length = strlen(Apogee_String); // Get string length
delay(3000); // Pause for 3 seconds
for (uint8_t i = 0; i < length; i++ )
{
delay(1000); // Pause 1 second for every digit output
uint8_t digit = (Apogee_String[i] - '0'); // Convert ASCI to actual numerical digit
if ( digit == 0 ) {
digit = 10;
}
if ( digit == 0 ) {
longBeepRepeat(1);
}
else {
shortBeepRepeat(digit);
}
}
}
/*
*
* continuityCheckAsync()
* This will check continuity on all altimeter outputs then wait for 10s and do it again
* long beep = no continuity
* short beep = continuity
*/
void continuityCheckAsync()
{
#ifndef ALTIMULTIESP322222
int val = 0; // variable to store the read value
if (!noContinuity && !allApogeeFiredComplete )
{
if ((millis() - savedDelay ) > bigdelay ) {
if (lastPin == -1)
{
currentPin = continuityPins[currentPinPos];
currentPinPos++;
if (currentPinPos > pos)
{
currentPinPos = 0;
}
lastPin = currentPin;
if (currentPin != -1) {
val = digitalRead(currentPin);
if (val == 0)
{
// no continuity long beep
tempo = 1500;
}
else {
//short beep
tempo = 300;
}
tone(pinSpeaker, beepingFrequency);
startTempo = millis();
}
else {
noTone(pinSpeaker);
}
}
else {
if ((millis() - startTempo ) > tempo && tempo > 0) {
//Serial1.print("End tempo:");
//Serial1.println((millis() - startTempo ));
noTone(pinSpeaker);
tempo = 0;
tempo2 = 500;
startTempo2 = millis();
}
else {
if ((millis() - startTempo2 ) > tempo2 && tempo2 > 0) {
lastPin = -1;
if (currentPinPos == 0) {
// Then 10s delay
bigdelay = 10000;
savedDelay = millis();
}
tempo2 = 0;
}
}
}
}
}
else
noTone(pinSpeaker);
#endif
}