mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-26 22:22:16 +03:00
33 lines
698 B
C++
33 lines
698 B
C++
#pragma once
|
|
|
|
#include <Arduino.h>
|
|
|
|
class UptimeInterval {
|
|
public:
|
|
UptimeInterval(unsigned long interval, boolean postpone = true) : _next{0}, _interval{interval} {
|
|
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:
|
|
unsigned long _next, _interval;
|
|
};
|