-
Notifications
You must be signed in to change notification settings - Fork 71
/
Led.cpp
75 lines (64 loc) · 1.81 KB
/
Led.cpp
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
63
64
65
66
67
68
69
70
71
72
73
74
75
#include "AlarmClock.h"
#include "Led.h"
namespace as {
StatusLed sled;
const StatusLed::BlinkPattern pattern [11] PROGMEM = {
{0, 0, {0 , 0 } }, // 0; define nothing
{2, 60, {5, 5,} }, // 1; define pairing string
{2, 1, {20, 0,} }, // 2; define pairing success
{2, 3, {1, 1,} }, // 3; define pairing error
{2, 1, {1, 1,} }, // 4; define send indicator
{0, 0, {0, 0,} }, // 5; define ack indicator
{0, 0, {0, 0,} }, // 6; define no ack indicator
{6, 3, {5, 1, 1, 1, 1, 10} }, // 7; define battery low indicator
{6, 3, {1, 1, 1, 1, 1, 10} }, // 8; define defect indicator
{6, 1, {1, 1, 5, 1, 5, 10} }, // 9; define welcome indicator
{2, 6, {2, 2, } }, // 10; key long indicator
};
void StatusLed::copyPattern (Mode stat) {
memcpy_P(¤t,&pattern[stat],sizeof(BlinkPattern));
}
void StatusLed::set(Mode stat) {
aclock.cancel(*this);
ledOff();
copyPattern(stat);
if( current.length > 0 ) {
step = 0;
repeat = 0;
next(aclock);
}
}
void StatusLed::ledOn (uint8_t ticks) {
if( active() == false && ticks > 0 ) {
current.length = 2;
current.duration = 1;
current.pattern[0] = ticks;
current.pattern[1] = 0;
// start the pattern
step = repeat = 0;
next(aclock);
}
}
void StatusLed::next (AlarmClock& clock) {
tick = current.pattern[step++];
((step & 0x01) == 0x01) ? ledOn() : ledOff();
clock.add(*this);
}
void StatusLed::trigger (AlarmClock& clock) {
ATOMIC_BLOCK( ATOMIC_RESTORESTATE ) {
if( step < current.length ) {
next(clock);
}
else {
step = 0;
if( current.duration == 0 || ++repeat < current.duration ) {
next(clock);
}
else {
ledOff();
copyPattern(nothing);
}
}
}
}
}