6 #ifndef __STATUSLED_H__
7 #define __STATUSLED_H__
16 enum Mode { nothing=0, pairing=1,send=2, ack=3,
17 nack=4, bat_low=5, welcome=6, key_long=7, failure=8 };
30 template <
class PINTYPE=ArduinoPins>
39 void copyPattern (Mode stat,
const BlinkPattern* patt) {
40 memcpy_P(¤t,patt+stat,
sizeof(BlinkPattern));
44 tick = decis2ticks(current.pattern[step++]);
45 ((step & 0x01) == 0x01) ? ledOn() : ledOff();
50 Led () :
Alarm(0), step(0), repeat(0), pin(0), inv(
false) {
55 void init (uint8_t p) {
57 PINTYPE::setOutput(pin);
61 void invert (
bool value) {
65 bool invert ()
const {
69 void set(Mode stat,
const BlinkPattern* patt) {
70 sysclock.cancel(*
this);
72 copyPattern(stat,patt);
73 if( current.length > 0 ) {
81 if( invert() ==
true ) {
82 PINTYPE::setHigh(pin);
90 if( invert() ==
true ) {
94 PINTYPE::setHigh(pin);
98 void ledOn (uint32_t ticks) {
99 if( active() ==
false && ticks > 0 ) {
101 current.duration = 1;
102 current.pattern[0] = ticks2decis(ticks);
103 current.pattern[1] = 0;
110 bool active ()
const {
return current.length != 0; }
113 ATOMIC_BLOCK( ATOMIC_RESTORESTATE ) {
114 if( step < current.length ) {
119 if( current.duration == 0 || ++repeat < current.duration ) {
124 copyPattern(nothing,single);
131 template<u
int8_t LEDPIN1,
class PINTYPE=ArduinoPins>
139 void init () { led1.init(LEDPIN1); }
140 bool active ()
const {
return led1.active(); }
141 void ledOn (uint32_t ticks) { led1.ledOn(ticks); }
142 void ledOn (uint32_t ticks,__attribute__((unused)) uint32_t tacks) { led1.ledOn(ticks); }
143 void set(Mode stat) { led1.set(stat,single); }
144 void ledOn () { led1.ledOn(); }
145 void ledOff () { led1.ledOff(); }
146 void invert (
bool value) { led1.invert(value); }
149 template <u
int8_t LEDPIN1,u
int8_t LEDPIN2,
class PINTYPE1=ArduinoPins,
class PINTYPE2=ArduinoPins>
156 void init () { led1.init(LEDPIN1); led2.init(LEDPIN2); }
157 bool active ()
const {
return led1.active() || led2.active(); }
158 void ledOn (uint32_t ticks) { led1.ledOn(ticks); led2.ledOn(ticks); }
159 void ledOn (uint32_t ticks,uint32_t tacks) { led1.ledOn(ticks); led2.ledOn(tacks); }
160 void set(Mode stat) { led1.set(stat,dual1); led2.set(stat,dual2); }
161 void ledOn () { led1.ledOn(); led2.ledOn(); }
162 void ledOff () { led1.ledOff(); led2.ledOff(); }
163 void invert (
bool value) { led1.invert(value); led2.invert(value); }
170 bool active ()
const {
return false; }
171 void ledOn (__attribute__((unused)) uint32_t ticks) {}
172 void ledOn (__attribute__((unused)) uint32_t ticks,__attribute__((unused)) uint32_t tacks) {}
173 void set(__attribute__((unused)) LedStates::Mode stat) {}
176 void invert (__attribute__((unused))
bool value) {}