Consolidates Buzzer and Speaker into a single object
This commit is contained in:
@@ -32,7 +32,6 @@
|
||||
/**
|
||||
* @brief Tone structure
|
||||
* @details Simple abstraction of a tone based on a duration and a frequency.
|
||||
*
|
||||
*/
|
||||
struct tone_t {
|
||||
uint16_t duration;
|
||||
@@ -116,14 +115,23 @@ class Buzzer {
|
||||
* playing the tones in the queue.
|
||||
*/
|
||||
virtual void tick() {
|
||||
const millis_t now = millis();
|
||||
|
||||
if (!this->state.endtime) {
|
||||
if (this->buffer.isEmpty()) return;
|
||||
|
||||
this->state.tone = this->buffer.dequeue();
|
||||
this->state.endtime = millis() + this->state.tone.duration;
|
||||
if (this->state.tone.frequency > 0) this->on();
|
||||
this->state.endtime = now + this->state.tone.duration;
|
||||
|
||||
if (this->state.tone.frequency > 0) {
|
||||
#if ENABLED(SPEAKER)
|
||||
::tone(BEEPER_PIN, this->state.tone.frequency, this->state.tone.duration);
|
||||
#else
|
||||
this->on();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
else if (ELAPSED(millis(), this->state.endtime)) this->reset();
|
||||
else if (ELAPSED(now, this->state.endtime)) this->reset();
|
||||
}
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user