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)
{}
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()
{
switch (_state) {
case LS_RUN: {
uint8_t instr;
if (_signal)
instr = *_ptr; // instrukce
else if (_psignal)
instr = pgm_read_byte(_pptr);
else
instr = LEDS_STOP;
case LS_WAIT:
--_timer;
if (_timer != 0)
break;
_state = LS_RUN;
++_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) {
case LEDS_ONFOR:
digitalWrite(_pin, _ledon);
_timer = 10ul * ((instr & 0x3F) + 1);
_timer = (instr & 0x3F) + 1;
_state = LS_WAIT;
break;
case LEDS_OFFFOR:
digitalWrite(_pin, _ledoff);
_timer = 10ul * ((instr & 0x3F) + 1);
_timer = (instr & 0x3F) + 1;
_state = LS_WAIT;
break;
case LEDS_STOP:
_state = LS_IDLE;
break;
case LEDS_RESTART:
_ptr = _signal;
_pptr = _psignal;
break;
}
} break;
case LS_WAIT:
--_timer;
if (0 == _timer) {
_state = LS_RUN;
++_ptr;
++_pptr;
}
break;
default:
break;
}
@ -64,7 +72,7 @@ void SigLED::prepare()
pinMode(_pin, OUTPUT);
digitalWrite(_pin, _ledoff);
_state = LS_IDLE;
_handler.attach_ms(10, lh, this);
_handler.attach_ms(100, lh, this);
}
void SigLED::set(const uint8_t * signal)

View File

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