Files
firmware/src/PeriodicTask.cpp

26 lines
533 B
C++
Raw Normal View History

2020-02-21 08:41:36 -08:00
#include "PeriodicTask.h"
#include "Periodic.h"
2020-03-15 19:27:42 -07:00
PeriodicTask::PeriodicTask(uint32_t initialPeriod) : period(initialPeriod) {}
2020-02-21 08:41:36 -08:00
/// call this from loop
void PeriodicTask::loop()
{
{
2020-03-15 19:27:42 -07:00
meshtastic::LockGuard lg(&lock);
uint32_t now = millis();
if (!period || (now - lastMsec) < period) {
return;
}
2020-02-21 08:41:36 -08:00
lastMsec = now;
}
2020-03-15 19:27:42 -07:00
// Release the lock in case the task wants to change the period.
doTask();
2020-02-21 08:41:36 -08:00
}
2020-02-21 10:20:47 -08:00
void Periodic::doTask()
{
uint32_t p = callback();
setPeriod(p);
2020-03-15 19:27:42 -07:00
}