|
@@ -1,74 +0,0 @@
|
1
|
|
-/**
|
2
|
|
- * Marlin 3D Printer Firmware
|
3
|
|
- * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
4
|
|
- *
|
5
|
|
- * Based on Sprinter and grbl.
|
6
|
|
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
|
7
|
|
- *
|
8
|
|
- * This program is free software: you can redistribute it and/or modify
|
9
|
|
- * it under the terms of the GNU General Public License as published by
|
10
|
|
- * the Free Software Foundation, either version 3 of the License, or
|
11
|
|
- * (at your option) any later version.
|
12
|
|
- *
|
13
|
|
- * This program is distributed in the hope that it will be useful,
|
14
|
|
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15
|
|
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16
|
|
- * GNU General Public License for more details.
|
17
|
|
- *
|
18
|
|
- * You should have received a copy of the GNU General Public License
|
19
|
|
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
|
20
|
|
- *
|
21
|
|
- */
|
22
|
|
-
|
23
|
|
-#ifndef __SPEAKER_H__
|
24
|
|
-#define __SPEAKER_H__
|
25
|
|
-
|
26
|
|
-#include "buzzer.h"
|
27
|
|
-
|
28
|
|
-class Speaker: public Buzzer {
|
29
|
|
- private:
|
30
|
|
- typedef Buzzer super;
|
31
|
|
-
|
32
|
|
- struct state_t {
|
33
|
|
- tone_t tone;
|
34
|
|
- millis_t next;
|
35
|
|
- } state;
|
36
|
|
-
|
37
|
|
- protected:
|
38
|
|
- /**
|
39
|
|
- * @brief Resets the state of the class
|
40
|
|
- * @details Brings the class state to a known one.
|
41
|
|
- */
|
42
|
|
- void reset() {
|
43
|
|
- super::reset();
|
44
|
|
- this->state.next = 0;
|
45
|
|
- }
|
46
|
|
-
|
47
|
|
- public:
|
48
|
|
- /**
|
49
|
|
- * @brief Class constructor
|
50
|
|
- */
|
51
|
|
- Speaker() {
|
52
|
|
- this->reset();
|
53
|
|
- }
|
54
|
|
-
|
55
|
|
- /**
|
56
|
|
- * @brief Loop function
|
57
|
|
- * @details This function should be called at loop, it will take care of
|
58
|
|
- * playing the tones in the queue.
|
59
|
|
- */
|
60
|
|
- virtual void tick() {
|
61
|
|
- const uint32_t now = millis();
|
62
|
|
-
|
63
|
|
- if (now >= this->state.next) {
|
64
|
|
- if (this->buffer.isEmpty()) return;
|
65
|
|
-
|
66
|
|
- this->reset();
|
67
|
|
- this->state.tone = this->buffer.dequeue();
|
68
|
|
- this->state.next = now + this->state.tone.duration;
|
69
|
|
- ::tone(BEEPER_PIN, this->state.tone.frequency, this->state.tone.duration);
|
70
|
|
- }
|
71
|
|
- }
|
72
|
|
-};
|
73
|
|
-
|
74
|
|
-#endif
|