48 lines
829 B
C++
48 lines
829 B
C++
#ifndef LedManager_cpp
|
|
#define LedManager_cpp
|
|
|
|
#include "LED.cpp"
|
|
#include "TimerManager.cpp"
|
|
#include <map>
|
|
#include <functional>
|
|
|
|
class LedManager {
|
|
TimerManager *_timers;
|
|
std::map<int, LED *> _leds;
|
|
|
|
public:
|
|
LedManager(TimerManager *timers) {
|
|
_timers = timers;
|
|
}
|
|
|
|
void registerLEDs(int id, LED *leds) {
|
|
_leds[id] = leds;
|
|
_timers->add(id, [&]() { leds->off(); });
|
|
}
|
|
|
|
void loop() {
|
|
for (auto iterator = _leds.begin(); iterator != _leds.end(); ++iterator) {
|
|
auto leds = iterator->second;
|
|
leds->loop();
|
|
}
|
|
}
|
|
|
|
void setLedProperties(int id, bool on, float brightness, unsigned long timer) {
|
|
if (!_leds.count(id))
|
|
return;
|
|
|
|
auto led = _leds.find(id)->second;
|
|
|
|
led->setBrightness(brightness);
|
|
|
|
if (on)
|
|
led->on();
|
|
else
|
|
led->off();
|
|
|
|
if (timer > 0)
|
|
_timers->reset(id, timer);
|
|
}
|
|
};
|
|
|
|
#endif
|