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:
- 35:dffa06d09fdc
- Parent:
- 34:5a141ed5d52a
- Child:
- 36:0fe7917a832a
--- a/WS281X.cpp Fri Nov 04 13:19:38 2016 +0000
+++ b/WS281X.cpp Fri Nov 04 14:40:41 2016 +0000
@@ -31,10 +31,12 @@
// TARGET_STM32F7
// TARGET_DISCO_F746NG
// TARGET_NUCLEO_F746ZG
+// TARGET_NUCLEO_F446RE
// TARGET_STM32F0
// TARGET_NUCLEO_F030R8
// TARGET_NUCLEO_F070RB
// TARGET_NUCLEO_F072RB
+// TARGET_NUCLEO_F091RC
// TARGET_LPC82X
// TARGET_LPC824
@@ -412,36 +414,34 @@
// 指定位置のピクセルへ色配列を指定サイズ分をコピーする
void WS281X::setPixels(int index, 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 = len - (-index);
- color += (-index);
- index = 0;
+ len += index;
+ color -= index;
+ index = 0;
}
-
+ if (index + len > numPixels)
+ len = numPixels - index;
memcpy(&_pixels[index], color, len * sizeof(_pixels[0]));
}
}
void WS281X::setPixels(int index, HSVColor *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 = len - (-index);
- color += (-index);
- index = 0;
+ len += index;
+ color -= index;
+ index = 0;
}
-
+ if (index + len > numPixels)
+ len = numPixels - index;
RGBColor *dest = &_pixels[index];
do
{