Snizeni zatizeni systemu modulem signalizace - 10x snizena perioda preruseni, zachovana zpetna kompatibilita signalizace.

This commit is contained in:
Pavel Brychta 2023-10-09 10:33:45 +02:00
parent ed47d70b22
commit be4244d482
2 changed files with 34 additions and 25 deletions

View File

@ -7,52 +7,60 @@ SigLED::SigLED(int pin, int ledon, int ledoff)
: _pin(pin), _ledon(ledon), _ledoff(ledoff), _state(LS_NOTINITIALIZED) : _pin(pin), _ledon(ledon), _ledoff(ledoff), _state(LS_NOTINITIALIZED)
{} {}
uint8_t SigLED::getInstruction()
{
uint8_t instr;
if (_signal)
instr = *_ptr; // instrukce
else if (_psignal)
instr = pgm_read_byte(_pptr);
else
instr = LEDS_STOP;
return instr;
}
void SigLED::rtLed() void SigLED::rtLed()
{ {
switch (_state) { switch (_state) {
case LS_RUN: {
uint8_t instr;
if (_signal) case LS_WAIT:
instr = *_ptr; // instrukce --_timer;
else if (_psignal) if (_timer != 0)
instr = pgm_read_byte(_pptr); break;
else _state = LS_RUN;
instr = LEDS_STOP; ++_ptr;
++_pptr;
// no break - we fall through LS_RUN state
case LS_RUN: {
uint8_t instr = getInstruction();
if ((instr & 0xc0) == LEDS_RESTART) {
_ptr = _signal;
_pptr = _psignal;
instr = getInstruction();
}
switch (instr & 0xc0) { switch (instr & 0xc0) {
case LEDS_ONFOR: case LEDS_ONFOR:
digitalWrite(_pin, _ledon); digitalWrite(_pin, _ledon);
_timer = 10ul * ((instr & 0x3F) + 1); _timer = (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 = (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:
_ptr = _signal;
_pptr = _psignal;
break;
} }
} break; } break;
case LS_WAIT:
--_timer;
if (0 == _timer) {
_state = LS_RUN;
++_ptr;
++_pptr;
}
break;
default: default:
break; break;
} }
@ -64,7 +72,7 @@ void SigLED::prepare()
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(100, lh, this);
} }
void SigLED::set(const uint8_t * signal) void SigLED::set(const uint8_t * signal)

View File

@ -54,6 +54,7 @@ class SigLED {
void prepare(); void prepare();
static void lh(SigLED * ptr); static void lh(SigLED * ptr);
void rtLed(); // vykonna metoda void rtLed(); // vykonna metoda
uint8_t getInstruction();
public: public:
SigLED(int pin, int ledon, int ledoff); SigLED(int pin, int ledon, int ledoff);