From 9519c8edbd016a14bb0585ac92e2bb2e2e059d0e Mon Sep 17 00:00:00 2001 From: Blaz Kristan Date: Wed, 6 Jul 2022 19:42:48 +0200 Subject: [PATCH] Fix disbling AudioReactive usermod Reduce IRAM pressure for ESP8266 --- usermods/audioreactive/audio_reactive.h | 29 +++++++++++++++---------- wled00/FX_2Dfcn.cpp | 22 ++++++++++++++----- wled00/FX_fcn.cpp | 17 +++++++++++++++ 3 files changed, 51 insertions(+), 17 deletions(-) diff --git a/usermods/audioreactive/audio_reactive.h b/usermods/audioreactive/audio_reactive.h index 0e9ddb233..24cf651a0 100644 --- a/usermods/audioreactive/audio_reactive.h +++ b/usermods/audioreactive/audio_reactive.h @@ -110,7 +110,7 @@ static float fftResultPink[16] = { 1.70f, 1.71f, 1.73f, 1.78f, 1.68f, 1.56f, 1.5 // Create FFT object static arduinoFFT FFT = arduinoFFT(vReal, vImag, samplesFFT, SAMPLE_RATE); -static TaskHandle_t FFT_Task; +static TaskHandle_t FFT_Task = nullptr; float fftAddAvg(int from, int to) { float result = 0.0f; @@ -987,17 +987,22 @@ class AudioReactive : public Usermod { #ifdef WLED_DEBUG fftTime = sampleTime = 0; #endif - if (init) vTaskDelete(FFT_Task); // update is about to begin, remove task to prevent crash - else { // update has failed or create task requested - // Define the FFT Task and lock it to core 0 - xTaskCreatePinnedToCore( - FFTcode, // Function to implement the task - "FFT", // Name of the task - 5000, // Stack size in words - NULL, // Task input parameter - 1, // Priority of the task - &FFT_Task, // Task handle - 0); // Core where the task should run + if (init && FFT_Task) { + vTaskSuspend(FFT_Task); // update is about to begin, disable task to prevent crash + } else { + // update has failed or create task requested + if (FFT_Task) + vTaskResume(FFT_Task); + else + xTaskCreatePinnedToCore( + FFTcode, // Function to implement the task + "FFT", // Name of the task + 5000, // Stack size in words + NULL, // Task input parameter + 1, // Priority of the task + &FFT_Task, // Task handle + 0 // Core where the task should run + ); } } diff --git a/wled00/FX_2Dfcn.cpp b/wled00/FX_2Dfcn.cpp index b592fa863..d90954cd2 100644 --- a/wled00/FX_2Dfcn.cpp +++ b/wled00/FX_2Dfcn.cpp @@ -26,6 +26,23 @@ #include "FX.h" #include "palettes.h" +#ifdef SEGMENT + #undef SEGMENT + #define SEGMENT _segments[_segment_index] +#endif +#ifdef SEGCOLOR + #undef SEGCOLOR + #define SEGCOLOR(x) _colors_t[x] +#endif +#ifdef SEGENV + #undef SEGENV + #define SEGENV _segment_runtimes[_segment_index] +#endif +#ifdef SEGLEN + #undef SEGLEN + #define SEGLEN _virtualSegmentLength +#endif + // setUpMatrix() - constructs ledmap array from matrix of panels with WxH pixels // this converts physical (possibly irregular) LED arrangement into well defined // array of logical pixels: fist entry corresponds to left-topmost logical pixel @@ -151,21 +168,16 @@ void IRAM_ATTR WS2812FX::setPixelColorXY(int x, int y, byte r, byte g, byte b, b uint16_t index, xX = (x+g), yY = (y+j); if (xX >= SEGMENT.width() || yY >= SEGMENT.height()) continue; // we have reached one dimension's end - //if (SEGMENT.getOption(SEG_OPTION_REVERSED) ) xX = SEGMENT.width() - xX - 1; - //if (SEGMENT.getOption(SEG_OPTION_REVERSED_Y)) yY = SEGMENT.height() - yY - 1; - index = get2DPixelIndex(xX, yY); if (index < customMappingSize) index = customMappingTable[index]; busses.setPixelColor(index, col); if (SEGMENT.getOption(SEG_OPTION_MIRROR)) { //set the corresponding horizontally mirrored pixel - //index = get2DPixelIndex(SEGMENT.width() - xX - 1, yY); index = SEGMENT.getOption(SEG_OPTION_TRANSPOSED) ? get2DPixelIndex(xX, SEGMENT.height() - yY - 1) : get2DPixelIndex(SEGMENT.width() - xX - 1, yY); if (index < customMappingSize) index = customMappingTable[index]; busses.setPixelColor(index, col); } if (SEGMENT.getOption(SEG_OPTION_MIRROR_Y)) { //set the corresponding vertically mirrored pixel - //index = get2DPixelIndex(xX, SEGMENT.height() - yY - 1); index = SEGMENT.getOption(SEG_OPTION_TRANSPOSED) ? get2DPixelIndex(SEGMENT.width() - xX - 1, yY) : get2DPixelIndex(xX, SEGMENT.height() - yY - 1); if (index < customMappingSize) index = customMappingTable[index]; busses.setPixelColor(index, col); diff --git a/wled00/FX_fcn.cpp b/wled00/FX_fcn.cpp index be9aaa7b5..8ac84bfd4 100644 --- a/wled00/FX_fcn.cpp +++ b/wled00/FX_fcn.cpp @@ -27,6 +27,23 @@ #include "FX.h" #include "palettes.h" +#ifdef SEGMENT + #undef SEGMENT + #define SEGMENT _segments[_segment_index] +#endif +#ifdef SEGCOLOR + #undef SEGCOLOR + #define SEGCOLOR(x) _colors_t[x] +#endif +#ifdef SEGENV + #undef SEGENV + #define SEGENV _segment_runtimes[_segment_index] +#endif +#ifdef SEGLEN + #undef SEGLEN + #define SEGLEN _virtualSegmentLength +#endif + /* Custom per-LED mapping has moved!