firmware/src/concurrency/Periodic.h

25 lines
597 B
C
Raw Normal View History

#pragma once
#include "concurrency/OSThread.h"
2020-07-05 22:54:30 +00:00
namespace concurrency
{
/**
* @brief Periodically invoke a callback. This just provides C-style callback conventions
2020-07-05 22:54:30 +00:00
* rather than a virtual function - FIXME, remove?
*/
class Periodic : public OSThread
{
2020-10-10 01:57:57 +00:00
int32_t (*callback)();
public:
// callback returns the period for the next callback invocation (or 0 if we should no longer be called)
2020-10-10 01:57:57 +00:00
Periodic(const char *name, int32_t (*_callback)()) : OSThread(name), callback(_callback) {}
2020-02-21 16:41:36 +00:00
protected:
2020-10-10 01:57:57 +00:00
int32_t runOnce() { return callback(); }
};
2020-07-05 22:54:30 +00:00
} // namespace concurrency