2020-12-15 19:32:50 -07:00
|
|
|
#include "pulse.h"
|
|
|
|
|
|
|
|
#include <Arduino.h>
|
|
|
|
|
|
|
|
Pulse::Pulse(unsigned long period) {
|
|
|
|
this->period = period;
|
|
|
|
this->nextEventMillis = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Pulse::Ticked() {
|
2020-12-19 16:46:43 -07:00
|
|
|
return Ticked(millis());
|
|
|
|
}
|
2020-12-15 19:32:50 -07:00
|
|
|
|
2020-12-19 16:46:43 -07:00
|
|
|
bool Pulse::Ticked(unsigned long now) {
|
2020-12-15 19:32:50 -07:00
|
|
|
if (now >= nextEventMillis) {
|
|
|
|
Until(period, now);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Pulse::Until(unsigned long next, unsigned long now) {
|
|
|
|
nextEventMillis = now + next;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Pulse::Until(unsigned long next) {
|
|
|
|
Until(next, millis());
|
|
|
|
}
|