Move to new folder in preparation for more controllers

This commit is contained in:
Robert Marshall 2022-09-08 13:11:16 +01:00
parent bcea2ee550
commit ae3c20b59d
18 changed files with 59 additions and 4 deletions

View file

@ -0,0 +1,32 @@
#ifndef TimerManager_cpp
#define TimerManager_cpp
#include <map>
#include <functional>
#include "Timer.cpp"
class TimerManager{
std::map<int, Timer*> _timers;
public:
void add(int id, std::function<void()> callback){
_timers[id] = new Timer(callback);
}
void reset(int id, unsigned long interval){
if (!_timers.count(id))
return;
_timers.find(id)->second->reset(interval);
}
void loop(){
for(auto iterator = _timers.begin(); iterator != _timers.end(); ++iterator)
{
auto timer = iterator->second;
timer->loop();
}
}
};
#endif