Snaha o vylepseni obsluhy - nutno overit!

This commit is contained in:
Pavel Brychta 2021-07-23 14:15:59 +02:00
parent b8e9092035
commit 707d6a3375
2 changed files with 17 additions and 15 deletions

View File

@ -20,6 +20,8 @@
// moved into a C file so the attribute will be applied correctly // 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); extern "C" void ICACHE_RAM_ATTR send_pixels_800(uint8_t* pixel, size_t count, uint8_t pin);
#endif #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])) #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) void wsLED::begin(int pin)
@ -146,25 +140,30 @@ void ICACHE_RAM_ATTR wsLED::rtLed(void)
case LED_BREATH: { case LED_BREATH: {
_handler.detach();
++_subState; ++_subState;
_subState %= countof(LB); _subState %= countof(LB);
uint16_t val = pgm_read_word(&LB[_subState]); uint16_t val = pgm_read_word(&LB[_subState]);
_scale = (uint8_t)val; _scale = (uint8_t)val;
show(); show();
val >>= 8; val >>= 8;
_handler.attach_ms(30ul * val, lh, this); _lastTiming = 30ul * val;
_handler.attach_ms(_lastTiming, lh, this);
break; break;
} }
case LED_PULSE: { case LED_PULSE: {
_handler.detach();
_ledState = _savedState; _ledState = _savedState;
_handler.attach_ms(300, lh, this); // vratime zpet puvodni casovani
setColor(_color1); setColor(_color1);
show();
_handler.attach_ms(_lastTiming, lh, this); // vratime zpet puvodni casovani
break; break;
} }
default: default:
_handler.attach_ms(300, lh, this); // jen pomale casovani _handler.detach();
// _handler.attach_ms(300, lh, this); // jen pomale casovani
break; break;
} }
} }
@ -195,7 +194,8 @@ void wsLED::blink(int speed)
_ledState = LED_BLINK; _ledState = LED_BLINK;
_scale = 0xff; _scale = 0xff;
_subState = 1; _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; _ledState = LED_BREATH;
_subState = 0; _subState = 0;
setColor(_color1); setColor(_color1);
_handler.attach_ms(1, lh, this); _lastTiming = 1;
_handler.attach_ms(_lastTiming, lh, this);
} }
} }
} }

View File

@ -135,6 +135,7 @@ protected:
ledstate_t _ledState; // stav LEDky (blika, dycha, ...) ledstate_t _ledState; // stav LEDky (blika, dycha, ...)
ledstate_t _savedState; // stav pro navrat ledstate_t _savedState; // stav pro navrat
int _subState; // pomocny stav/index v poli dychani int _subState; // pomocny stav/index v poli dychani
uint32_t _lastTiming; // posledni nastaveny cas
#if defined(ARDUINO_ARCH_ESP32) #if defined(ARDUINO_ARCH_ESP32)
int _rmtChannel; int _rmtChannel;
#endif #endif