timestamp => endtime

This commit is contained in:
Scott Lahteine 2016-07-10 19:36:46 -07:00
parent 71674059c3
commit d1dffc7ad1

View file

@ -46,7 +46,7 @@ class Buzzer {
private: private:
struct state_t { struct state_t {
tone_t tone; tone_t tone;
uint32_t timestamp; uint32_t endtime;
} state; } state;
protected: protected:
@ -82,7 +82,7 @@ class Buzzer {
*/ */
void reset() { void reset() {
this->off(); this->off();
this->state.timestamp = 0; this->state.endtime = 0;
} }
public: public:
@ -117,14 +117,14 @@ class Buzzer {
* playing the tones in the queue. * playing the tones in the queue.
*/ */
virtual void tick() { virtual void tick() {
if (!this->state.timestamp) { if (!this->state.endtime) {
if (this->buffer.isEmpty()) return; if (this->buffer.isEmpty()) return;
this->state.tone = this->buffer.dequeue(); this->state.tone = this->buffer.dequeue();
this->state.timestamp = millis() + this->state.tone.duration; this->state.endtime = millis() + this->state.tone.duration;
if (this->state.tone.frequency > 0) this->on(); if (this->state.tone.frequency > 0) this->on();
} }
else if (ELAPSED(millis(), this->state.timestamp)) this->reset(); else if (ELAPSED(millis(), this->state.endtime)) this->reset();
} }
}; };