Color order override macros

This commit is contained in:
cschwinne 2020-11-27 23:59:00 +01:00
parent ac010cd7b2
commit fb91d9b2d4
10 changed files with 121 additions and 53 deletions

View File

@ -2,6 +2,12 @@
### WLED version 0.11.0 ### WLED version 0.11.0
#### Build 2011270
- Added tooltips for speed and intensity sliders (PR #1378)
- Moved color order to NpbWrapper.h
- Added compile time define to override the color order for a specific range
#### Build 2011260 #### Build 2011260
- Add `live` property to state, allowing toggling of realtime (not incl. in state resp.) - Add `live` property to state, allowing toggling of realtime (not incl. in state resp.)

View File

@ -469,6 +469,7 @@ class WS2812FX {
setPixelColor(uint16_t n, uint8_t r, uint8_t g, uint8_t b, uint8_t w = 0), setPixelColor(uint16_t n, uint8_t r, uint8_t g, uint8_t b, uint8_t w = 0),
show(void), show(void),
setRgbwPwm(void), setRgbwPwm(void),
setColorOrder(uint8_t co),
setPixelSegment(uint8_t n); setPixelSegment(uint8_t n);
bool bool
@ -484,7 +485,6 @@ class WS2812FX {
rgbwMode = RGBW_MODE_DUAL, rgbwMode = RGBW_MODE_DUAL,
paletteFade = 0, paletteFade = 0,
paletteBlend = 0, paletteBlend = 0,
colorOrder = 0,
milliampsPerLed = 55, milliampsPerLed = 55,
getBrightness(void), getBrightness(void),
getMode(void), getMode(void),
@ -494,6 +494,7 @@ class WS2812FX {
getMaxSegments(void), getMaxSegments(void),
//getFirstSelectedSegment(void), //getFirstSelectedSegment(void),
getMainSegmentId(void), getMainSegmentId(void),
getColorOrder(void),
gamma8(uint8_t), gamma8(uint8_t),
gamma8_cal(uint8_t, float), gamma8_cal(uint8_t, float),
get_random_wheel_index(uint8_t); get_random_wheel_index(uint8_t);

View File

@ -150,18 +150,8 @@ void WS2812FX::setPixelColor(uint16_t i, byte r, byte g, byte b, byte w)
} }
} }
//reorder channels to selected order
RgbwColor col; RgbwColor col;
switch (colorOrder) col.R = r; col.G = g; col.B = b; col.W = w;
{
case 0: col.G = g; col.R = r; col.B = b; break; //0 = GRB, default
case 1: col.G = r; col.R = g; col.B = b; break; //1 = RGB, common for WS2811
case 2: col.G = b; col.R = r; col.B = g; break; //2 = BRG
case 3: col.G = r; col.R = b; col.B = g; break; //3 = RBG
case 4: col.G = b; col.R = g; col.B = r; break; //4 = BGR
default: col.G = g; col.R = b; col.B = r; break; //5 = GBR
}
col.W = w;
uint16_t skip = _skipFirstMode ? LED_SKIP_AMOUNT : 0; uint16_t skip = _skipFirstMode ? LED_SKIP_AMOUNT : 0;
if (SEGLEN) {//from segment if (SEGLEN) {//from segment
@ -258,7 +248,7 @@ void WS2812FX::show(void) {
for (uint16_t i = 0; i < _length; i++) //sum up the usage of each LED for (uint16_t i = 0; i < _length; i++) //sum up the usage of each LED
{ {
RgbwColor c = bus->GetPixelColorRgbw(i); RgbwColor c = bus->GetPixelColorRaw(i);
if(useWackyWS2815PowerModel) if(useWackyWS2815PowerModel)
{ {
@ -467,18 +457,7 @@ uint32_t WS2812FX::getPixelColor(uint16_t i)
if (i >= _lengthRaw) return 0; if (i >= _lengthRaw) return 0;
RgbwColor col = bus->GetPixelColorRgbw(i); return bus->GetPixelColorRgbw(i);
switch (colorOrder)
{
// W G R B
case 0: return ((col.W << 24) | (col.G << 8) | (col.R << 16) | (col.B)); //0 = GRB, default
case 1: return ((col.W << 24) | (col.R << 8) | (col.G << 16) | (col.B)); //1 = RGB, common for WS2811
case 2: return ((col.W << 24) | (col.B << 8) | (col.R << 16) | (col.G)); //2 = BRG
case 3: return ((col.W << 24) | (col.B << 8) | (col.G << 16) | (col.R)); //3 = RBG
case 4: return ((col.W << 24) | (col.R << 8) | (col.B << 16) | (col.G)); //4 = BGR
case 5: return ((col.W << 24) | (col.G << 8) | (col.B << 16) | (col.R)); //5 = GBR
}
return 0;
} }
WS2812FX::Segment& WS2812FX::getSegment(uint8_t id) { WS2812FX::Segment& WS2812FX::getSegment(uint8_t id) {
@ -498,6 +477,14 @@ uint32_t WS2812FX::getLastShow(void) {
return _lastShow; return _lastShow;
} }
uint8_t WS2812FX::getColorOrder(void) {
return bus->GetColorOrder();
}
void WS2812FX::setColorOrder(uint8_t co) {
bus->SetColorOrder(co);
}
void WS2812FX::setSegment(uint8_t n, uint16_t i1, uint16_t i2, uint8_t grouping, uint8_t spacing) { void WS2812FX::setSegment(uint8_t n, uint16_t i1, uint16_t i2, uint8_t grouping, uint8_t spacing) {
if (n >= MAX_NUM_SEGMENTS) return; if (n >= MAX_NUM_SEGMENTS) return;
Segment& seg = _segments[n]; Segment& seg = _segments[n];
@ -936,27 +923,30 @@ void WS2812FX::setRgbwPwm(void) {
_analogLastShow = nowUp; _analogLastShow = nowUp;
RgbwColor color = bus->GetPixelColorRgbw(0); RgbwColor c;
uint32_t col = bus->GetPixelColorRgbw(0);
c.R = col >> 16; c.G = col >> 8; c.B = col; c.W = col >> 24;
byte b = getBrightness(); byte b = getBrightness();
if (color == _analogLastColor && b == _analogLastBri) return; if (color == _analogLastColor && b == _analogLastBri) return;
// check color values for Warm / Cold white mix (for RGBW) // EsplanexaDevice.cpp // check color values for Warm / Cold white mix (for RGBW) // EsplanexaDevice.cpp
#ifdef WLED_USE_5CH_LEDS #ifdef WLED_USE_5CH_LEDS
if (color.R == 255 && color.G == 255 && color.B == 255 && color.W == 255) { if (c.R == 255 && c.G == 255 && c.B == 255 && c.W == 255) {
bus->SetRgbwPwm(0, 0, 0, 0, color.W * b / 255); bus->SetRgbwPwm(0, 0, 0, 0, c.W * b / 255);
} else if (color.R == 127 && color.G == 127 && color.B == 127 && color.W == 255) { } else if (c.R == 127 && c.G == 127 && c.B == 127 && c.W == 255) {
bus->SetRgbwPwm(0, 0, 0, color.W * b / 512, color.W * b / 255); bus->SetRgbwPwm(0, 0, 0, c.W * b / 512, c.W * b / 255);
} else if (color.R == 0 && color.G == 0 && color.B == 0 && color.W == 255) { } else if (c.R == 0 && c.G == 0 && c.B == 0 && c.W == 255) {
bus->SetRgbwPwm(0, 0, 0, color.W * b / 255, 0); bus->SetRgbwPwm(0, 0, 0, c.W * b / 255, 0);
} else if (color.R == 130 && color.G == 90 && color.B == 0 && color.W == 255) { } else if (c.R == 130 && c.G == 90 && c.B == 0 && c.W == 255) {
bus->SetRgbwPwm(0, 0, 0, color.W * b / 255, color.W * b / 512); bus->SetRgbwPwm(0, 0, 0, c.W * b / 255, c.W * b / 512);
} else if (color.R == 255 && color.G == 153 && color.B == 0 && color.W == 255) { } else if (c.R == 255 && c.G == 153 && c.B == 0 && c.W == 255) {
bus->SetRgbwPwm(0, 0, 0, color.W * b / 255, 0); bus->SetRgbwPwm(0, 0, 0, c.W * b / 255, 0);
} else { // not only white colors } else { // not only white colors
bus->SetRgbwPwm(color.R * b / 255, color.G * b / 255, color.B * b / 255, color.W * b / 255); bus->SetRgbwPwm(c.R * b / 255, c.G * b / 255, c.B * b / 255, c.W * b / 255);
} }
#else #else
bus->SetRgbwPwm(color.R * b / 255, color.G * b / 255, color.B * b / 255, color.W * b / 255); bus->SetRgbwPwm(c.R * b / 255, c.G * b / 255, c.B * b / 255, c.W * b / 255);
#endif #endif
_analogLastColor = color; _analogLastColor = color;
_analogLastBri = b; _analogLastBri = b;

View File

@ -41,6 +41,13 @@
#define RLYMDE 1 //mode for relay, 0: LOW if LEDs are on 1: HIGH if LEDs are on #define RLYMDE 1 //mode for relay, 0: LOW if LEDs are on 1: HIGH if LEDs are on
#endif #endif
//enable color order override for a specific range of the strip
//This can be useful if you want to chain multiple strings with incompatible color order
//#define COLOR_ORDER_OVERRIDE
#define COO_MIN 0
#define COO_MAX 27 //not inclusive, this would set the override for LEDs 0-26
#define COO_ORDER COL_ORDER_GRB
//END CONFIGURATION //END CONFIGURATION
#if defined(USE_APA102) || defined(USE_WS2801) || defined(USE_LPD8806) || defined(USE_P9813) #if defined(USE_APA102) || defined(USE_WS2801) || defined(USE_LPD8806) || defined(USE_P9813)
@ -168,6 +175,7 @@
#include <NeoPixelBrightnessBus.h> #include <NeoPixelBrightnessBus.h>
#include "const.h"
enum NeoPixelType enum NeoPixelType
{ {
@ -296,23 +304,41 @@ public:
} }
} }
void SetPixelColor(uint16_t indexPixel, RgbwColor color) void SetPixelColor(uint16_t indexPixel, RgbwColor c)
{ {
RgbwColor col;
uint8_t co = _colorOrder;
#ifdef COLOR_ORDER_OVERRIDE
if (indexPixel >= COO_MIN && indexPixel < COO_MAX) co = COO_ORDER;
#endif
//reorder channels to selected order
switch (co)
{
case 0: col.G = c.G; col.R = c.R; col.B = c.B; break; //0 = GRB, default
case 1: col.G = c.R; col.R = c.G; col.B = c.B; break; //1 = RGB, common for WS2811
case 2: col.G = c.B; col.R = c.R; col.B = c.G; break; //2 = BRG
case 3: col.G = c.R; col.R = c.B; col.B = c.G; break; //3 = RBG
case 4: col.G = c.B; col.R = c.G; col.B = c.R; break; //4 = BGR
default: col.G = c.G; col.R = c.B; col.B = c.R; break; //5 = GBR
}
col.W = c.W;
switch (_type) { switch (_type) {
case NeoPixelType_Grb: { case NeoPixelType_Grb: {
_pGrb->SetPixelColor(indexPixel, RgbColor(color.R,color.G,color.B)); _pGrb->SetPixelColor(indexPixel, RgbColor(col.R,col.G,col.B));
} }
break; break;
case NeoPixelType_Grbw: { case NeoPixelType_Grbw: {
#if defined(USE_LPD8806) || defined(USE_WS2801) #if defined(USE_LPD8806) || defined(USE_WS2801)
_pGrbw->SetPixelColor(indexPixel, RgbColor(color.R,color.G,color.B)); _pGrbw->SetPixelColor(indexPixel, RgbColor(col.R,col.G,col.B));
#else #else
_pGrbw->SetPixelColor(indexPixel, color); _pGrbw->SetPixelColor(indexPixel, col);
#endif #endif
} }
break; break;
} }
} }
void SetBrightness(byte b) void SetBrightness(byte b)
@ -323,9 +349,15 @@ public:
} }
} }
// NOTE: Due to feature differences, some support RGBW but the method name void SetColorOrder(byte colorOrder) {
// here needs to be unique, thus GetPixeColorRgbw _colorOrder = colorOrder;
RgbwColor GetPixelColorRgbw(uint16_t indexPixel) const }
uint8_t GetColorOrder() {
return _colorOrder;
}
RgbwColor GetPixelColorRaw(uint16_t indexPixel) const
{ {
switch (_type) { switch (_type) {
case NeoPixelType_Grb: return _pGrb->GetPixelColor(indexPixel); break; case NeoPixelType_Grb: return _pGrb->GetPixelColor(indexPixel); break;
@ -334,6 +366,34 @@ public:
return 0; return 0;
} }
// NOTE: Due to feature differences, some support RGBW but the method name
// here needs to be unique, thus GetPixeColorRgbw
uint32_t GetPixelColorRgbw(uint16_t indexPixel) const
{
RgbwColor col(0,0,0,0);
switch (_type) {
case NeoPixelType_Grb: col = _pGrb->GetPixelColor(indexPixel); break;
case NeoPixelType_Grbw: col = _pGrbw->GetPixelColor(indexPixel); break;
}
uint8_t co = _colorOrder;
#ifdef COLOR_ORDER_OVERRIDE
if (indexPixel >= COO_MIN && indexPixel < COO_MAX) co = COO_ORDER;
#endif
switch (co)
{
// W G R B
case 0: return ((col.W << 24) | (col.G << 8) | (col.R << 16) | (col.B)); //0 = GRB, default
case 1: return ((col.W << 24) | (col.R << 8) | (col.G << 16) | (col.B)); //1 = RGB, common for WS2811
case 2: return ((col.W << 24) | (col.B << 8) | (col.R << 16) | (col.G)); //2 = BRG
case 3: return ((col.W << 24) | (col.B << 8) | (col.G << 16) | (col.R)); //3 = RBG
case 4: return ((col.W << 24) | (col.R << 8) | (col.B << 16) | (col.G)); //4 = BGR
case 5: return ((col.W << 24) | (col.G << 8) | (col.B << 16) | (col.R)); //5 = GBR
}
return 0;
}
uint8_t* GetPixels(void) uint8_t* GetPixels(void)
{ {
switch (_type) { switch (_type) {
@ -351,6 +411,8 @@ private:
NeoPixelBrightnessBus<PIXELFEATURE3,PIXELMETHOD>* _pGrb; NeoPixelBrightnessBus<PIXELFEATURE3,PIXELMETHOD>* _pGrb;
NeoPixelBrightnessBus<PIXELFEATURE4,PIXELMETHOD>* _pGrbw; NeoPixelBrightnessBus<PIXELFEATURE4,PIXELMETHOD>* _pGrbw;
byte _colorOrder = 0;
void cleanup() void cleanup()
{ {
switch (_type) { switch (_type) {

View File

@ -99,7 +99,7 @@ void deserializeConfig() {
//int hw_led_ins_0_pin_0 = hw_led_ins_0[F("pin")][0]; // 2 //int hw_led_ins_0_pin_0 = hw_led_ins_0[F("pin")][0]; // 2
strip.colorOrder = hw_led_ins_0[F("order")]; strip.setColorOrder(hw_led_ins_0[F("order")]);
//bool hw_led_ins_0_rev = hw_led_ins_0[F("rev")]; // false //bool hw_led_ins_0_rev = hw_led_ins_0[F("rev")]; // false
skipFirstLed = hw_led_ins_0[F("skip")]; // 0 skipFirstLed = hw_led_ins_0[F("skip")]; // 0
useRGBW = (hw_led_ins_0[F("type")] == TYPE_SK6812_RGBW); useRGBW = (hw_led_ins_0[F("type")] == TYPE_SK6812_RGBW);
@ -390,7 +390,7 @@ void serializeConfig() {
#ifdef DATAPIN #ifdef DATAPIN
hw_led_ins_0_pin.add(DATAPIN); hw_led_ins_0_pin.add(DATAPIN);
#endif #endif
hw_led_ins_0[F("order")] = strip.colorOrder; //color order hw_led_ins_0[F("order")] = strip.getColorOrder();
hw_led_ins_0[F("rev")] = false; hw_led_ins_0[F("rev")] = false;
hw_led_ins_0[F("skip")] = skipFirstLed ? 1 : 0; hw_led_ins_0[F("skip")] = skipFirstLed ? 1 : 0;

View File

@ -104,6 +104,15 @@
#define TYPE_TM1814 54 #define TYPE_TM1814 54
//Color orders
#define COL_ORDER_GRB 0 //GRB(w),defaut
#define COL_ORDER_RGB 1 //common for WS2811
#define COL_ORDER_BRG 2
#define COL_ORDER_RBG 3
#define COL_ORDER_BGR 4
#define COL_ORDER_GBR 5
//Button type //Button type
#define BTN_TYPE_NONE 0 #define BTN_TYPE_NONE 0
#define BTN_TYPE_RESERVED 1 #define BTN_TYPE_RESERVED 1

View File

@ -82,7 +82,7 @@ void handleSettingsSet(AsyncWebServerRequest *request, byte subPage)
strip.milliampsPerLed = request->arg(F("LA")).toInt(); strip.milliampsPerLed = request->arg(F("LA")).toInt();
useRGBW = request->hasArg(F("EW")); useRGBW = request->hasArg(F("EW"));
strip.colorOrder = request->arg(F("CO")).toInt(); strip.setColorOrder(request->arg(F("CO")).toInt());
strip.rgbwMode = request->arg(F("AW")).toInt(); strip.rgbwMode = request->arg(F("AW")).toInt();
briS = request->arg(F("CA")).toInt(); briS = request->arg(F("CA")).toInt();

View File

@ -8,7 +8,7 @@
*/ */
// version code in format yymmddb (b = daily build) // version code in format yymmddb (b = daily build)
#define VERSION 2011230 #define VERSION 2011270
//uncomment this if you have a "my_config.h" file you'd like to use //uncomment this if you have a "my_config.h" file you'd like to use
//#define WLED_USE_MY_CONFIG //#define WLED_USE_MY_CONFIG

View File

@ -224,7 +224,7 @@ void loadSettingsFromEEPROM()
if (lastEEPROMversion > 9) if (lastEEPROMversion > 9)
{ {
strip.colorOrder = EEPROM.read(383); strip.setColorOrder(EEPROM.read(383));
irEnabled = EEPROM.read(385); irEnabled = EEPROM.read(385);
strip.ablMilliampsMax = EEPROM.read(387) + ((EEPROM.read(388) << 8) & 0xFF00); strip.ablMilliampsMax = EEPROM.read(387) + ((EEPROM.read(388) << 8) & 0xFF00);
} else if (lastEEPROMversion > 1) //ABL is off by default when updating from version older than 0.8.2 } else if (lastEEPROMversion > 1) //ABL is off by default when updating from version older than 0.8.2

View File

@ -268,7 +268,7 @@ void getSettingsJS(byte subPage, char* dest)
sappend('v',SET_F("CA"),briS); sappend('v',SET_F("CA"),briS);
sappend('c',SET_F("EW"),useRGBW); sappend('c',SET_F("EW"),useRGBW);
sappend('i',SET_F("CO"),strip.colorOrder); sappend('i',SET_F("CO"),strip.getColorOrder());
sappend('v',SET_F("AW"),strip.rgbwMode); sappend('v',SET_F("AW"),strip.rgbwMode);
sappend('c',SET_F("BO"),turnOnAtBoot); sappend('c',SET_F("BO"),turnOnAtBoot);