From e5c4fcfa7311338accff7edf405bdd3d6e4661d0 Mon Sep 17 00:00:00 2001 From: LunarLegionnaire <123407168+LunarLegionnaire@users.noreply.github.com> Date: Mon, 23 Jan 2023 17:50:47 -0800 Subject: [PATCH 1/4] Update SmartMatrixHUB75.h controller for generic panels Update to SmartMatrixHUB75.h to be more user friendly in applying to other HUB75 panels, including a PixelGroup generator for rectangular panel setups. For a 2 panel (left/right) setup, users should only have to interact with the setup block. --- src/Controllers/SmartMatrixHUB75.h | 64 ++++++++++++++++-------------- 1 file changed, 35 insertions(+), 29 deletions(-) diff --git a/src/Controllers/SmartMatrixHUB75.h b/src/Controllers/SmartMatrixHUB75.h index 2e48bf95..1a654505 100644 --- a/src/Controllers/SmartMatrixHUB75.h +++ b/src/Controllers/SmartMatrixHUB75.h @@ -10,17 +10,24 @@ #include "Controller.h" #include "Render/Camera.h" -#include "Flash/PixelGroups/P3HUB75.h" +//#include "Flash/PixelGroups/P3HUB75.h" #include "Flash/PixelGroups/LinearPixels.h" -//HUB75 +//HUB75 SETUP ~~~~~~~~~~ +#define RESOLUTION_X 128 //Pixel count of your HUB75 panel +#define RESOLUTION_Y 64 +#define P_VALUE 2 //Use whatever P{VALUE} your panels are, Example: P2, P3, P4. This would be the size of your individual pixels in millimeters. #define ENABLE_HUB75_REFRESH 1 #define COLOR_DEPTH 24 // Choose the color depth used for storing pixels in the layers: 24 or 48 (24 is good for most sketches - If the sketch uses type `rgb24` directly, COLOR_DEPTH must be 24) -const uint16_t kMatrixWidth = 64; // Set to the width of your display, must be a multiple of 8 -const uint16_t kMatrixHeight = 64; // Set to the height of your display +#define VERTICAL_STRETCH 0.8 //float 0.0 - 2.0 give best effects, usually around 0.8 for P2 +#define HORIZONTAL_STRETCH 0.5 //float 0.0 - 2.0 give best effects, usually around 0.5 for P2 +const uint8_t kPanelType = SM_PANELTYPE_HUB75_64ROW_MOD32SCAN; // Choose the configuration that matches your panels. See more details in MatrixCommonHub75.h and the docs: https://github.com/pixelmatix/SmartMatrix/wiki +//~~~~~~~~~~~~ + +const uint16_t kMatrixWidth = RESOLUTION_X; // Set to the width of your display, must be a multiple of 8 +const uint16_t kMatrixHeight = RESOLUTION_Y*2; // Set to the height of your display const uint8_t kRefreshDepth = 36; // Tradeoff of color quality vs refresh rate, max brightness, and RAM usage. 36 is typically good, drop down to 24 if you need to. On Teensy, multiples of 3, up to 48: 3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, 48. On ESP32: 24, 36, 48 const uint8_t kDmaBufferRows = 4; // known working: 2-4, use 2 to save RAM, more to keep from dropping frames and automatically lowering refresh rate. (This isn't used on ESP32, leave as default) -const uint8_t kPanelType = SM_PANELTYPE_HUB75_32ROW_MOD16SCAN; // Choose the configuration that matches your panels. See more details in MatrixCommonHub75.h and the docs: https://github.com/pixelmatix/SmartMatrix/wiki const uint32_t kMatrixOptions = (SM_HUB75_OPTIONS_NONE); // see docs for options: https://github.com/pixelmatix/SmartMatrix/wiki const uint8_t kBackgroundLayerOptions = (SM_BACKGROUND_OPTIONS_NONE); @@ -45,10 +52,12 @@ class SmartMatrixHUB75 : public Controller { private: CameraLayout cameraLayout = CameraLayout(CameraLayout::ZForward, CameraLayout::YUp); - Transform camTransform = Transform(Vector3D(), Vector3D(0, 0, -500.0f), Vector3D(1, 1, 1)); + Transform camTransform = Transform(Vector3D(), Vector3D(0, 0, 0), Vector3D(HORIZONTAL_STRETCH, VERTICAL_STRETCH, 1)); Transform camSideTransform = Transform(Vector3D(), Vector3D(0, 0, -500.0f), Vector3D(1, 1, 1)); - PixelGroup camPixels = PixelGroup(P3HUB75, 2048); + Vector2D* panel = createPanel(); + PixelGroup camPixels = PixelGroup(panel, RESOLUTION_X*RESOLUTION_Y); + //PixelGroup camPixels = PixelGroup(P3HUB75, 2048); PixelGroup camSidePixels = PixelGroup(LinearPixels, 100); Camera camMain = Camera(&camTransform, &cameraLayout, &camPixels); @@ -59,6 +68,18 @@ class SmartMatrixHUB75 : public Controller { public: SmartMatrixHUB75(uint8_t maxBrightness, uint8_t maxAccentBrightness) : Controller(cameras, 2, maxBrightness, maxAccentBrightness){} + Vector2D* createPanel(){ + static Vector2D panelConfig[RESOLUTION_X*RESOLUTION_Y] = {}; + int count = 0; + for (int y = 0; y < RESOLUTION_Y; y++) { + for (int x = 0; x < RESOLUTION_X; x++){ + panelConfig[count]=Vector2D((float)x*P_VALUE,(float)y*P_VALUE); + count++; + } + } + return panelConfig; + } + void Initialize() override{ //HUB75 matrix.addLayer(&backgroundLayer); @@ -67,38 +88,23 @@ class SmartMatrixHUB75 : public Controller { matrix.setRefreshRate(120); backgroundLayer.swapBuffers();//for ESP32 - first is ignored - - //APA102 - pinMode(SMARTLED_APA_ENABLE_PIN, OUTPUT); - digitalWrite(SMARTLED_APA_ENABLE_PIN, HIGH); // enable access to LEDs - apamatrix.addLayer(&apaBackgroundLayer); - - apamatrix.begin(); } void Display() override { matrix.setBrightness(brightness); - apamatrix.setBrightness(accentBrightness); - - while(apaBackgroundLayer.isSwapPending()); - rgb24 *apabuffer = apaBackgroundLayer.backBuffer(); - for (uint16_t y = 0; y < 32; y++) { - for (uint16_t x = 0; x < 64; x++){ - uint16_t pixelNum = y * 64 + x; + for (uint16_t y = 0; y < RESOLUTION_Y; y++) { + for (uint16_t x = 0; x < RESOLUTION_X; x++){ + uint16_t pixelNum = y * RESOLUTION_X + x; - rgb24 rgbColor = rgb24((uint16_t)camPixels.GetPixel(pixelNum)->Color.R, (uint16_t)camPixels.GetPixel(pixelNum)->Color.G, (uint16_t)camPixels.GetPixel(pixelNum)->Color.B); + rgb24 rgbColor = rgb24((uint16_t)camPixels.GetColor(pixelNum)->R, (uint16_t)camPixels.GetColor(pixelNum)->G, (uint16_t)camPixels.GetColor(pixelNum)->B); - backgroundLayer.drawPixel(x, (31 - y), rgbColor); - backgroundLayer.drawPixel(63 - x, (31 - y) + 32, rgbColor); + + backgroundLayer.drawPixel(x, RESOLUTION_Y - y, rgbColor); + backgroundLayer.drawPixel(RESOLUTION_X - 1 - x, kMatrixHeight-y, rgbColor);//mirroring is vertical, provided by assigning y values up to 2*RESOLUTION_Y } } - - for (uint16_t x = 0; x < kApaMatrixWidth; x++){ - apabuffer[x] = CRGB(camSidePixels.GetPixel(x)->Color.R, camSidePixels.GetPixel(x)->Color.G, camSidePixels.GetPixel(x)->Color.B); - } backgroundLayer.swapBuffers(); - apaBackgroundLayer.swapBuffers(false); } }; From 802431b7da0447deaa733bf1c3fa4737406c92b0 Mon Sep 17 00:00:00 2001 From: LunarLegionnaire <123407168+LunarLegionnaire@users.noreply.github.com> Date: Mon, 23 Jan 2023 18:01:14 -0800 Subject: [PATCH 2/4] Revert removal of external led string --- src/Controllers/SmartMatrixHUB75.h | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/Controllers/SmartMatrixHUB75.h b/src/Controllers/SmartMatrixHUB75.h index 1a654505..f9a82cfe 100644 --- a/src/Controllers/SmartMatrixHUB75.h +++ b/src/Controllers/SmartMatrixHUB75.h @@ -88,10 +88,21 @@ class SmartMatrixHUB75 : public Controller { matrix.setRefreshRate(120); backgroundLayer.swapBuffers();//for ESP32 - first is ignored + + //APA102 + pinMode(SMARTLED_APA_ENABLE_PIN, OUTPUT); + digitalWrite(SMARTLED_APA_ENABLE_PIN, HIGH); // enable access to LEDs + apamatrix.addLayer(&apaBackgroundLayer); + + apamatrix.begin(); } void Display() override { matrix.setBrightness(brightness); + apamatrix.setBrightness(accentBrightness); + + while(apaBackgroundLayer.isSwapPending()); + rgb24 *apabuffer = apaBackgroundLayer.backBuffer(); for (uint16_t y = 0; y < RESOLUTION_Y; y++) { for (uint16_t x = 0; x < RESOLUTION_X; x++){ @@ -99,12 +110,16 @@ class SmartMatrixHUB75 : public Controller { rgb24 rgbColor = rgb24((uint16_t)camPixels.GetColor(pixelNum)->R, (uint16_t)camPixels.GetColor(pixelNum)->G, (uint16_t)camPixels.GetColor(pixelNum)->B); - backgroundLayer.drawPixel(x, RESOLUTION_Y - y, rgbColor); backgroundLayer.drawPixel(RESOLUTION_X - 1 - x, kMatrixHeight-y, rgbColor);//mirroring is vertical, provided by assigning y values up to 2*RESOLUTION_Y } } + + for (uint16_t x = 0; x < kApaMatrixWidth; x++){ + apabuffer[x] = CRGB(camSidePixels.GetColor(x)->R, camSidePixels.GetColor(x)->G, camSidePixels.GetColor(x)->B); + } backgroundLayer.swapBuffers(); + apaBackgroundLayer.swapBuffers(false); } }; From 0c3dd00e3177e3fa0b55379babe809eb608a2d3e Mon Sep 17 00:00:00 2001 From: LunarLegionnaire <123407168+LunarLegionnaire@users.noreply.github.com> Date: Tue, 24 Jan 2023 18:03:05 -0800 Subject: [PATCH 3/4] Add toggle between panel definition modes Added a toggle between two different PixelGroup constructions, '0' is base rectangular constructor from PixelGroup, '1' is less memory conscious but seems to have better FPS performance. --- src/Controllers/SmartMatrixHUB75.h | 48 +++++++++++++----------------- 1 file changed, 21 insertions(+), 27 deletions(-) diff --git a/src/Controllers/SmartMatrixHUB75.h b/src/Controllers/SmartMatrixHUB75.h index f9a82cfe..4b48beb3 100644 --- a/src/Controllers/SmartMatrixHUB75.h +++ b/src/Controllers/SmartMatrixHUB75.h @@ -16,11 +16,12 @@ //HUB75 SETUP ~~~~~~~~~~ #define RESOLUTION_X 128 //Pixel count of your HUB75 panel #define RESOLUTION_Y 64 -#define P_VALUE 2 //Use whatever P{VALUE} your panels are, Example: P2, P3, P4. This would be the size of your individual pixels in millimeters. +#define P_VALUE 2 //Use whatever P{VALUE} your panels are, Example: P2, P3, P4 #define ENABLE_HUB75_REFRESH 1 #define COLOR_DEPTH 24 // Choose the color depth used for storing pixels in the layers: 24 or 48 (24 is good for most sketches - If the sketch uses type `rgb24` directly, COLOR_DEPTH must be 24) #define VERTICAL_STRETCH 0.8 //float 0.0 - 2.0 give best effects, usually around 0.8 for P2 #define HORIZONTAL_STRETCH 0.5 //float 0.0 - 2.0 give best effects, usually around 0.5 for P2 +#define PIXELGROUP_TYPE 1 //0 = Base CoelaCan't formatting (better for memory), 1 = Slightly better FPS performance but more memory const uint8_t kPanelType = SM_PANELTYPE_HUB75_64ROW_MOD32SCAN; // Choose the configuration that matches your panels. See more details in MatrixCommonHub75.h and the docs: https://github.com/pixelmatix/SmartMatrix/wiki //~~~~~~~~~~~~ @@ -55,8 +56,10 @@ class SmartMatrixHUB75 : public Controller { Transform camTransform = Transform(Vector3D(), Vector3D(0, 0, 0), Vector3D(HORIZONTAL_STRETCH, VERTICAL_STRETCH, 1)); Transform camSideTransform = Transform(Vector3D(), Vector3D(0, 0, -500.0f), Vector3D(1, 1, 1)); - Vector2D* panel = createPanel(); - PixelGroup camPixels = PixelGroup(panel, RESOLUTION_X*RESOLUTION_Y); + PixelGroup camPixels = createPanel(); + //Vector2D* panel = createPanel(); + //PixelGroup camPixels = PixelGroup(panel, RESOLUTION_X*RESOLUTION_Y); + //PixelGroup camPixels = PixelGroup(P3HUB75, 2048); PixelGroup camSidePixels = PixelGroup(LinearPixels, 100); @@ -68,16 +71,22 @@ class SmartMatrixHUB75 : public Controller { public: SmartMatrixHUB75(uint8_t maxBrightness, uint8_t maxAccentBrightness) : Controller(cameras, 2, maxBrightness, maxAccentBrightness){} - Vector2D* createPanel(){ - static Vector2D panelConfig[RESOLUTION_X*RESOLUTION_Y] = {}; - int count = 0; - for (int y = 0; y < RESOLUTION_Y; y++) { - for (int x = 0; x < RESOLUTION_X; x++){ - panelConfig[count]=Vector2D((float)x*P_VALUE,(float)y*P_VALUE); - count++; + PixelGroup createPanel(){ + + if(PIXELGROUP_TYPE == 0){ + return PixelGroup(Vector2D(RESOLUTION_X*P_VALUE,RESOLUTION_Y*P_VALUE), Vector2D(RESOLUTION_X,RESOLUTION_Y), RESOLUTION_Y*2, RESOLUTION_X*RESOLUTION_Y); + } else { + static Vector2D panelConfig[RESOLUTION_X*RESOLUTION_Y] = {}; + int count = 0; + for (int y = 0; y < RESOLUTION_Y; y++) { + for (int x = 0; x < RESOLUTION_X; x++){ + panelConfig[count]=Vector2D((float)x*P_VALUE,(float)y*P_VALUE); + count++; + } } + return PixelGroup(panelConfig, RESOLUTION_X*RESOLUTION_Y); } - return panelConfig; + return camPixels; } void Initialize() override{ @@ -88,21 +97,10 @@ class SmartMatrixHUB75 : public Controller { matrix.setRefreshRate(120); backgroundLayer.swapBuffers();//for ESP32 - first is ignored - - //APA102 - pinMode(SMARTLED_APA_ENABLE_PIN, OUTPUT); - digitalWrite(SMARTLED_APA_ENABLE_PIN, HIGH); // enable access to LEDs - apamatrix.addLayer(&apaBackgroundLayer); - - apamatrix.begin(); } void Display() override { matrix.setBrightness(brightness); - apamatrix.setBrightness(accentBrightness); - - while(apaBackgroundLayer.isSwapPending()); - rgb24 *apabuffer = apaBackgroundLayer.backBuffer(); for (uint16_t y = 0; y < RESOLUTION_Y; y++) { for (uint16_t x = 0; x < RESOLUTION_X; x++){ @@ -110,16 +108,12 @@ class SmartMatrixHUB75 : public Controller { rgb24 rgbColor = rgb24((uint16_t)camPixels.GetColor(pixelNum)->R, (uint16_t)camPixels.GetColor(pixelNum)->G, (uint16_t)camPixels.GetColor(pixelNum)->B); + backgroundLayer.drawPixel(x, RESOLUTION_Y - y, rgbColor); backgroundLayer.drawPixel(RESOLUTION_X - 1 - x, kMatrixHeight-y, rgbColor);//mirroring is vertical, provided by assigning y values up to 2*RESOLUTION_Y } } - - for (uint16_t x = 0; x < kApaMatrixWidth; x++){ - apabuffer[x] = CRGB(camSidePixels.GetColor(x)->R, camSidePixels.GetColor(x)->G, camSidePixels.GetColor(x)->B); - } backgroundLayer.swapBuffers(); - apaBackgroundLayer.swapBuffers(false); } }; From 341c9c3b1e81ea325488582a595078564ee9d1fd Mon Sep 17 00:00:00 2001 From: LunarLegionnaire <123407168+LunarLegionnaire@users.noreply.github.com> Date: Fri, 27 Jan 2023 19:24:56 -0800 Subject: [PATCH 4/4] Fix errant line appearing on other panel --- src/Controllers/SmartMatrixHUB75.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Controllers/SmartMatrixHUB75.h b/src/Controllers/SmartMatrixHUB75.h index 4b48beb3..b8665243 100644 --- a/src/Controllers/SmartMatrixHUB75.h +++ b/src/Controllers/SmartMatrixHUB75.h @@ -110,7 +110,7 @@ class SmartMatrixHUB75 : public Controller { backgroundLayer.drawPixel(x, RESOLUTION_Y - y, rgbColor); - backgroundLayer.drawPixel(RESOLUTION_X - 1 - x, kMatrixHeight-y, rgbColor);//mirroring is vertical, provided by assigning y values up to 2*RESOLUTION_Y + backgroundLayer.drawPixel(RESOLUTION_X - 1 - x, kMatrixHeight-y-1, rgbColor);//mirroring is vertical, provided by assigning y values up to 2*RESOLUTION_Y } }