Formatovani, drobne korektury.

This commit is contained in:
Pavel Brychta 2020-03-24 08:44:11 +01:00
parent 3ff15595af
commit 4c8af5fd1b
4 changed files with 98 additions and 110 deletions

View File

@ -12,7 +12,7 @@
"type": "git", "type": "git",
"url": "http://git.xpablo.cz/xPablo.cz/SigLed" "url": "http://git.xpablo.cz/xPablo.cz/SigLed"
}, },
"version": "1.0.0", "version": "1.0.1",
"license": "MIT", "license": "MIT",
"frameworks": "arduino", "frameworks": "arduino",
"platforms": "*", "platforms": "*",

View File

@ -1,5 +1,5 @@
name=SigLED name=SigLED
version=1.0.0 version=1.0.1
author=Pavel Brychta author=Pavel Brychta
maintainer=Pavel Brychta maintainer=Pavel Brychta
sentence=Handle signalling LED easily sentence=Handle signalling LED easily

View File

@ -4,110 +4,108 @@
SigLED::SigLED(int pin, int ledon, int ledoff) SigLED::SigLED(int pin, int ledon, int ledoff)
{ {
_pin = pin;
_ledon = ledon; _pin = pin;
_ledoff = ledoff; _ledon = ledon;
_ledoff = ledoff;
} }
void SigLED::rtLed(void) void SigLED::rtLed(void)
{ {
switch (_state) switch (_state) {
{ case LS_RUN: {
case LS_RUN: uint8_t instr;
{
uint8_t instr;
if (NULL != _signal) if (NULL != _signal)
instr = *_ptr; // instrukce instr = *_ptr; // instrukce
else if (NULL != _psignal) else if (NULL != _psignal)
instr = pgm_read_byte(_pptr); instr = pgm_read_byte(_pptr);
else else
instr = LEDS_STOP; instr = LEDS_STOP;
switch (instr & 0xc0) switch (instr & 0xc0) {
{ case LEDS_ONFOR:
case LEDS_ONFOR: digitalWrite(_pin, _ledon);
digitalWrite(_pin, _ledon); _timer = 10ul * ((instr & 0x3F) + 1);
_timer = 10ul * ((instr & 0x3F) + 1); _state = LS_WAIT;
_state = LS_WAIT; break;
break;
case LEDS_OFFFOR: case LEDS_OFFFOR:
digitalWrite(_pin, _ledoff); digitalWrite(_pin, _ledoff);
_timer = 10ul * ((instr & 0x3F) + 1); _timer = 10ul * ((instr & 0x3F) + 1);
_state = LS_WAIT; _state = LS_WAIT;
break; break;
case LEDS_STOP: case LEDS_STOP:
_state = LS_IDLE; _state = LS_IDLE;
break; break;
case LEDS_RESTART: case LEDS_RESTART:
_ptr = _signal; _ptr = _signal;
_pptr = _psignal; _pptr = _psignal;
break; break;
} }
} }
break; break;
case LS_WAIT: case LS_WAIT:
--_timer; --_timer;
if (0 == _timer) if (0 == _timer) {
{ _state = LS_RUN;
_state = LS_RUN; ++_ptr;
++_ptr; ++_pptr;
++_pptr; }
} break;
break;
default: default:
break; break;
} }
} }
void SigLED::begin(void) void SigLED::begin(void)
{ {
pinMode(_pin, OUTPUT); pinMode(_pin, OUTPUT);
digitalWrite(_pin, _ledoff); digitalWrite(_pin, _ledoff);
_state = LS_IDLE; _state = LS_IDLE;
_handler.attach_ms(10, lh, this); _handler.attach_ms(10, lh, this);
} }
void SigLED::set(const uint8_t *signal) void SigLED::set(const uint8_t *signal)
{ {
noInterrupts(); noInterrupts();
_signal = signal; _signal = signal;
_ptr = _signal; _ptr = _signal;
_psignal = NULL; _psignal = NULL;
_state = LS_RUN; _state = LS_RUN;
interrupts(); interrupts();
} }
void SigLED::set(PGM_P signal) void SigLED::set(PGM_P signal)
{ {
noInterrupts();
_psignal = signal; noInterrupts();
_pptr = _psignal; _psignal = signal;
_signal = NULL; _pptr = _psignal;
_state = LS_RUN; _signal = NULL;
interrupts(); _state = LS_RUN;
interrupts();
} }
void SigLED::start() void SigLED::start(void)
{ {
noInterrupts(); noInterrupts();
_ptr = _signal; _ptr = _signal;
_pptr = _psignal; _pptr = _psignal;
_state = LS_RUN; _state = LS_RUN;
interrupts(); interrupts();
} }
void SigLED::lh(SigLED *ptr) void SigLED::lh(SigLED *ptr)
{ {
SigLED *pled = ptr; SigLED *pled = ptr;
pled->rtLed(); pled->rtLed();
} }

View File

@ -25,47 +25,37 @@
#include <Ticker.h> #include <Ticker.h>
#include <pgmspace.h> #include <pgmspace.h>
typedef struct 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,
}ledsignal_t; 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 class SigLED
{ {
// typedef void (LED::*runtime)(void);
protected: protected:
int _pin; // pin, na kterem je LED pripojena int _pin; // pin, na kterem je LED pripojena
Ticker _handler; // obsluha LED signalizace Ticker _handler; // obsluha LED signalizace
const uint8_t *_signal; // ukazatel na vzor signalizace const uint8_t *_signal; // ukazatel na vzor signalizace
PGM_P _psignal; PGM_P _psignal;
const uint8_t *_ptr; // ukazatel na aktualne zpracovavane misto v signalizaci const uint8_t *_ptr; // ukazatel na aktualne zpracovavane misto v signalizaci
PGM_P _pptr; PGM_P _pptr;
uint32_t _timer; // casovani uint32_t _timer; // casovani
int _ledon; int _ledon;
int _ledoff; int _ledoff;
enum enum {
{ LS_IDLE, // klid, cekame na zmenu (zavolani set, nebo start)
LS_IDLE, // klid, cekame na zmenu (zavolani set, nebo start) LS_RUN, // bezi automat
LS_RUN, // bezi automat LS_WAIT, // cekame v automatu
LS_WAIT, // cekame v automatu } _state; // stav automatu
}_state; // stav automatu public:
public: SigLED(int pin, int ledon, int ledoff);
SigLED(int pin, int ledon, int ledoff); void begin(void);
void begin(void); void set(const uint8_t *signal);
void set(const uint8_t *signal); void set(PGM_P signal);
// void set(const __FlashStringHelper *signal); void start(void);
void set(PGM_P signal);
void start();
// static void lh(void *ptr);
static void lh(SigLED *ptr); static void lh(SigLED *ptr);
void rtLed(void); // vykonna metoda void rtLed(void); // vykonna metoda
}; };