Add a timer to turn off after a period of time. Move the LED name to reduce string literals.

This commit is contained in:
Robert Marshall 2021-08-27 09:02:35 +01:00
parent 59ec76b52f
commit c3e91d269e
5 changed files with 93 additions and 12 deletions

26
src/TimerManager.cpp Normal file
View file

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