unify periodic timers
This commit is contained in:
1 parent
132e54ecc5
commit
5f3e8b5309
7 files changed
+76
-58
No files matched your search
@@ -0,0 +1,19 @@
|
||||
#include "PeriodicTask.h"
|
||||
#include "Periodic.h"
|
||||
|
||||
PeriodicTask::PeriodicTask(uint32_t initialPeriod) : period(initialPeriod)
|
||||
{
|
||||
}
|
||||
|
||||
/// call this from loop
|
||||
void PeriodicTask::loop()
|
||||
{
|
||||
uint32_t now = millis();
|
||||
if (period && (now - lastMsec) >= period)
|
||||
{
|
||||
lastMsec = now;
|
||||
period = doTask();
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t Periodic::doTask() { return callback(); }
|
||||
Reference in new issue
Block a user