-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPixelEffect_Fade.h
62 lines (55 loc) · 1.45 KB
/
PixelEffect_Fade.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
59
60
61
62
#ifndef PIXELEFFECT_FADE_H_INCLUDED
#define PIXELEFFECT_FADE_H_INCLUDED
#include "PixelEffect.h"
#include "Timer.h"
/**
This class fades the current display. The cbFinished will be called
when this effect is complete
*/
class PixelEffect_Fade : public PixelEffectWithCallback
{
private:
/** run states */
typedef enum {kInit, kTimer, kFinished} State;
/** timer */
Opcom::Timer m_timer;
/** current run state */
State m_state;
public:
/**
Create a fader using delay between steps
@param strip Physical strip or logical Panel pointer
@param delay Delay between each fade step
*/
PixelEffect_Fade(PixelStrip *strip, uint32_t delay) :
PixelEffectWithCallback(strip), m_timer(delay)
{
}
void init() {
m_state = kInit;
}
void run()
{
if(m_strip == NULL || !isEnabled()) return;
switch(m_state)
{
case kInit:
m_state = kTimer;
m_timer.reset();
// no break
case kTimer:
if(m_strip->getBrightness() > 0) {
if(!m_timer.hasPeriodPassed())
break;
m_strip->setBrightness(m_strip->getBrightness() - 1);
m_timer.reset();
} else {
m_state = kFinished;
}
case kFinished:
if(cbFinished) cbFinished(this);
break;
}
}
};
#endif // PIXELEFFECT_FADE_H_INCLUDED