Pridana autoinit schopnost

This commit is contained in:
Pavel Brychta 2020-03-24 09:10:02 +01:00
parent 4c8af5fd1b
commit c6c8c70af2
3 changed files with 16 additions and 7 deletions

View File

@ -1,3 +1,3 @@
# SigLed
Arduino knihovn pro signalizační LED
Arduino knihovna pro signalizační LED

View File

@ -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;

View File

@ -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 <Ticker.h>
#include <pgmspace.h>
@ -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