2020-06-20 14:27:58 +03:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <Arduino.h>
|
|
|
|
|
|
|
|
|
|
class UptimeInterval {
|
|
|
|
|
public:
|
2020-06-22 03:11:02 +03:00
|
|
|
UptimeInterval(unsigned long interval, boolean postpone = true) : _next{0}, _interval{interval} {
|
2020-06-20 14:27:58 +03:00
|
|
|
reset(postpone);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
boolean check() {
|
|
|
|
|
if (_next <= get()) {
|
|
|
|
|
_next += _interval;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void reset(bool postpone = true) {
|
|
|
|
|
_next = (postpone ? _uptime_seconds + _interval : _uptime_seconds);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static unsigned long get() {
|
|
|
|
|
unsigned long _uptime_seconds = millis() / 1000;
|
|
|
|
|
return _uptime_seconds;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static unsigned long _uptime_seconds;
|
|
|
|
|
|
|
|
|
|
private:
|
2020-06-22 03:11:02 +03:00
|
|
|
unsigned long _next, _interval;
|
2020-06-20 14:27:58 +03:00
|
|
|
};
|