From cf00e8a41b75e7ffb778cd0c48802a1f65281da3 Mon Sep 17 00:00:00 2001 From: Andrew Melvin Date: Thu, 27 Aug 2015 07:30:16 +0100 Subject: [PATCH] not working --- NeoPixelBus.cpp | 35 ++++++++++++++++++---------- NeoPixelBus.h | 2 +- NeoPixelesp8266uart.cpp | 20 ++++++++++++---- examples/NeoPixelFun/NeoPixelFun.pde | 17 ++++++++++++-- 4 files changed, 55 insertions(+), 19 deletions(-) diff --git a/NeoPixelBus.cpp b/NeoPixelBus.cpp index 4d08f24..aae3e05 100644 --- a/NeoPixelBus.cpp +++ b/NeoPixelBus.cpp @@ -42,7 +42,7 @@ License along with NeoPixel. If not, see #define UART_INV_MASK (0x3f<<19) #define UART 1 - extern void ICACHE_RAM_ATTR send_pixels_UART(uint8_t* pixels, uint8_t* end); + extern void ICACHE_RAM_ATTR send_pixels_UART(uint8_t* pixels, uint8_t* end, bool force); #else // due to linker overriding the ICACHE_RAM_ATTR for cpp files, these methods are @@ -98,6 +98,17 @@ NeoPixelBus::~NeoPixelBus() } + +void NeoPixelBus::FillUart(void) { + + uint8_t* p = _pixels; + uint8_t* end = p + _sizePixels; + + send_pixels_UART(p, end, false); + +} + + void NeoPixelBus::Begin(void) { @@ -785,21 +796,21 @@ void NeoPixelBus::Show(void) send_pixels_800(p, end, _pin); #else - send_pixels_UART(p, end); + send_pixels_UART(p, end,true); - char buff[4]; + // char buff[4]; - do - { - uint8_t subpix = *p++; + // do + // { + // uint8_t subpix = *p++; - buff[0] = data[(subpix >> 6) & 3]; - buff[1] = data[(subpix >> 4) & 3]; - buff[2] = data[(subpix >> 2) & 3]; - buff[3] = data[subpix & 3]; - Serial1.write(buff, sizeof(buff)); + // buff[0] = data[(subpix >> 6) & 3]; + // buff[1] = data[(subpix >> 4) & 3]; + // buff[2] = data[(subpix >> 2) & 3]; + // buff[3] = data[subpix & 3]; + // Serial1.write(buff, sizeof(buff)); - } while (p < end); + // } while (p < end); #endif diff --git a/NeoPixelBus.h b/NeoPixelBus.h index 0d9bc93..f0b2f79 100644 --- a/NeoPixelBus.h +++ b/NeoPixelBus.h @@ -61,7 +61,7 @@ public: { ClearTo(c.R, c.G, c.B); } - + void FillUart(); bool IsDirty() { return (_flagsPixels & NEO_DIRTY); diff --git a/NeoPixelesp8266uart.cpp b/NeoPixelesp8266uart.cpp index 3be509b..57b9c37 100644 --- a/NeoPixelesp8266uart.cpp +++ b/NeoPixelesp8266uart.cpp @@ -33,21 +33,33 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA const char data[4] = { 0b00110111, 0b00000111, 0b00110100, 0b00000100 }; -void ICACHE_RAM_ATTR send_pixels_UART(uint8_t* pixels, uint8_t* end) +void ICACHE_RAM_ATTR send_pixels_UART(uint8_t* pixels, uint8_t* end, bool force) { char buff[4]; - + uint8_t count = 0; + static uint8_t* position = NULL; + + + if (position != NULL && !force ) { + pixels = position; + } else if (position == NULL && !force ) { + return; + } + do { uint8_t subpix = *pixels++; - + position = pixels; + count++; buff[0] = data[(subpix >> 6) & 3]; buff[1] = data[(subpix >> 4) & 3]; buff[2] = data[(subpix >> 2) & 3]; buff[3] = data[subpix & 3]; Serial1.write(buff, sizeof(buff)); - } while (pixels < end); + } while (pixels < end || count < 156 ); + + if ( pixels == end) { position = NULL; } } diff --git a/examples/NeoPixelFun/NeoPixelFun.pde b/examples/NeoPixelFun/NeoPixelFun.pde index b97ec40..89a2afe 100644 --- a/examples/NeoPixelFun/NeoPixelFun.pde +++ b/examples/NeoPixelFun/NeoPixelFun.pde @@ -1,8 +1,8 @@ #include -#define pixelCount 4 +#define pixelCount 300 -NeoPixelBus strip = NeoPixelBus(pixelCount, 8); +NeoPixelBus strip = NeoPixelBus(pixelCount, 2); uint16_t effectState = 0; @@ -13,6 +13,7 @@ void setup() SetRandomSeed(); } +uint32_t update_strip_time; void loop() { @@ -33,6 +34,18 @@ void loop() strip.Show(); delay(31); // ~30hz change cycle } + + if ( (millis() - update_strip_time > 30) ) { + + strip.UpdateAnimations(); + + strip.Show(); // takes 6ms with 200, take 12ms with 400 ----> so 100 takes 3ms. + // one LED takes 30uS of nointeruppts, 100 takes 3ms. + update_strip_time = millis(); + + } + + strip.FillUart(); }