-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathBeepManager.cpp
160 lines (138 loc) · 3.53 KB
/
BeepManager.cpp
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
#include "BeepManager.h"
#include "defines.h"
// constructor
BeepManager::BeepManager(int pin) {
buzzerPin = pin;
pinMode(buzzerPin, OUTPUT);
}
// create tone
void BeepManager::ManualTone(int frequency, int duration) {
long period = 1000000L / frequency; // Berechne die Periode in Mikrosekunden
long cycles = (long)duration * 1000L / period; // Anzahl der Zyklen
for (long i = 0; i < cycles; i++) {
digitalWrite(buzzerPin, HIGH);
delayMicroseconds(period / 2); // Halbe Periode HIGH
digitalWrite(buzzerPin, LOW);
delayMicroseconds(period / 2); // Halbe Periode LOW
}
}
// create a beep
void BeepManager::Beep(int duration, int frequency) {
ManualTone(frequency, duration); // create beep
delay(200); // delay
}
// beep code for pitch axis
void BeepManager::CalibrationBeepPitch() {
Beep(BEEP_LONG_TONE, 1000);
Beep(BEEP_SHORT_TONE, 500);
delay(300);
}
// beep code for roll axis
void BeepManager::CalibrationBeepRoll() {
Beep(BEEP_LONG_TONE, 500);
Beep(BEEP_SHORT_TONE, 1000);
delay(300);
}
// Roll or Pitch code?
void BeepManager::CalibrationBeepAxis(bool isRoll) {
if(isRoll)
{
CalibrationBeepRoll();
}else{
CalibrationBeepPitch();
}
}
// system start
void BeepManager::SystemStart() {
Beep(200, 1000);
delay(1000);
}
// start calibration
void BeepManager::CalibrationStart() {
Beep(500, 600);
delay(500);
Beep(500, 600);
delay(500);
Beep(500, 600);
delay(1000);
}
// calibration successful finished
void BeepManager::CalibrationSuccess() {
Beep(100, 500);
delay(100);
Beep(100, 600);
delay(100);
Beep(300, 700);
delay(1000);
}
// Error on calibration
void BeepManager::CalibrationError() {
Beep(100, 600);
delay(100);
Beep(100, 600);
delay(100);
Beep(100, 600);
delay(200);
Beep(300, 600);
delay(200);
Beep(300, 600);
delay(200);
Beep(300, 600);
delay(200);
Beep(100, 600);
delay(100);
Beep(100, 600);
delay(100);
Beep(100, 600);
delay(1000);
}
// axis not moving timeout (short, short)
void BeepManager::CalibrationTimeoutMotor(bool isRoll) {
for(byte x=0; x<=BEEP_CODE_COUNT;x++)
{
CalibrationBeepAxis(isRoll);
Beep(BEEP_SHORT_TONE, BEEP_CODE_FREQUENCY);
Beep(BEEP_SHORT_TONE, BEEP_CODE_FREQUENCY);
delay(BEEP_CODE_DELAY);
}
}
// timeout for calibration (short, long)
void BeepManager::CalibrationTimeoutGeneral(bool isRoll) {
for(byte x=0; x<=BEEP_CODE_COUNT;x++)
{
CalibrationBeepAxis(isRoll);
Beep(BEEP_SHORT_TONE, BEEP_CODE_FREQUENCY);
Beep(BEEP_LONG_TONE, BEEP_CODE_FREQUENCY);
delay(BEEP_CODE_DELAY);
}
}
// motor goes in wrong direction (long, short)
void BeepManager::CalibrationMotorInverted(bool isRoll) {
for(byte x=0; x<=BEEP_CODE_COUNT;x++)
{
CalibrationBeepAxis(isRoll);
Beep(BEEP_LONG_TONE, BEEP_CODE_FREQUENCY);
Beep(BEEP_SHORT_TONE, BEEP_CODE_FREQUENCY);
delay(BEEP_CODE_DELAY);
}
}
// encoder counts in wrong direction (long,long)
void BeepManager::CalibrationEncoderInverted(bool isRoll) {
for(byte x=0; x<=BEEP_CODE_COUNT;x++)
{
CalibrationBeepAxis(isRoll);
Beep(BEEP_LONG_TONE, BEEP_CODE_FREQUENCY);
Beep(BEEP_LONG_TONE, BEEP_CODE_FREQUENCY);
delay(BEEP_CODE_DELAY);
}
}
void BeepManager::NoMotorPower() {
for(byte x=0; x<=BEEP_CODE_COUNT;x++)
{
Beep(BEEP_LONG_TONE, BEEP_CODE_FREQUENCY);
Beep(BEEP_LONG_TONE, BEEP_CODE_FREQUENCY);
Beep(BEEP_LONG_TONE, BEEP_CODE_FREQUENCY);
Beep(BEEP_LONG_TONE, BEEP_CODE_FREQUENCY);
delay(BEEP_CODE_DELAY);
}
}