Move components to lib folder
This commit is contained in:
parent
ae3c20b59d
commit
b9b68f08cb
8 changed files with 1 additions and 0 deletions
32
lib/Timer/TimerManager.cpp
Normal file
32
lib/Timer/TimerManager.cpp
Normal 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
|
Loading…
Add table
Add a link
Reference in a new issue