Files
firmware/src/PeriodicTask.h

31 lines
724 B
C
Raw Normal View History

2020-02-06 07:39:21 -08:00
#pragma once
#include <Arduino.h>
#include "configuration.h"
2020-02-21 08:41:36 -08:00
/**
* A base class for tasks that want their doTask() method invoked periodically
*
* FIXME: currently just syntatic sugar for polling in loop (you must call .loop), but eventually
* generalize with the freertos scheduler so we can save lots of power by having everything either in
* something like this or triggered off of an irq.
*/
2020-02-06 07:39:21 -08:00
class PeriodicTask
{
2020-02-21 08:41:36 -08:00
uint32_t lastMsec = 0;
uint32_t period = 1; // call soon after creation
2020-02-06 07:39:21 -08:00
public:
uint32_t periodMsec;
virtual ~PeriodicTask() {}
2020-02-21 08:41:36 -08:00
PeriodicTask(uint32_t initialPeriod = 1);
2020-02-06 07:39:21 -08:00
/// call this from loop
2020-02-21 08:41:36 -08:00
virtual void loop();
2020-02-06 07:39:21 -08:00
2020-02-21 08:41:36 -08:00
protected:
virtual uint32_t doTask() = 0;
2020-02-06 07:39:21 -08:00
};