diff --git a/README.md b/README.md index f5f4b50..808133c 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,3 @@ # SigLed -Arduino knihovn pro signalizační LED \ No newline at end of file +Arduino knihovna pro signalizační LED \ No newline at end of file diff --git a/src/SigLed.cpp b/src/SigLed.cpp index 17a4e14..a50fa32 100644 --- a/src/SigLed.cpp +++ b/src/SigLed.cpp @@ -8,6 +8,7 @@ SigLED::SigLED(int pin, int ledon, int ledoff) _pin = pin; _ledon = ledon; _ledoff = ledoff; + _state = LS_NOTINITIALIZED; } void SigLED::rtLed(void) @@ -62,7 +63,7 @@ void SigLED::rtLed(void) } } -void SigLED::begin(void) +void SigLED::_init(void) { pinMode(_pin, OUTPUT); @@ -74,6 +75,8 @@ void SigLED::begin(void) void SigLED::set(const uint8_t *signal) { + if (LS_NOTINITIALIZED == _state) + _init(); noInterrupts(); _signal = signal; _ptr = _signal; @@ -82,9 +85,11 @@ void SigLED::set(const uint8_t *signal) interrupts(); } -void SigLED::set(PGM_P signal) +void SigLED::set_P(PGM_P signal) { + if (LS_NOTINITIALIZED == _state) + _init(); noInterrupts(); _psignal = signal; _pptr = _psignal; @@ -96,6 +101,8 @@ void SigLED::set(PGM_P signal) void SigLED::start(void) { + if (LS_NOTINITIALIZED == _state) + _init(); noInterrupts(); _ptr = _signal; _pptr = _psignal; diff --git a/src/SigLed.h b/src/SigLed.h index 453d77a..bb9b134 100644 --- a/src/SigLed.h +++ b/src/SigLed.h @@ -19,8 +19,8 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * */ -#ifndef _sigled_h_ -#define _sigled_h_ +#ifndef _SIGLED_H_ +#define _SIGLED_H_ #include #include @@ -46,15 +46,17 @@ protected: int _ledon; int _ledoff; enum { + LS_NOTINITIALIZED = 0, // neinicializovany stav LS_IDLE, // klid, cekame na zmenu (zavolani set, nebo start) LS_RUN, // bezi automat LS_WAIT, // cekame v automatu } _state; // stav automatu + void _init(void); + public: SigLED(int pin, int ledon, int ledoff); - void begin(void); void set(const uint8_t *signal); - void set(PGM_P signal); + void set_P(PGM_P signal); void start(void); static void lh(SigLED *ptr); void rtLed(void); // vykonna metoda