From be4244d4827a1c4b85ca4bbe5eb852761a182021 Mon Sep 17 00:00:00 2001 From: Pablo2048 Date: Mon, 9 Oct 2023 10:33:45 +0200 Subject: [PATCH] Snizeni zatizeni systemu modulem signalizace - 10x snizena perioda preruseni, zachovana zpetna kompatibilita signalizace. --- src/SigLed.cpp | 58 ++++++++++++++++++++++++++++---------------------- src/SigLed.h | 1 + 2 files changed, 34 insertions(+), 25 deletions(-) diff --git a/src/SigLed.cpp b/src/SigLed.cpp index 182561f..20cd42d 100644 --- a/src/SigLed.cpp +++ b/src/SigLed.cpp @@ -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) diff --git a/src/SigLed.h b/src/SigLed.h index e243a26..52220a1 100644 --- a/src/SigLed.h +++ b/src/SigLed.h @@ -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);