Skip to content

Commit fb91d9b

Browse files
committed
Color order override macros
1 parent ac010cd commit fb91d9b

File tree

10 files changed

+121
-53
lines changed

10 files changed

+121
-53
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
### WLED version 0.11.0
44

5+
#### Build 2011270
6+
7+
- Added tooltips for speed and intensity sliders (PR #1378)
8+
- Moved color order to NpbWrapper.h
9+
- Added compile time define to override the color order for a specific range
10+
511
#### Build 2011260
612

713
- Add `live` property to state, allowing toggling of realtime (not incl. in state resp.)

wled00/FX.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,7 @@ class WS2812FX {
469469
setPixelColor(uint16_t n, uint8_t r, uint8_t g, uint8_t b, uint8_t w = 0),
470470
show(void),
471471
setRgbwPwm(void),
472+
setColorOrder(uint8_t co),
472473
setPixelSegment(uint8_t n);
473474

474475
bool
@@ -484,7 +485,6 @@ class WS2812FX {
484485
rgbwMode = RGBW_MODE_DUAL,
485486
paletteFade = 0,
486487
paletteBlend = 0,
487-
colorOrder = 0,
488488
milliampsPerLed = 55,
489489
getBrightness(void),
490490
getMode(void),
@@ -494,6 +494,7 @@ class WS2812FX {
494494
getMaxSegments(void),
495495
//getFirstSelectedSegment(void),
496496
getMainSegmentId(void),
497+
getColorOrder(void),
497498
gamma8(uint8_t),
498499
gamma8_cal(uint8_t, float),
499500
get_random_wheel_index(uint8_t);

wled00/FX_fcn.cpp

Lines changed: 27 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -150,18 +150,8 @@ void WS2812FX::setPixelColor(uint16_t i, byte r, byte g, byte b, byte w)
150150
}
151151
}
152152

153-
//reorder channels to selected order
154153
RgbwColor col;
155-
switch (colorOrder)
156-
{
157-
case 0: col.G = g; col.R = r; col.B = b; break; //0 = GRB, default
158-
case 1: col.G = r; col.R = g; col.B = b; break; //1 = RGB, common for WS2811
159-
case 2: col.G = b; col.R = r; col.B = g; break; //2 = BRG
160-
case 3: col.G = r; col.R = b; col.B = g; break; //3 = RBG
161-
case 4: col.G = b; col.R = g; col.B = r; break; //4 = BGR
162-
default: col.G = g; col.R = b; col.B = r; break; //5 = GBR
163-
}
164-
col.W = w;
154+
col.R = r; col.G = g; col.B = b; col.W = w;
165155

166156
uint16_t skip = _skipFirstMode ? LED_SKIP_AMOUNT : 0;
167157
if (SEGLEN) {//from segment
@@ -258,7 +248,7 @@ void WS2812FX::show(void) {
258248

259249
for (uint16_t i = 0; i < _length; i++) //sum up the usage of each LED
260250
{
261-
RgbwColor c = bus->GetPixelColorRgbw(i);
251+
RgbwColor c = bus->GetPixelColorRaw(i);
262252

263253
if(useWackyWS2815PowerModel)
264254
{
@@ -467,18 +457,7 @@ uint32_t WS2812FX::getPixelColor(uint16_t i)
467457

468458
if (i >= _lengthRaw) return 0;
469459

470-
RgbwColor col = bus->GetPixelColorRgbw(i);
471-
switch (colorOrder)
472-
{
473-
// W G R B
474-
case 0: return ((col.W << 24) | (col.G << 8) | (col.R << 16) | (col.B)); //0 = GRB, default
475-
case 1: return ((col.W << 24) | (col.R << 8) | (col.G << 16) | (col.B)); //1 = RGB, common for WS2811
476-
case 2: return ((col.W << 24) | (col.B << 8) | (col.R << 16) | (col.G)); //2 = BRG
477-
case 3: return ((col.W << 24) | (col.B << 8) | (col.G << 16) | (col.R)); //3 = RBG
478-
case 4: return ((col.W << 24) | (col.R << 8) | (col.B << 16) | (col.G)); //4 = BGR
479-
case 5: return ((col.W << 24) | (col.G << 8) | (col.B << 16) | (col.R)); //5 = GBR
480-
}
481-
return 0;
460+
return bus->GetPixelColorRgbw(i);
482461
}
483462

484463
WS2812FX::Segment& WS2812FX::getSegment(uint8_t id) {
@@ -498,6 +477,14 @@ uint32_t WS2812FX::getLastShow(void) {
498477
return _lastShow;
499478
}
500479

480+
uint8_t WS2812FX::getColorOrder(void) {
481+
return bus->GetColorOrder();
482+
}
483+
484+
void WS2812FX::setColorOrder(uint8_t co) {
485+
bus->SetColorOrder(co);
486+
}
487+
501488
void WS2812FX::setSegment(uint8_t n, uint16_t i1, uint16_t i2, uint8_t grouping, uint8_t spacing) {
502489
if (n >= MAX_NUM_SEGMENTS) return;
503490
Segment& seg = _segments[n];
@@ -936,27 +923,30 @@ void WS2812FX::setRgbwPwm(void) {
936923

937924
_analogLastShow = nowUp;
938925

939-
RgbwColor color = bus->GetPixelColorRgbw(0);
926+
RgbwColor c;
927+
uint32_t col = bus->GetPixelColorRgbw(0);
928+
c.R = col >> 16; c.G = col >> 8; c.B = col; c.W = col >> 24;
929+
940930
byte b = getBrightness();
941931
if (color == _analogLastColor && b == _analogLastBri) return;
942932

943933
// check color values for Warm / Cold white mix (for RGBW) // EsplanexaDevice.cpp
944934
#ifdef WLED_USE_5CH_LEDS
945-
if (color.R == 255 && color.G == 255 && color.B == 255 && color.W == 255) {
946-
bus->SetRgbwPwm(0, 0, 0, 0, color.W * b / 255);
947-
} else if (color.R == 127 && color.G == 127 && color.B == 127 && color.W == 255) {
948-
bus->SetRgbwPwm(0, 0, 0, color.W * b / 512, color.W * b / 255);
949-
} else if (color.R == 0 && color.G == 0 && color.B == 0 && color.W == 255) {
950-
bus->SetRgbwPwm(0, 0, 0, color.W * b / 255, 0);
951-
} else if (color.R == 130 && color.G == 90 && color.B == 0 && color.W == 255) {
952-
bus->SetRgbwPwm(0, 0, 0, color.W * b / 255, color.W * b / 512);
953-
} else if (color.R == 255 && color.G == 153 && color.B == 0 && color.W == 255) {
954-
bus->SetRgbwPwm(0, 0, 0, color.W * b / 255, 0);
935+
if (c.R == 255 && c.G == 255 && c.B == 255 && c.W == 255) {
936+
bus->SetRgbwPwm(0, 0, 0, 0, c.W * b / 255);
937+
} else if (c.R == 127 && c.G == 127 && c.B == 127 && c.W == 255) {
938+
bus->SetRgbwPwm(0, 0, 0, c.W * b / 512, c.W * b / 255);
939+
} else if (c.R == 0 && c.G == 0 && c.B == 0 && c.W == 255) {
940+
bus->SetRgbwPwm(0, 0, 0, c.W * b / 255, 0);
941+
} else if (c.R == 130 && c.G == 90 && c.B == 0 && c.W == 255) {
942+
bus->SetRgbwPwm(0, 0, 0, c.W * b / 255, c.W * b / 512);
943+
} else if (c.R == 255 && c.G == 153 && c.B == 0 && c.W == 255) {
944+
bus->SetRgbwPwm(0, 0, 0, c.W * b / 255, 0);
955945
} else { // not only white colors
956-
bus->SetRgbwPwm(color.R * b / 255, color.G * b / 255, color.B * b / 255, color.W * b / 255);
946+
bus->SetRgbwPwm(c.R * b / 255, c.G * b / 255, c.B * b / 255, c.W * b / 255);
957947
}
958948
#else
959-
bus->SetRgbwPwm(color.R * b / 255, color.G * b / 255, color.B * b / 255, color.W * b / 255);
949+
bus->SetRgbwPwm(c.R * b / 255, c.G * b / 255, c.B * b / 255, c.W * b / 255);
960950
#endif
961951
_analogLastColor = color;
962952
_analogLastBri = b;

wled00/NpbWrapper.h

Lines changed: 71 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,13 @@
4141
#define RLYMDE 1 //mode for relay, 0: LOW if LEDs are on 1: HIGH if LEDs are on
4242
#endif
4343

44+
//enable color order override for a specific range of the strip
45+
//This can be useful if you want to chain multiple strings with incompatible color order
46+
//#define COLOR_ORDER_OVERRIDE
47+
#define COO_MIN 0
48+
#define COO_MAX 27 //not inclusive, this would set the override for LEDs 0-26
49+
#define COO_ORDER COL_ORDER_GRB
50+
4451
//END CONFIGURATION
4552

4653
#if defined(USE_APA102) || defined(USE_WS2801) || defined(USE_LPD8806) || defined(USE_P9813)
@@ -168,6 +175,7 @@
168175

169176

170177
#include <NeoPixelBrightnessBus.h>
178+
#include "const.h"
171179

172180
enum NeoPixelType
173181
{
@@ -296,23 +304,41 @@ class NeoPixelWrapper
296304
}
297305
}
298306

299-
void SetPixelColor(uint16_t indexPixel, RgbwColor color)
307+
void SetPixelColor(uint16_t indexPixel, RgbwColor c)
300308
{
309+
RgbwColor col;
310+
311+
uint8_t co = _colorOrder;
312+
#ifdef COLOR_ORDER_OVERRIDE
313+
if (indexPixel >= COO_MIN && indexPixel < COO_MAX) co = COO_ORDER;
314+
#endif
315+
316+
//reorder channels to selected order
317+
switch (co)
318+
{
319+
case 0: col.G = c.G; col.R = c.R; col.B = c.B; break; //0 = GRB, default
320+
case 1: col.G = c.R; col.R = c.G; col.B = c.B; break; //1 = RGB, common for WS2811
321+
case 2: col.G = c.B; col.R = c.R; col.B = c.G; break; //2 = BRG
322+
case 3: col.G = c.R; col.R = c.B; col.B = c.G; break; //3 = RBG
323+
case 4: col.G = c.B; col.R = c.G; col.B = c.R; break; //4 = BGR
324+
default: col.G = c.G; col.R = c.B; col.B = c.R; break; //5 = GBR
325+
}
326+
col.W = c.W;
327+
301328
switch (_type) {
302329
case NeoPixelType_Grb: {
303-
_pGrb->SetPixelColor(indexPixel, RgbColor(color.R,color.G,color.B));
330+
_pGrb->SetPixelColor(indexPixel, RgbColor(col.R,col.G,col.B));
304331
}
305332
break;
306333
case NeoPixelType_Grbw: {
307334
#if defined(USE_LPD8806) || defined(USE_WS2801)
308-
_pGrbw->SetPixelColor(indexPixel, RgbColor(color.R,color.G,color.B));
335+
_pGrbw->SetPixelColor(indexPixel, RgbColor(col.R,col.G,col.B));
309336
#else
310-
_pGrbw->SetPixelColor(indexPixel, color);
337+
_pGrbw->SetPixelColor(indexPixel, col);
311338
#endif
312339
}
313340
break;
314-
}
315-
341+
}
316342
}
317343

318344
void SetBrightness(byte b)
@@ -323,9 +349,15 @@ class NeoPixelWrapper
323349
}
324350
}
325351

326-
// NOTE: Due to feature differences, some support RGBW but the method name
327-
// here needs to be unique, thus GetPixeColorRgbw
328-
RgbwColor GetPixelColorRgbw(uint16_t indexPixel) const
352+
void SetColorOrder(byte colorOrder) {
353+
_colorOrder = colorOrder;
354+
}
355+
356+
uint8_t GetColorOrder() {
357+
return _colorOrder;
358+
}
359+
360+
RgbwColor GetPixelColorRaw(uint16_t indexPixel) const
329361
{
330362
switch (_type) {
331363
case NeoPixelType_Grb: return _pGrb->GetPixelColor(indexPixel); break;
@@ -334,6 +366,34 @@ class NeoPixelWrapper
334366
return 0;
335367
}
336368

369+
// NOTE: Due to feature differences, some support RGBW but the method name
370+
// here needs to be unique, thus GetPixeColorRgbw
371+
uint32_t GetPixelColorRgbw(uint16_t indexPixel) const
372+
{
373+
RgbwColor col(0,0,0,0);
374+
switch (_type) {
375+
case NeoPixelType_Grb: col = _pGrb->GetPixelColor(indexPixel); break;
376+
case NeoPixelType_Grbw: col = _pGrbw->GetPixelColor(indexPixel); break;
377+
}
378+
379+
uint8_t co = _colorOrder;
380+
#ifdef COLOR_ORDER_OVERRIDE
381+
if (indexPixel >= COO_MIN && indexPixel < COO_MAX) co = COO_ORDER;
382+
#endif
383+
384+
switch (co)
385+
{
386+
// W G R B
387+
case 0: return ((col.W << 24) | (col.G << 8) | (col.R << 16) | (col.B)); //0 = GRB, default
388+
case 1: return ((col.W << 24) | (col.R << 8) | (col.G << 16) | (col.B)); //1 = RGB, common for WS2811
389+
case 2: return ((col.W << 24) | (col.B << 8) | (col.R << 16) | (col.G)); //2 = BRG
390+
case 3: return ((col.W << 24) | (col.B << 8) | (col.G << 16) | (col.R)); //3 = RBG
391+
case 4: return ((col.W << 24) | (col.R << 8) | (col.B << 16) | (col.G)); //4 = BGR
392+
case 5: return ((col.W << 24) | (col.G << 8) | (col.B << 16) | (col.R)); //5 = GBR
393+
}
394+
return 0;
395+
}
396+
337397
uint8_t* GetPixels(void)
338398
{
339399
switch (_type) {
@@ -351,6 +411,8 @@ class NeoPixelWrapper
351411
NeoPixelBrightnessBus<PIXELFEATURE3,PIXELMETHOD>* _pGrb;
352412
NeoPixelBrightnessBus<PIXELFEATURE4,PIXELMETHOD>* _pGrbw;
353413

414+
byte _colorOrder = 0;
415+
354416
void cleanup()
355417
{
356418
switch (_type) {

wled00/cfg.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ void deserializeConfig() {
9999

100100
//int hw_led_ins_0_pin_0 = hw_led_ins_0[F("pin")][0]; // 2
101101

102-
strip.colorOrder = hw_led_ins_0[F("order")];
102+
strip.setColorOrder(hw_led_ins_0[F("order")]);
103103
//bool hw_led_ins_0_rev = hw_led_ins_0[F("rev")]; // false
104104
skipFirstLed = hw_led_ins_0[F("skip")]; // 0
105105
useRGBW = (hw_led_ins_0[F("type")] == TYPE_SK6812_RGBW);
@@ -390,7 +390,7 @@ void serializeConfig() {
390390
#ifdef DATAPIN
391391
hw_led_ins_0_pin.add(DATAPIN);
392392
#endif
393-
hw_led_ins_0[F("order")] = strip.colorOrder; //color order
393+
hw_led_ins_0[F("order")] = strip.getColorOrder();
394394
hw_led_ins_0[F("rev")] = false;
395395
hw_led_ins_0[F("skip")] = skipFirstLed ? 1 : 0;
396396

wled00/const.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,15 @@
104104
#define TYPE_TM1814 54
105105

106106

107+
//Color orders
108+
#define COL_ORDER_GRB 0 //GRB(w),defaut
109+
#define COL_ORDER_RGB 1 //common for WS2811
110+
#define COL_ORDER_BRG 2
111+
#define COL_ORDER_RBG 3
112+
#define COL_ORDER_BGR 4
113+
#define COL_ORDER_GBR 5
114+
115+
107116
//Button type
108117
#define BTN_TYPE_NONE 0
109118
#define BTN_TYPE_RESERVED 1

wled00/set.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ void handleSettingsSet(AsyncWebServerRequest *request, byte subPage)
8282
strip.milliampsPerLed = request->arg(F("LA")).toInt();
8383

8484
useRGBW = request->hasArg(F("EW"));
85-
strip.colorOrder = request->arg(F("CO")).toInt();
85+
strip.setColorOrder(request->arg(F("CO")).toInt());
8686
strip.rgbwMode = request->arg(F("AW")).toInt();
8787

8888
briS = request->arg(F("CA")).toInt();

wled00/wled.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*/
99

1010
// version code in format yymmddb (b = daily build)
11-
#define VERSION 2011230
11+
#define VERSION 2011270
1212

1313
//uncomment this if you have a "my_config.h" file you'd like to use
1414
//#define WLED_USE_MY_CONFIG

wled00/wled_eeprom.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ void loadSettingsFromEEPROM()
224224

225225
if (lastEEPROMversion > 9)
226226
{
227-
strip.colorOrder = EEPROM.read(383);
227+
strip.setColorOrder(EEPROM.read(383));
228228
irEnabled = EEPROM.read(385);
229229
strip.ablMilliampsMax = EEPROM.read(387) + ((EEPROM.read(388) << 8) & 0xFF00);
230230
} else if (lastEEPROMversion > 1) //ABL is off by default when updating from version older than 0.8.2

wled00/xml.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ void getSettingsJS(byte subPage, char* dest)
268268

269269
sappend('v',SET_F("CA"),briS);
270270
sappend('c',SET_F("EW"),useRGBW);
271-
sappend('i',SET_F("CO"),strip.colorOrder);
271+
sappend('i',SET_F("CO"),strip.getColorOrder());
272272
sappend('v',SET_F("AW"),strip.rgbwMode);
273273

274274
sappend('c',SET_F("BO"),turnOnAtBoot);

0 commit comments

Comments
 (0)