-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFastLEDLightRelay.h
59 lines (39 loc) · 1.13 KB
/
FastLEDLightRelay.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#ifndef _FastLEDLightRelay_h
#define _FastLEDLightRelay_h
#if defined(ARDUINO) && ARDUINO >= 100
#include "arduino.h"
#else
#include "WProgram.h"
#endif
#include "FastLEDLight.h"
#include <ClockTimer.hpp>
typedef std::function<void(void)> callback_function;
class FastLEDLightRelay : public FastLEDLight
{
public:
FastLEDLightRelay(callback_function relayON, callback_function relayOFF, LEDLine* ledLine, uint16_t effectDuration = 60);
void powerON() override;
void powerOFF() override;
private:
MillisTimer powerTimer;
callback_function relayON = nullptr;
callback_function relayOFF = nullptr;
};
FastLEDLightRelay::FastLEDLightRelay(callback_function relayON, callback_function relayOFF, LEDLine* ledLine, uint16_t effectDuration)
: FastLEDLight(ledLine, effectDuration), powerTimer(5000), relayON(relayON), relayOFF(relayOFF)
{
}
void FastLEDLightRelay::powerON()
{
if (powerTimer.isActive() && !powerTimer.isReady())
return;
FastLEDLight::powerON();
if (relayON != nullptr) relayON();
}
void FastLEDLightRelay::powerOFF()
{
powerTimer.start();
FastLEDLight::powerOFF();
if (relayOFF != nullptr) relayOFF();
}
#endif