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,11 +7,8 @@ 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)
{} {}
void SigLED::rtLed() uint8_t SigLED::getInstruction()
{ {
switch (_state) {
case LS_RUN: {
uint8_t instr; uint8_t instr;
if (_signal) if (_signal)
@ -20,39 +17,50 @@ void SigLED::rtLed()
instr = pgm_read_byte(_pptr); instr = pgm_read_byte(_pptr);
else else
instr = LEDS_STOP; instr = LEDS_STOP;
return instr;
}
void SigLED::rtLed()
{
switch (_state) {
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) { 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);