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:
- 36:0fe7917a832a
- Parent:
- 35:dffa06d09fdc
- Child:
- 44:d89e5c59aeb0
--- a/WS281X.cpp Fri Nov 04 14:40:41 2016 +0000
+++ b/WS281X.cpp Fri Nov 04 17:40:25 2016 +0000
@@ -453,10 +453,16 @@
// 指定色を指定位置のピクセルから指定サイズ分書き込む
void WS281X::fillPixels(int index, const RGBColor color, int len)
{
- if (_pixels && len > 0 && (uint16_t)index < _numPixels)
+ int numPixels = static_cast<int>(_numPixels);
+ if (_pixels && len > 0 && index < numPixels && (index + len) >= 0)
{
- if (index + len > _numPixels)
- len = _numPixels - index;
+ if (index < 0)
+ {
+ len += index;
+ index = 0;
+ }
+ if (index + len > numPixels)
+ len = numPixels - index;
_pixels[index] = color;
repeat_buffer<RGBColor>(_pixels + index, len, 1);
}