Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: WS281X.cpp
- Revision:
- 24:f93a61e727a3
- Parent:
- 23:d4061c4b6238
- Child:
- 27:bc79f444883b
--- a/WS281X.cpp Fri Aug 26 22:18:43 2016 +0000
+++ b/WS281X.cpp Sat Aug 27 19:53:37 2016 +0000
@@ -380,11 +380,10 @@
{
if (index + len > _numPixels)
len = _numPixels - index;
+ RGBColor *dest = &_pixels[index];
do
{
- _pixels[index] = *color;
- ++index;
- ++color;
+ *dest++ = *color++;
} while (--len);
}
}
@@ -392,15 +391,16 @@
// 指定位置のピクセルから指定色を指定サイズ分書き込む
void WS281X::fillColor(int index, const RGBColor color, int len)
{
- if (!_pixels || len < 1 || (uint16_t)index >= _numPixels)
- return;
- if (index + len > _numPixels)
- len = _numPixels - index;
- do
+ if (_pixels && len > 0 && (uint16_t)index < _numPixels)
{
- _pixels[index] = color;
- ++index;
- } while (--len);
+ if (index + len > _numPixels)
+ len = _numPixels - index;
+ RGBColor *dest = &_pixels[index];
+ do
+ {
+ *dest++ = color;
+ } while (--len);
+ }
}
// 先頭から指定サイズ分のブロックをバッファの最後までコピーする
@@ -421,6 +421,29 @@
}
}
+void WS281X::repeatBlock(RGBColor *source, int size)
+{
+ if (_pixels && source && size > 0)
+ {
+ if (size > _numPixels)
+ size = _numPixels;
+ memcpy(_pixels, source, size * sizeof(_pixels[0]));
+ repeatBlock(size);
+ }
+}
+
+void WS281X::repeatBlock(HSVColor *source, int size)
+{
+ if (_pixels && source && size > 0)
+ {
+ if (size > _numPixels)
+ size = _numPixels;
+ for (int i = 0; i < size; ++i)
+ _pixels[i] = *source++;
+ repeatBlock(size);
+ }
+}
+
// 指定色でバッファを埋める
void WS281X::clear(const RGBColor color)
{