|
@@ -46,7 +46,7 @@ class Buzzer {
|
46
|
46
|
private:
|
47
|
47
|
struct state_t {
|
48
|
48
|
tone_t tone;
|
49
|
|
- uint32_t timestamp;
|
|
49
|
+ uint32_t endtime;
|
50
|
50
|
} state;
|
51
|
51
|
|
52
|
52
|
protected:
|
|
@@ -82,7 +82,7 @@ class Buzzer {
|
82
|
82
|
*/
|
83
|
83
|
void reset() {
|
84
|
84
|
this->off();
|
85
|
|
- this->state.timestamp = 0;
|
|
85
|
+ this->state.endtime = 0;
|
86
|
86
|
}
|
87
|
87
|
|
88
|
88
|
public:
|
|
@@ -97,7 +97,7 @@ class Buzzer {
|
97
|
97
|
/**
|
98
|
98
|
* @brief Add a tone to the queue
|
99
|
99
|
* @details Adds a tone_t structure to the ring buffer, will block IO if the
|
100
|
|
- * queue is full waiting for one slot to get available.
|
|
100
|
+ * queue is full waiting for one slot to get available.
|
101
|
101
|
*
|
102
|
102
|
* @param duration Duration of the tone in milliseconds
|
103
|
103
|
* @param frequency Frequency of the tone in hertz
|
|
@@ -114,17 +114,17 @@ class Buzzer {
|
114
|
114
|
/**
|
115
|
115
|
* @brief Loop function
|
116
|
116
|
* @details This function should be called at loop, it will take care of
|
117
|
|
- * playing the tones in the queue.
|
|
117
|
+ * playing the tones in the queue.
|
118
|
118
|
*/
|
119
|
119
|
virtual void tick() {
|
120
|
|
- if (!this->state.timestamp) {
|
|
120
|
+ if (!this->state.endtime) {
|
121
|
121
|
if (this->buffer.isEmpty()) return;
|
122
|
122
|
|
123
|
123
|
this->state.tone = this->buffer.dequeue();
|
124
|
|
- this->state.timestamp = millis() + this->state.tone.duration;
|
|
124
|
+ this->state.endtime = millis() + this->state.tone.duration;
|
125
|
125
|
if (this->state.tone.frequency > 0) this->on();
|
126
|
126
|
}
|
127
|
|
- else if (millis() >= this->state.timestamp) this->reset();
|
|
127
|
+ else if (ELAPSED(millis(), this->state.endtime)) this->reset();
|
128
|
128
|
}
|
129
|
129
|
};
|
130
|
130
|
|