From 634fe64dcafe5865dc7bdd38a50eff28beab0bc3 Mon Sep 17 00:00:00 2001 From: Sam Martin Date: Sat, 28 Nov 2020 21:58:02 -0600 Subject: [PATCH 1/2] update to track core NpbWrapper.h --- usermods/esp32_multistrip/NpbWrapper.h | 106 ++++++++++++++++++++----- 1 file changed, 85 insertions(+), 21 deletions(-) diff --git a/usermods/esp32_multistrip/NpbWrapper.h b/usermods/esp32_multistrip/NpbWrapper.h index 1058e514..4fbcce26 100644 --- a/usermods/esp32_multistrip/NpbWrapper.h +++ b/usermods/esp32_multistrip/NpbWrapper.h @@ -41,6 +41,7 @@ #endif #include +#include "const.h" const uint8_t numStrips = NUM_STRIPS; // max 8 strips allowed on esp32 const uint16_t pixelCounts[numStrips] = {PIXEL_COUNTS}; // number of pixels on each strip @@ -190,7 +191,7 @@ public: } } - void SetPixelColor(uint16_t indexPixel, RgbwColor color) + void SetPixelColorRaw(uint16_t indexPixel, RgbwColor c) { // figure out which strip this pixel index is on uint8_t stripIdx = 0; @@ -211,17 +212,17 @@ public: { case NeoPixelType_Grb: { - RgbColor c = RgbColor(color.R, color.G, color.B); + RgbColor rgb = RgbColor(c.R, c.G, c.B); switch (stripIdx) { - case 0: pGrb0->SetPixelColor(indexPixel, c); break; - case 1: pGrb1->SetPixelColor(indexPixel, c); break; - case 2: pGrb2->SetPixelColor(indexPixel, c); break; - case 3: pGrb3->SetPixelColor(indexPixel, c); break; - case 4: pGrb4->SetPixelColor(indexPixel, c); break; - case 5: pGrb5->SetPixelColor(indexPixel, c); break; - case 6: pGrb6->SetPixelColor(indexPixel, c); break; - case 7: pGrb7->SetPixelColor(indexPixel, c); break; + case 0: pGrb0->SetPixelColor(indexPixel, rgb); break; + case 1: pGrb1->SetPixelColor(indexPixel, rgb); break; + case 2: pGrb2->SetPixelColor(indexPixel, rgb); break; + case 3: pGrb3->SetPixelColor(indexPixel, rgb); break; + case 4: pGrb4->SetPixelColor(indexPixel, rgb); break; + case 5: pGrb5->SetPixelColor(indexPixel, rgb); break; + case 6: pGrb6->SetPixelColor(indexPixel, rgb); break; + case 7: pGrb7->SetPixelColor(indexPixel, rgb); break; } break; } @@ -229,20 +230,48 @@ public: { switch (stripIdx) { - case 0: pGrbw0->SetPixelColor(indexPixel, color); break; - case 1: pGrbw1->SetPixelColor(indexPixel, color); break; - case 2: pGrbw2->SetPixelColor(indexPixel, color); break; - case 3: pGrbw3->SetPixelColor(indexPixel, color); break; - case 4: pGrbw4->SetPixelColor(indexPixel, color); break; - case 5: pGrbw5->SetPixelColor(indexPixel, color); break; - case 6: pGrbw6->SetPixelColor(indexPixel, color); break; - case 7: pGrbw7->SetPixelColor(indexPixel, color); break; + case 0: pGrbw0->SetPixelColor(indexPixel, c); break; + case 1: pGrbw1->SetPixelColor(indexPixel, c); break; + case 2: pGrbw2->SetPixelColor(indexPixel, c); break; + case 3: pGrbw3->SetPixelColor(indexPixel, c); break; + case 4: pGrbw4->SetPixelColor(indexPixel, c); break; + case 5: pGrbw5->SetPixelColor(indexPixel, c); break; + case 6: pGrbw6->SetPixelColor(indexPixel, c); break; + case 7: pGrbw7->SetPixelColor(indexPixel, c); break; } break; } } } + void SetPixelColor(uint16_t indexPixel, RgbwColor c) + { + /* + Set pixel color with necessary color order conversion. + */ + + 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; + + SetPixelColorRaw(indexPixel, col); + } + void SetBrightness(byte b) { switch (_type) @@ -286,9 +315,17 @@ public: } } - // NOTE: Due to feature differences, some support RGBW but the method name - // here needs to be unique, thus GetPixeColorRgbw - RgbwColor GetPixelColorRgbw(uint16_t indexPixel) const + void SetColorOrder(byte colorOrder) + { + _colorOrder = colorOrder; + } + + uint8_t GetColorOrder() + { + return _colorOrder; + } + + RgbwColor GetPixelColorRaw(uint16_t indexPixel) const { // figure out which strip this pixel index is on uint8_t stripIdx = 0; @@ -339,8 +376,35 @@ public: 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 = GetPixelColorRaw(indexPixel); + 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; + + } + + private: NeoPixelType _type; + byte _colorOrder = 0; uint16_t pixelStripStartIdx[numStrips]; From 4b8cde7b3b007db8d9070d89bff98f61a325b534 Mon Sep 17 00:00:00 2001 From: Sam Martin Date: Sat, 12 Dec 2020 07:58:25 -0600 Subject: [PATCH 2/2] added CanShow function to fix build errors --- usermods/esp32_multistrip/NpbWrapper.h | 46 +++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/usermods/esp32_multistrip/NpbWrapper.h b/usermods/esp32_multistrip/NpbWrapper.h index e468e46e..84cf8ac0 100644 --- a/usermods/esp32_multistrip/NpbWrapper.h +++ b/usermods/esp32_multistrip/NpbWrapper.h @@ -149,7 +149,6 @@ public: void Show() { - byte b; switch (_type) { case NeoPixelType_Grb: @@ -191,6 +190,51 @@ public: } } + bool CanShow() + { + bool canShow = true; + switch (_type) + { + case NeoPixelType_Grb: + { + for (uint8_t idx = 0; idx < numStrips; idx++) + { + switch (idx) + { + case 0: canShow &= pGrb0->CanShow(); break; + case 1: canShow &= pGrb1->CanShow(); break; + case 2: canShow &= pGrb2->CanShow(); break; + case 3: canShow &= pGrb3->CanShow(); break; + case 4: canShow &= pGrb4->CanShow(); break; + case 5: canShow &= pGrb5->CanShow(); break; + case 6: canShow &= pGrb6->CanShow(); break; + case 7: canShow &= pGrb7->CanShow(); break; + } + } + break; + } + case NeoPixelType_Grbw: + { + for (uint8_t idx = 0; idx < numStrips; idx++) + { + switch (idx) + { + case 0: canShow &= pGrbw0->CanShow(); break; + case 1: canShow &= pGrbw1->CanShow(); break; + case 2: canShow &= pGrbw2->CanShow(); break; + case 3: canShow &= pGrbw3->CanShow(); break; + case 4: canShow &= pGrbw4->CanShow(); break; + case 5: canShow &= pGrbw5->CanShow(); break; + case 6: canShow &= pGrbw6->CanShow(); break; + case 7: canShow &= pGrbw7->CanShow(); break; + } + } + break; + } + } + return canShow; + } + void SetPixelColorRaw(uint16_t indexPixel, RgbwColor c) { // figure out which strip this pixel index is on