diff --git a/src/wsLED.cpp b/src/wsLED.cpp index a9c36de..9b6de9f 100644 --- a/src/wsLED.cpp +++ b/src/wsLED.cpp @@ -33,10 +33,10 @@ static const uint16_t LB[] PROGMEM = { 0x12d , 0x12a , 0x126 , 0x123 , 0x11f , 0x11c , 0x11a , 0x117 , 0x115 , 0x112 , 0x110 , 0x10e , 0x10c , 0x10b , 0x109 , 0x108 , 0x107 , 0x105 , 0x104 , 0x203 , 0x102 , 0x201 , 0x2a00 }; -inline bool wsLED::canShow(void) +static void ICACHE_RAM_ATTR ledTrampoline(wsLED *ptr) { - return (micros() - _endtime) >= 70L; + ptr->rtLed(); } void wsLED::show(void) @@ -48,8 +48,6 @@ void wsLED::show(void) uint16_t c = (uint16_t)_color[i] * (1 + (uint16_t)_scale); color[i] = (uint8_t)(c >> 8); } - while (!canShow()) - __asm__ volatile ("nop"); #if defined(ARDUINO_ARCH_ESP32) rmt_item32_t led_data_buffer[LED_BUFFER_ITEMS]; @@ -67,7 +65,6 @@ led_data_buffer[bit] = bit_is_set ? (rmt_item32_t) {{{T1H, 1, TL, 0}}} : (rmt_it send_pixels_800(color, 1, _pin); interrupts(); #endif - _endtime = micros(); } @@ -126,63 +123,48 @@ void wsLED::setColor(LEDRGB color) void ICACHE_RAM_ATTR wsLED::rtLed(void) { + _handler.detach(); switch (_ledState) { case LED_BLINK: - _handler.detach(); if (_subState) { - _subState = 0; setColor(_color2); } else { - _subState = 1; setColor(_color1); } - show(); - _handler.attach_ms(_blinkSpeed, lh, this); + _subState = !_subState; + _handler.attach_ms(_blinkSpeed, ledTrampoline, this); break; case LED_BREATH: { - _handler.detach(); ++_subState; _subState %= countof(LB); uint16_t val = pgm_read_word(&LB[_subState]); _scale = (uint8_t)val; - show(); val >>= 8; uint32_t timing = 30ul * val; - _handler.attach_ms(timing, lh, this); + _handler.attach_ms(timing, ledTrampoline, this); break; } case LED_PULSE: { - _handler.detach(); _ledState = _savedState; _subState = 0; setColor(_color1); - show(); - _handler.attach_ms(1, lh, this); // co nejrychleji do predchoziho stavu + _handler.attach_ms(5, ledTrampoline, 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); + _handler.attach_ms(_pulseDuration, ledTrampoline, this); break; default: - _handler.detach(); break; } -} - -void ICACHE_RAM_ATTR wsLED::lh(wsLED *ptr) -{ - - wsLED *pled = ptr; - pled->rtLed(); + show(); } void wsLED::setColors(LEDRGB color1, LEDRGB color2) @@ -205,7 +187,7 @@ void wsLED::blink(uint32_t speed) _scale = 0xff; _subState = 1; _blinkSpeed = speed; - _handler.attach_ms(1, lh, this); + _handler.attach_ms(5, ledTrampoline, this); } } } @@ -219,7 +201,7 @@ void wsLED::breath(void) _ledState = LED_BREATH; _subState = 0; setColor(_color1); - _handler.attach_ms(1, lh, this); + _handler.attach_ms(5, ledTrampoline, this); } } } @@ -242,7 +224,7 @@ void wsLED::pulse(LEDRGB color, uint32_t duration) } _pulseDuration = duration; _ledState = LED_PULSE_START; - _handler.attach_ms(5, lh, this); + _handler.attach_ms(5, ledTrampoline, this); } } diff --git a/src/wsLED.h b/src/wsLED.h index 258b336..9070d3d 100644 --- a/src/wsLED.h +++ b/src/wsLED.h @@ -129,7 +129,6 @@ protected: LEDRGB _color1; LEDRGB _color2; int _order; // ColorOrder - uint32_t _endtime; uint8_t _scale; uint8_t _color[3]; Ticker _handler; @@ -143,7 +142,6 @@ protected: int _rmtChannel; #endif - bool canShow(void); void show(void); void setColor(LEDRGB color); #if defined(ARDUINO_ARCH_ESP32) @@ -155,7 +153,6 @@ public: wsLED(void); void begin(void); void begin(int pin); - static void lh(wsLED *ptr); void rtLed(void); // vykonna metoda void setColors(LEDRGB color1, LEDRGB color2 = LEDRGB(0, 0, 0)); void blink(uint32_t speed = 300);