firmware/src/concurrency/Periodic.h

27 lines
598 B
C
Raw Normal View History

#pragma once
2020-02-21 16:41:36 +00:00
#include "PeriodicTask.h"
2020-07-05 22:54:30 +00:00
namespace concurrency {
/**
2020-07-05 22:54:30 +00:00
* @brief Periodically invoke a callback. This just provides C-style callback conventions
* rather than a virtual function - FIXME, remove?
*/
2020-02-21 16:41:36 +00: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 16:41:36 +00:00
protected:
2020-07-05 22:54:30 +00:00
void doTask() {
uint32_t p = callback();
setPeriod(p);
}
};
2020-07-05 22:54:30 +00:00
} // namespace concurrency