From 4c8af5fd1bb72e93a0a21c676fc0547f91c88a1c Mon Sep 17 00:00:00 2001 From: Pavel Brychta Date: Tue, 24 Mar 2020 08:44:11 +0100 Subject: [PATCH] Formatovani, drobne korektury. --- library.json | 2 +- library.properties | 2 +- src/SigLed.cpp | 142 ++++++++++++++++++++++----------------------- src/SigLed.h | 62 +++++++++----------- 4 files changed, 98 insertions(+), 110 deletions(-) diff --git a/library.json b/library.json index 95c0006..4f3682e 100644 --- a/library.json +++ b/library.json @@ -12,7 +12,7 @@ "type": "git", "url": "http://git.xpablo.cz/xPablo.cz/SigLed" }, - "version": "1.0.0", + "version": "1.0.1", "license": "MIT", "frameworks": "arduino", "platforms": "*", diff --git a/library.properties b/library.properties index 292ab5a..9d5a3ff 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=SigLED -version=1.0.0 +version=1.0.1 author=Pavel Brychta maintainer=Pavel Brychta sentence=Handle signalling LED easily diff --git a/src/SigLed.cpp b/src/SigLed.cpp index 8bfee0b..17a4e14 100644 --- a/src/SigLed.cpp +++ b/src/SigLed.cpp @@ -4,110 +4,108 @@ SigLED::SigLED(int pin, int ledon, int ledoff) { - _pin = pin; - _ledon = ledon; - _ledoff = ledoff; + + _pin = pin; + _ledon = ledon; + _ledoff = ledoff; } void SigLED::rtLed(void) { - switch (_state) - { - case LS_RUN: - { - uint8_t instr; + switch (_state) { + case LS_RUN: { + uint8_t instr; - if (NULL != _signal) - instr = *_ptr; // instrukce - else if (NULL != _psignal) - instr = pgm_read_byte(_pptr); - else - instr = LEDS_STOP; - switch (instr & 0xc0) - { - case LEDS_ONFOR: - digitalWrite(_pin, _ledon); - _timer = 10ul * ((instr & 0x3F) + 1); - _state = LS_WAIT; - break; + if (NULL != _signal) + instr = *_ptr; // instrukce + else if (NULL != _psignal) + instr = pgm_read_byte(_pptr); + else + instr = LEDS_STOP; + switch (instr & 0xc0) { + case LEDS_ONFOR: + digitalWrite(_pin, _ledon); + _timer = 10ul * ((instr & 0x3F) + 1); + _state = LS_WAIT; + break; - case LEDS_OFFFOR: - digitalWrite(_pin, _ledoff); - _timer = 10ul * ((instr & 0x3F) + 1); - _state = LS_WAIT; - break; + case LEDS_OFFFOR: + digitalWrite(_pin, _ledoff); + _timer = 10ul * ((instr & 0x3F) + 1); + _state = LS_WAIT; + break; - case LEDS_STOP: - _state = LS_IDLE; - break; + case LEDS_STOP: + _state = LS_IDLE; + break; - case LEDS_RESTART: - _ptr = _signal; - _pptr = _psignal; - break; - } - } - break; + case LEDS_RESTART: + _ptr = _signal; + _pptr = _psignal; + break; + } + } + break; - case LS_WAIT: - --_timer; - if (0 == _timer) - { - _state = LS_RUN; - ++_ptr; - ++_pptr; - } - break; + case LS_WAIT: + --_timer; + if (0 == _timer) { + _state = LS_RUN; + ++_ptr; + ++_pptr; + } + break; - default: - break; - } + default: + break; + } } void SigLED::begin(void) { - pinMode(_pin, OUTPUT); - digitalWrite(_pin, _ledoff); - _state = LS_IDLE; - _handler.attach_ms(10, lh, this); + pinMode(_pin, OUTPUT); + digitalWrite(_pin, _ledoff); + _state = LS_IDLE; + _handler.attach_ms(10, lh, this); } void SigLED::set(const uint8_t *signal) { - noInterrupts(); - _signal = signal; - _ptr = _signal; - _psignal = NULL; - _state = LS_RUN; - interrupts(); + noInterrupts(); + _signal = signal; + _ptr = _signal; + _psignal = NULL; + _state = LS_RUN; + interrupts(); } void SigLED::set(PGM_P signal) { - noInterrupts(); - _psignal = signal; - _pptr = _psignal; - _signal = NULL; - _state = LS_RUN; - interrupts(); + + noInterrupts(); + _psignal = signal; + _pptr = _psignal; + _signal = NULL; + _state = LS_RUN; + interrupts(); } -void SigLED::start() +void SigLED::start(void) { - noInterrupts(); - _ptr = _signal; - _pptr = _psignal; - _state = LS_RUN; - interrupts(); + noInterrupts(); + _ptr = _signal; + _pptr = _psignal; + _state = LS_RUN; + interrupts(); } void SigLED::lh(SigLED *ptr) { - SigLED *pled = ptr; - pled->rtLed(); + SigLED *pled = ptr; + pled->rtLed(); } diff --git a/src/SigLed.h b/src/SigLed.h index 8697e3a..453d77a 100644 --- a/src/SigLed.h +++ b/src/SigLed.h @@ -25,47 +25,37 @@ #include #include -typedef struct -{ - -}ledsignal_t; - -enum -{ - LEDS_ONFOR = 0x00, // rozsviti LED na delku, ktera je uvedena v nizsich 6-ti bitech (+1) [100ms], 0 znamena, ze se rozsviti na 100ms - LEDS_OFFFOR = 0x40, - LEDS_STOP = 0x80, - LEDS_RESTART = 0xc0 +enum { + LEDS_ONFOR = 0x00, // rozsviti LED na delku, ktera je uvedena v nizsich 6-ti bitech (+1) [100ms], 0 znamena, ze se rozsviti na 100ms + LEDS_OFFFOR = 0x40, + LEDS_STOP = 0x80, + LEDS_RESTART = 0xc0 }; class SigLED { -// typedef void (LED::*runtime)(void); - protected: - int _pin; // pin, na kterem je LED pripojena - Ticker _handler; // obsluha LED signalizace - const uint8_t *_signal; // ukazatel na vzor signalizace - PGM_P _psignal; - const uint8_t *_ptr; // ukazatel na aktualne zpracovavane misto v signalizaci - PGM_P _pptr; - uint32_t _timer; // casovani - int _ledon; - int _ledoff; - enum - { - LS_IDLE, // klid, cekame na zmenu (zavolani set, nebo start) - LS_RUN, // bezi automat - LS_WAIT, // cekame v automatu - }_state; // stav automatu - public: - SigLED(int pin, int ledon, int ledoff); - void begin(void); - void set(const uint8_t *signal); -// void set(const __FlashStringHelper *signal); - void set(PGM_P signal); - void start(); -// static void lh(void *ptr); +protected: + int _pin; // pin, na kterem je LED pripojena + Ticker _handler; // obsluha LED signalizace + const uint8_t *_signal; // ukazatel na vzor signalizace + PGM_P _psignal; + const uint8_t *_ptr; // ukazatel na aktualne zpracovavane misto v signalizaci + PGM_P _pptr; + uint32_t _timer; // casovani + int _ledon; + int _ledoff; + enum { + LS_IDLE, // klid, cekame na zmenu (zavolani set, nebo start) + LS_RUN, // bezi automat + LS_WAIT, // cekame v automatu + } _state; // stav automatu +public: + SigLED(int pin, int ledon, int ledoff); + void begin(void); + void set(const uint8_t *signal); + void set(PGM_P signal); + void start(void); static void lh(SigLED *ptr); void rtLed(void); // vykonna metoda };