Add a timer to turn off after a period of time. Move the LED name to reduce string literals.
This commit is contained in:
parent
59ec76b52f
commit
c3e91d269e
5 changed files with 93 additions and 12 deletions
26
src/TimerManager.cpp
Normal file
26
src/TimerManager.cpp
Normal 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();
|
||||
}
|
||||
}
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue