diff --git a/src/NeoPixelBus.h b/src/NeoPixelBus.h index f514430..f83a43e 100644 --- a/src/NeoPixelBus.h +++ b/src/NeoPixelBus.h @@ -131,11 +131,7 @@ public: ~NeoPixelBus() { -#if defined(NEOPIXEBUS_NO_ARRAY_NEW) - free(_pixels); -#else delete[] _pixels; -#endif } @@ -356,11 +352,7 @@ protected: void _initialize() { -#if defined(NEOPIXEBUS_NO_ARRAY_NEW) - _pixels = static_cast(malloc(_countPixels * sizeof(T_EXPOSED_COLOR_OBJECT))); -#else _pixels = new T_EXPOSED_COLOR_OBJECT[_countPixels]; -#endif ClearTo(0); } @@ -416,11 +408,11 @@ protected: void _shiftRight(uint16_t shiftCount, uint16_t first, uint16_t last) { - uint16_t front = last - shiftCount; + uint16_t back = last - shiftCount; - while (first <= last) + while (first < last) { - _pixels[last--] = _pixels[front--]; + _pixels[last--] = _pixels[back--]; } } }; diff --git a/src/internal/NeoUtil.cpp b/src/internal/NeoUtil.cpp new file mode 100644 index 0000000..eeadce8 --- /dev/null +++ b/src/internal/NeoUtil.cpp @@ -0,0 +1,40 @@ +/*------------------------------------------------------------------------- +NeoPixel library helper functions + +Written by Michael C. Miller. + +I invest time and resources providing this open source code, +please support me by dontating (see https://github.com/Makuna/NeoPixelBus) + +------------------------------------------------------------------------- +This file is part of the Makuna/NeoPixelBus library. + +NeoPixelBus is free software: you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as +published by the Free Software Foundation, either version 3 of +the License, or (at your option) any later version. + +NeoPixelBus is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with NeoPixel. If not, see +. +-------------------------------------------------------------------------*/ + +#include +#include "NeoUtil.h" + +#if defined(NEOPIXEBUS_NO_ARRAY_NEW) +void* operator new[](size_t size) +{ + return malloc(size); +} + +void operator delete[](void* ptr) +{ + free(ptr); +} +#endif \ No newline at end of file diff --git a/src/internal/NeoUtil.h b/src/internal/NeoUtil.h index 9033ec9..571f2b2 100644 --- a/src/internal/NeoUtil.h +++ b/src/internal/NeoUtil.h @@ -57,6 +57,7 @@ License along with NeoPixel. If not, see #if defined(ARDUINO_AVR_DIGISPARK) || \ defined(ARDUINO_AVR_DIGISPARKPRO) #define NEOPIXEBUS_NO_ARRAY_NEW 1 + #endif // some platforms do not define this standard progmem type for some reason diff --git a/src/internal/methods/NeoAvrMethod.h b/src/internal/methods/NeoAvrMethod.h index 3f71257..adc5653 100644 --- a/src/internal/methods/NeoAvrMethod.h +++ b/src/internal/methods/NeoAvrMethod.h @@ -235,14 +235,15 @@ public: const T_COLOR_OBJECT* pixelEnd = pixel + countPixels; uint16_t stripCount = _pixelCount; - while (--stripCount) + while (stripCount--) { typename T_COLOR_FEATURE::ColorObject color = shader.Apply(*pixel); - T_COLOR_FEATURE::applyPixelColor(sendData, T_COLOR_FEATURE::PixelSize, color); + T_COLOR_FEATURE::applyPixelColor(sendData, sendDataSize, color); T_SPEED::send_data(sendData, T_COLOR_FEATURE::PixelSize, _port, _pinMask); - if (++pixel == pixelEnd) + pixel++; + if (pixel >= pixelEnd) { // restart at first pixel = pixels;