From 0575babe735fcb0bf5f30956b948a2792faf7e57 Mon Sep 17 00:00:00 2001 From: Will Tatam Date: Wed, 25 Oct 2023 19:20:09 +0100 Subject: [PATCH] Inital code for HUB75 output --- platformio.ini | 12 ++++++- src/User/UserModHub75.h | 80 +++++++++++++++++++++++++++++++++++++++++ src/main.cpp | 10 ++++++ 3 files changed, 101 insertions(+), 1 deletion(-) create mode 100644 src/User/UserModHub75.h diff --git a/platformio.ini b/platformio.ini index 9f0789be..515387b3 100644 --- a/platformio.ini +++ b/platformio.ini @@ -39,7 +39,15 @@ lib_deps = build_flags = -D USERMOD_WLEDAUDIO lib_deps = - https://github.com/netmindz/WLED-sync#v0.14.0.b16 + https://github.com/netmindz/WLED-sync#v0.14.0.b16 + +[usermod_hub75] +build_flags = + -D USERMOD_HUB75 +lib_deps = + ; https://github.com/pixelmatix/SmartMatrix.git@4.0.3 + https://github.com/netmindz/SmartMatrix.git#platform-2-support + [env:esp32dev] platform = espressif32 @@ -53,12 +61,14 @@ build_flags = ${usermod_e131.build_flags} ; ${usermod_ha.build_flags} ${usermod_wledaudio.build_flags} + ${usermod_hub75.build_flags} lib_deps = ${starmod.lib_deps} ${appmod_leds.lib_deps} ${usermod_e131.lib_deps} ; ${usermod_ha.lib_deps} ${usermod_wledaudio.lib_deps} + ${usermod_hub75.lib_deps} ; RAM: [== ] 15.6% (used 51124 bytes from 327680 bytes) ; Flash: [======= ] 68.1% (used 892033 bytes from 1310720 bytes) diff --git a/src/User/UserModHub75.h b/src/User/UserModHub75.h new file mode 100644 index 00000000..15d9890d --- /dev/null +++ b/src/User/UserModHub75.h @@ -0,0 +1,80 @@ +/* + @title StarMod + @file UserModHub75.h + @date 20231016 + @repo https://github.com/ewowi/StarMod + @Authors https://github.com/ewowi/StarMod/commits/main + @Copyright (c) 2023 Github StarMod Commit Authors + @license GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 +*/ + +#include +#include + +#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 = 32; // Set to the width of your display, must be a multiple of 8 +const uint16_t kMatrixHeight = 32; // 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); +const uint8_t kScrollingLayerOptions = (SM_SCROLLING_OPTIONS_NONE); +const uint8_t kIndexedLayerOptions = (SM_INDEXED_OPTIONS_NONE); + +SMARTMATRIX_ALLOCATE_BUFFERS(smartMatrix, kMatrixWidth, kMatrixHeight, kRefreshDepth, kDmaBufferRows, kPanelType, kMatrixOptions); + +SMARTMATRIX_ALLOCATE_BACKGROUND_LAYER(backgroundLayer, kMatrixWidth, kMatrixHeight, COLOR_DEPTH, kBackgroundLayerOptions); + +class UserModHub75:public Module { + +public: + + UserModHub75() :Module("HUB75") { + USER_PRINT_FUNCTION("%s %s\n", __PRETTY_FUNCTION__, name); + + isEnabled = false; //default off + + USER_PRINT_FUNCTION("%s %s %s\n", __PRETTY_FUNCTION__, name, success?"success":"failed"); + }; + + //setup filesystem + void setup() { + Module::setup(); + USER_PRINT_FUNCTION("%s %s\n", __PRETTY_FUNCTION__, name); + + parentVar = ui->initModule(parentVar, name); + + smartMatrix.addLayer(&backgroundLayer); + smartMatrix.setBrightness(125); + smartMatrix.begin(); + + buffer = backgroundLayer.backBuffer(); + + USER_PRINT_FUNCTION("%s %s %s\n", __PRETTY_FUNCTION__, name, success?"success":"failed"); + } + + void loop() { + // Module::loop(); + + if(!SysModModules::isConnected) return; + + if(!lds->newFrame) return; + + int bri = mdl->getValue("bri"); + + for (size_t i = 0; i < ledsV.nrOfLedsP; i++) { + CRGB pixel = ledsP[i]; + buffer[i] = rgb24(scale8(pixel.r, bri), scale8(pixel.g, bri), scale8(pixel.b, bri)); + } + + backgroundLayer.swapBuffers(true); + } + + private: + rgb24* buffer; + +}; + +static UserModHub75 *hub75Mod; + diff --git a/src/main.cpp b/src/main.cpp index 754136b9..4718189e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -33,6 +33,9 @@ #ifdef USERMOD_DDP #include "User/UserModDDP.h" #endif + #ifdef USERMOD_HUB75 + #include "User/UserModHub75.h" + #endif #endif #ifdef USERMOD_E131 #include "User/UserModE131.h" @@ -44,6 +47,7 @@ #include "User/UserModWLEDAudio.h" #endif + //setup all modules void setup() { mdls = new SysModModules(); @@ -77,6 +81,9 @@ void setup() { #ifdef USERMOD_WLEDAUDIO wledAudioMod = new UserModWLEDAudio(); #endif + #ifdef USERMOD_HUB75 + hub75Mod = new UserModHub75(); + #endif //prefered default order in the UI. //Reorder with care! If changed make sure mdlEnabled.chFun executes var.createNestedArray("value"); and saveModel! @@ -112,6 +119,9 @@ void setup() { mdls->add(wledAudioMod); #endif mdls->add(mdns); //no ui + #ifdef USERMOD_HUB75 + mdls->add(hub75Mod); + #endif //do not add mdls itself as it does setup and loop for itself!!! (it is the orchestrator) mdls->setup();