Files
firmware/src/concurrency/Periodic.h

27 lines
598 B
C
Raw Normal View History

#pragma once
2020-02-21 08:41:36 -08:00
#include "PeriodicTask.h"
2020-07-06 00:54:30 +02:00
namespace concurrency {
/**
2020-07-06 00:54:30 +02:00
* @brief Periodically invoke a callback. This just provides C-style callback conventions
* rather than a virtual function - FIXME, remove?
*/
2020-02-21 08:41:36 -08:00
class Periodic : public PeriodicTask
{
uint32_t (*callback)();
public:
// callback returns the period for the next callback invocation (or 0 if we should no longer be called)
Periodic(uint32_t (*_callback)()) : callback(_callback) {}
2020-02-21 08:41:36 -08:00
protected:
2020-07-06 00:54:30 +02:00
void doTask() {
uint32_t p = callback();
setPeriod(p);
}
};
2020-07-06 00:54:30 +02:00
} // namespace concurrency