-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathArduinoBuzzerSoundsRG.h
116 lines (94 loc) · 3.76 KB
/
ArduinoBuzzerSoundsRG.h
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
#ifndef ARDUINO_BUZZER_SOUNDS_RG_H
#define ARDUINO_BUZZER_SOUNDS_RG_H
#include <Arduino.h> // will not hurt, as it contains guards against multiple definition
/* ############### BuzzerSoundsRgBase ############### */
class BuzzerSoundsRgBase { // Class Declaration
public:
// Definition of Morse Code timings and sound-types
enum class MorseCodeTiming {
// International Morse code is composed of five elements:
// short mark, dot or dit ( . ): "dit duration" is one time unit long
// long mark, dash or dah ( _ ): three time units long
// inter-element gap between the dits and dahs within a character: one dot duration or one unit long
// short gap (between letters): three time units long
// medium gap (between words): seven time units long
DitLength = 100, // short signal
DitPause = 100, // break between signals/signs
DahLength = 300, // long signal = Dah = 3xDit
DahPause = 300, // break between characters in a word
WordPause = 700 // break between words
};
// Definition of SoundTypes
enum class SoundType {
DbReadError,
NoAuth,
AuthOk,
SOS,
SMS,
OK
};
// Constructor
explicit BuzzerSoundsRgBase(int buzzerPin);
// virtual destructor
virtual ~BuzzerSoundsRgBase();
// method to play a sound based on enum type
void playSound(SoundType sound);
protected:
// methods
virtual void pause(BuzzerSoundsRgBase::MorseCodeTiming pause) = 0; // Reine virtuelle Methode
// this abstract method needs to be redefined depending on the usage with or without Rtos:
//
// class BuzzerSoundsRgNonRtos : public BuzzerSoundsRgBase {
// public:
// // derived class constructor calls base class constructor
// BuzzerSoundsRgNonRtos(int buzzerPin) : BuzzerSoundsRgBase(buzzerPin) {}
//
// redefine abstract method into concrete implementation for use without Rtos
// void pause(int time_in_ms) override {
// delay(time_in_ms); // Standard Arduino delay
// }
// };
//
// class BuzzerSoundsRgRtos : public BuzzerSoundsRgBase {
// public:
// // derived class constructor calls base class constructor
// BuzzerSoundsRgRtos(int buzzerPin) : BuzzerSoundsRgBase(buzzerPin) {}
//
// redefine abstract method into concrete implementation for use with Rtos
// void pause(int time_in_ms) override {
// vTaskDelay(pdMS_TO_TICKS(time_in_ms)); // Rtos delay
// }
// };
private:
// attributes
int _buzzerPin;
// methods
void db_read_error_sound();
void no_auth_sound();
void auth_ok_sound();
void sos_sound();
void sms_sound();
void ok_sound();
};
/* ############### BuzzerSoundsRgRtos ############### */
// should be derived in specific programs to avoid dependency on Rtos HERE
// class BuzzerSoundsRgRtos : public BuzzerSoundsRgBase {
// public:
// // derived class constructor calls base class constructor
// BuzzerSoundsRgRtos(int buzzerPin) : BuzzerSoundsRgBase(buzzerPin) {}
//
// // redefine abstract method into concrete implementation for use with rtos
// void pause(BuzzerSoundsRgBase::MorseCodeTiming pause) {
// vTaskDelay(pdMS_TO_TICKS(static_cast<int>(pause))); // Standard Arduino delay
// }
// };
/* ############### BuzzerSoundsRgNonRtos ############### */
class BuzzerSoundsRgNonRtos : public BuzzerSoundsRgBase {
public:
// derived class constructor calls base class constructor
BuzzerSoundsRgNonRtos(int buzzerPin) : BuzzerSoundsRgBase(buzzerPin) {}
protected:
// redefine abstract method into concrete implementation for use without Rtos
void pause(BuzzerSoundsRgBase::MorseCodeTiming pause) override; // for Stadnard Arduino / c++ Delay
};
#endif // ARDUINO_BUZZER_SOUNDS_RG_H