mirror of
https://github.com/meshtastic/firmware.git
synced 2025-08-10 23:47:12 +00:00
26 lines
533 B
C++
26 lines
533 B
C++
#include "PeriodicTask.h"
|
|
#include "Periodic.h"
|
|
|
|
PeriodicTask::PeriodicTask(uint32_t initialPeriod) : period(initialPeriod) {}
|
|
|
|
/// call this from loop
|
|
void PeriodicTask::loop()
|
|
{
|
|
{
|
|
meshtastic::LockGuard lg(&lock);
|
|
uint32_t now = millis();
|
|
if (!period || (now - lastMsec) < period) {
|
|
return;
|
|
}
|
|
lastMsec = now;
|
|
}
|
|
// Release the lock in case the task wants to change the period.
|
|
doTask();
|
|
}
|
|
|
|
void Periodic::doTask()
|
|
{
|
|
uint32_t p = callback();
|
|
setPeriod(p);
|
|
}
|