diff --git a/src/wsLED.cpp b/src/wsLED.cpp index 315c158..a9c36de 100644 --- a/src/wsLED.cpp +++ b/src/wsLED.cpp @@ -128,6 +128,7 @@ void ICACHE_RAM_ATTR wsLED::rtLed(void) switch (_ledState) { case LED_BLINK: + _handler.detach(); if (_subState) { _subState = 0; setColor(_color2); @@ -136,6 +137,7 @@ void ICACHE_RAM_ATTR wsLED::rtLed(void) setColor(_color1); } show(); + _handler.attach_ms(_blinkSpeed, lh, this); break; @@ -147,23 +149,31 @@ void ICACHE_RAM_ATTR wsLED::rtLed(void) _scale = (uint8_t)val; show(); val >>= 8; - _lastTiming = 30ul * val; - _handler.attach_ms(_lastTiming, lh, this); + uint32_t timing = 30ul * val; + _handler.attach_ms(timing, lh, this); break; } case LED_PULSE: { _handler.detach(); _ledState = _savedState; + _subState = 0; setColor(_color1); show(); - _handler.attach_ms(_lastTiming, lh, this); // vratime zpet puvodni casovani + _handler.attach_ms(1, lh, this); // co nejrychleji do predchoziho stavu break; } + case LED_PULSE_START: + _handler.detach(); + setColor(_pulseColor); + show(); + _ledState = LED_PULSE; + _handler.attach_ms(_pulseDuration, lh, this); + break; + default: _handler.detach(); -// _handler.attach_ms(300, lh, this); // jen pomale casovani break; } } @@ -185,7 +195,7 @@ void wsLED::setColors(LEDRGB color1, LEDRGB color2) } } -void wsLED::blink(int speed) +void wsLED::blink(uint32_t speed) { if (NOT_A_PIN != _pin) { @@ -194,8 +204,8 @@ void wsLED::blink(int speed) _ledState = LED_BLINK; _scale = 0xff; _subState = 1; - _lastTiming = 300; - _handler.attach_ms(_lastTiming, lh, this); + _blinkSpeed = speed; + _handler.attach_ms(1, lh, this); } } } @@ -209,8 +219,7 @@ void wsLED::breath(void) _ledState = LED_BREATH; _subState = 0; setColor(_color1); - _lastTiming = 1; - _handler.attach_ms(_lastTiming, lh, this); + _handler.attach_ms(1, lh, this); } } } @@ -227,13 +236,13 @@ void wsLED::pulse(LEDRGB color, uint32_t duration) if (NOT_A_PIN != _pin) { _handler.detach(); _scale = 0xff; - setColor(color); + _pulseColor = color; if (LED_PULSE != _ledState) { _savedState = _ledState; } - show(); - _ledState = LED_PULSE; - _handler.attach_ms(duration, lh, this); + _pulseDuration = duration; + _ledState = LED_PULSE_START; + _handler.attach_ms(5, lh, this); } } diff --git a/src/wsLED.h b/src/wsLED.h index 665a926..258b336 100644 --- a/src/wsLED.h +++ b/src/wsLED.h @@ -117,6 +117,7 @@ typedef enum { LED_STOP = 0, LED_BLINK, LED_BREATH, + LED_PULSE_START, LED_PULSE, LED_PATTERN, }ledstate_t; @@ -135,7 +136,9 @@ protected: ledstate_t _ledState; // stav LEDky (blika, dycha, ...) ledstate_t _savedState; // stav pro navrat int _subState; // pomocny stav/index v poli dychani - uint32_t _lastTiming; // posledni nastaveny cas + uint32_t _pulseDuration; + uint32_t _blinkSpeed; + LEDRGB _pulseColor; #if defined(ARDUINO_ARCH_ESP32) int _rmtChannel; #endif @@ -155,7 +158,7 @@ public: static void lh(wsLED *ptr); void rtLed(void); // vykonna metoda void setColors(LEDRGB color1, LEDRGB color2 = LEDRGB(0, 0, 0)); - void blink(int speed = 300); + void blink(uint32_t speed = 300); void breath(void); void setOrder(int neworder); ledstate_t getState(void);