@@ -160,14 +160,150 @@ template<typename T_COLOR_FEATURE, typename T_METHOD> class NeoPixelBus
160160
161161 void ClearTo (typename T_COLOR_FEATURE ::ColorObject color)
162162 {
163+ uint8_t temp[T_COLOR_FEATURE ::PixelSize];
164+
165+ T_COLOR_FEATURE::applyPixelColor (temp, 0 , color);
166+
163167 uint8_t * pixels = _method.getPixels ();
164- for (uint16_t n = 0 ; n < _countPixels; n++)
168+ uint8_t * pFirst = T_COLOR_FEATURE::getPixelAddress (pixels, 0 );
169+ uint8_t * pLast = T_COLOR_FEATURE::getPixelAddress (pixels, _countPixels);
170+ uint8_t * pFront = temp;
171+ while (pFirst < pLast)
165172 {
166- T_COLOR_FEATURE::applyPixelColor (pixels, n, color );
173+ T_COLOR_FEATURE::copyIncPixel (pFirst, pFront );
167174 }
175+
168176 Dirty ();
169177 };
170178
179+ void RotateLeft (uint16_t rotationCount, uint16_t first = 0 , uint16_t last = 0xffff )
180+ {
181+ if (last >= _countPixels)
182+ {
183+ last = _countPixels - 1 ;
184+ }
185+
186+ if (first < _countPixels &&
187+ last < _countPixels &&
188+ first < last &&
189+ (last - first) >= rotationCount)
190+ {
191+
192+ // store in temp
193+ uint8_t temp[rotationCount * T_COLOR_FEATURE ::PixelSize];
194+ uint8_t * pixels = _method.getPixels ();
195+ uint8_t * pFirst = T_COLOR_FEATURE::getPixelAddress (temp, 0 );
196+ uint8_t * pLast = T_COLOR_FEATURE::getPixelAddress (temp, rotationCount - 1 );
197+ uint8_t * pFront = T_COLOR_FEATURE::getPixelAddress (pixels, first);
198+ while (pFirst <= pLast)
199+ {
200+ T_COLOR_FEATURE::moveIncPixel (pFirst, pFront);
201+ }
202+
203+ // shift data
204+ ShiftLeft (rotationCount, first, last);
205+
206+ // move temp back
207+ pFirst = T_COLOR_FEATURE::getPixelAddress (temp, 0 );
208+ pFront = T_COLOR_FEATURE::getPixelAddress (pixels, last - (rotationCount - 1 ));
209+ while (pFirst <= pLast)
210+ {
211+ T_COLOR_FEATURE::moveIncPixel (pFront, pFirst);
212+ }
213+
214+ Dirty ();
215+ }
216+ }
217+
218+ void ShiftLeft (uint16_t shiftCount, uint16_t first = 0 , uint16_t last = 0xffff )
219+ {
220+ if (last >= _countPixels)
221+ {
222+ last = _countPixels - 1 ;
223+ }
224+
225+ if (first < _countPixels &&
226+ last < _countPixels &&
227+ first < last &&
228+ (last - first) >= shiftCount)
229+ {
230+ uint8_t * pixels = _method.getPixels ();
231+ uint8_t * pFirst = T_COLOR_FEATURE::getPixelAddress (pixels, first);
232+ uint8_t * pLast = T_COLOR_FEATURE::getPixelAddress (pixels, last);
233+ uint8_t * pFront = T_COLOR_FEATURE::getPixelAddress (pixels, first + shiftCount);
234+ while (pFront <= pLast)
235+ {
236+ T_COLOR_FEATURE::moveIncPixel (pFirst, pFront);
237+ }
238+
239+ Dirty ();
240+ }
241+ }
242+
243+ void RotateRight (uint16_t rotationCount, uint16_t first = 0 , uint16_t last = 0xffff )
244+ {
245+ if (last >= _countPixels)
246+ {
247+ last = _countPixels - 1 ;
248+ }
249+
250+ if (first < _countPixels &&
251+ last < _countPixels &&
252+ first < last &&
253+ (last - first) >= rotationCount)
254+ {
255+
256+ // store in temp
257+ uint8_t temp[rotationCount * T_COLOR_FEATURE ::PixelSize];
258+ uint8_t * pixels = _method.getPixels ();
259+ uint8_t * pFirst = T_COLOR_FEATURE::getPixelAddress (temp, 0 );
260+ uint8_t * pLast = T_COLOR_FEATURE::getPixelAddress (temp, rotationCount - 1 );
261+ uint8_t * pBack = T_COLOR_FEATURE::getPixelAddress (pixels, last);
262+ while (pLast >= pFirst)
263+ {
264+ T_COLOR_FEATURE::moveDecPixel (pLast, pBack);
265+ }
266+
267+ // shift data
268+ ShiftRight (rotationCount, first, last);
269+
270+ // move temp back
271+ pLast = T_COLOR_FEATURE::getPixelAddress (temp, rotationCount - 1 );
272+ pBack = T_COLOR_FEATURE::getPixelAddress (pixels, first + rotationCount - 1 );
273+ while (pLast >= pFirst)
274+ {
275+ T_COLOR_FEATURE::moveDecPixel (pBack, pLast);
276+ }
277+
278+ Dirty ();
279+ }
280+ }
281+
282+ void ShiftRight (uint16_t shiftCount, uint16_t first = 0 , uint16_t last = 0xffff )
283+ {
284+ if (last >= _countPixels)
285+ {
286+ last = _countPixels - 1 ;
287+ }
288+
289+ if (first < _countPixels &&
290+ last < _countPixels &&
291+ first < last &&
292+ (last - first) >= shiftCount)
293+ {
294+ uint8_t * pixels = _method.getPixels ();
295+ uint8_t * pFirst = T_COLOR_FEATURE::getPixelAddress (pixels, first);
296+ uint8_t * pLast = T_COLOR_FEATURE::getPixelAddress (pixels, last);
297+ uint8_t * pBack = T_COLOR_FEATURE::getPixelAddress (pixels, last - shiftCount);
298+ while (pBack >= pFirst)
299+ {
300+ T_COLOR_FEATURE::moveDecPixel (pLast, pBack);
301+ }
302+
303+ Dirty ();
304+ }
305+ }
306+
171307private:
172308 const uint16_t _countPixels; // Number of RGB LEDs in strip
173309
0 commit comments