From 707d6a337556d183b4d65eae24efcc325ca8ba3c Mon Sep 17 00:00:00 2001 From: Pavel Brychta Date: Fri, 23 Jul 2021 14:15:59 +0200 Subject: [PATCH] Snaha o vylepseni obsluhy - nutno overit! --- src/wsLED.cpp | 31 ++++++++++++++++--------------- src/wsLED.h | 1 + 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/src/wsLED.cpp b/src/wsLED.cpp index 63ef91a..315c158 100644 --- a/src/wsLED.cpp +++ b/src/wsLED.cpp @@ -20,6 +20,8 @@ // moved into a C file so the attribute will be applied correctly extern "C" void ICACHE_RAM_ATTR send_pixels_800(uint8_t* pixel, size_t count, uint8_t pin); #endif +// TODO: Proverit ESP32 s https://github.com/adafruit/Adafruit_NeoPixel/blob/master/esp.c +// ... a s https://github.com/Freenove/Freenove_WS2812_Lib_for_ESP32 #define countof(a) (sizeof(a) / sizeof(a[0])) @@ -69,20 +71,12 @@ led_data_buffer[bit] = bit_is_set ? (rmt_item32_t) {{{T1H, 1, TL, 0}}} : (rmt_it } -wsLED::wsLED(int pin, int order) +wsLED::wsLED(int pin, int order) : _pin(pin), _order(order), _ledState(LED_STOP) { - - _pin = pin; - _order = order; - _ledState = LED_STOP; } -wsLED::wsLED(void) +wsLED::wsLED(void) : _pin(NOT_A_PIN), _order(RGB), _ledState(LED_STOP) { - - _pin = NOT_A_PIN; - _order = RGB; - _ledState = LED_STOP; } void wsLED::begin(int pin) @@ -146,25 +140,30 @@ void ICACHE_RAM_ATTR wsLED::rtLed(void) case LED_BREATH: { + _handler.detach(); ++_subState; _subState %= countof(LB); uint16_t val = pgm_read_word(&LB[_subState]); _scale = (uint8_t)val; show(); val >>= 8; - _handler.attach_ms(30ul * val, lh, this); + _lastTiming = 30ul * val; + _handler.attach_ms(_lastTiming, lh, this); break; } case LED_PULSE: { + _handler.detach(); _ledState = _savedState; - _handler.attach_ms(300, lh, this); // vratime zpet puvodni casovani setColor(_color1); + show(); + _handler.attach_ms(_lastTiming, lh, this); // vratime zpet puvodni casovani break; } default: - _handler.attach_ms(300, lh, this); // jen pomale casovani + _handler.detach(); +// _handler.attach_ms(300, lh, this); // jen pomale casovani break; } } @@ -195,7 +194,8 @@ void wsLED::blink(int speed) _ledState = LED_BLINK; _scale = 0xff; _subState = 1; - _handler.attach_ms(300, lh, this); + _lastTiming = 300; + _handler.attach_ms(_lastTiming, lh, this); } } } @@ -209,7 +209,8 @@ void wsLED::breath(void) _ledState = LED_BREATH; _subState = 0; setColor(_color1); - _handler.attach_ms(1, lh, this); + _lastTiming = 1; + _handler.attach_ms(_lastTiming, lh, this); } } } diff --git a/src/wsLED.h b/src/wsLED.h index 0d6c7a1..665a926 100644 --- a/src/wsLED.h +++ b/src/wsLED.h @@ -135,6 +135,7 @@ 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 #if defined(ARDUINO_ARCH_ESP32) int _rmtChannel; #endif