From 4c759083be5a0c84c16de9122d7ec40959331599 Mon Sep 17 00:00:00 2001 From: Blaz Kristan Date: Tue, 21 Jun 2022 22:49:45 +0200 Subject: [PATCH] Multiple changes. Added: - introduced addEffect() and setupEffectData() - conditional compile for audio effects - introduced getModeData() and getModeDataSrc() instead of public var - changed _modeData[] to private non-static Fixes: - DMTYPE use - add reboot info to DMTYPE - transpose & reverse with mirroring --- usermods/audioreactive/audio_reactive.h | 7 +- .../usermod_v2_rotary_encoder_ui_ALT.h | 2 +- wled00/FX.cpp | 298 ++++++++++++++++-- wled00/FX.h | 266 ++++++++++++---- wled00/FX_2Dfcn.cpp | 12 +- wled00/json.cpp | 6 +- wled00/util.cpp | 4 +- 7 files changed, 482 insertions(+), 113 deletions(-) diff --git a/usermods/audioreactive/audio_reactive.h b/usermods/audioreactive/audio_reactive.h index 097de10e..dd1c3bdc 100644 --- a/usermods/audioreactive/audio_reactive.h +++ b/usermods/audioreactive/audio_reactive.h @@ -304,10 +304,10 @@ class AudioReactive : public Usermod { #else int8_t audioPin = AUDIOPIN; #endif - #ifndef DMENABLED // I2S mic type - uint8_t dmType = 0; // none/disabled + #ifndef DMTYPE // I2S mic type + uint8_t dmType = 0; // none/disabled/analog #else - uint8_t dmType = DMENABLED; + uint8_t dmType = DMTYPE; #endif #ifndef I2S_SDPIN // aka DOUT int8_t i2ssdPin = 32; @@ -1163,6 +1163,7 @@ class AudioReactive : public Usermod { oappend(SET_F("addOption(dd,'Normal',1);")); oappend(SET_F("addOption(dd,'Vivid',2);")); oappend(SET_F("addOption(dd,'Lazy',3);")); + oappend(SET_F("addInfo('AudioReactive:digitalmic:type',1,'requires reboot!');")); // 0 is field type, 1 is actual field oappend(SET_F("addInfo('AudioReactive:digitalmic:pin[]',0,'I2S SD');")); oappend(SET_F("addInfo('AudioReactive:digitalmic:pin[]',1,'I2S WS');")); oappend(SET_F("addInfo('AudioReactive:digitalmic:pin[]',2,'I2S SCK');")); diff --git a/usermods/usermod_v2_rotary_encoder_ui_ALT/usermod_v2_rotary_encoder_ui_ALT.h b/usermods/usermod_v2_rotary_encoder_ui_ALT/usermod_v2_rotary_encoder_ui_ALT.h index d1998a9f..34cace3c 100644 --- a/usermods/usermod_v2_rotary_encoder_ui_ALT/usermod_v2_rotary_encoder_ui_ALT.h +++ b/usermods/usermod_v2_rotary_encoder_ui_ALT/usermod_v2_rotary_encoder_ui_ALT.h @@ -186,7 +186,7 @@ private: */ void sortModesAndPalettes() { //modes_qstrings = re_findModeStrings(JSON_mode_names, strip.getModeCount()); - modes_qstrings = WS2812FX::_modeData; + modes_qstrings = strip.getModeDataSrc(); modes_alpha_indexes = re_initIndexArray(strip.getModeCount()); re_sortModes(modes_qstrings, modes_alpha_indexes, strip.getModeCount(), MODE_SORT_SKIP_COUNT); diff --git a/wled00/FX.cpp b/wled00/FX.cpp index 6ae565bd..d963e37c 100644 --- a/wled00/FX.cpp +++ b/wled00/FX.cpp @@ -5946,6 +5946,8 @@ static const char *_data_FX_MODE_DRIFT_ROSE PROGMEM = "2D Drift Rose@Fade,Blur;; /////////////////////////////////////////////////////////////////////////////// /******************** audio enhanced routines ************************/ /////////////////////////////////////////////////////////////////////////////// + + /* use the following code to pass AudioReactive usermod variables to effect uint8_t *binNum = (uint8_t*)&SEGENV.aux1, *maxVol = (uint8_t*)(&SEGENV.aux1+1); // just in case assignment @@ -6615,32 +6617,6 @@ uint16_t WS2812FX::mode_noisemeter(void) { // Noisemeter. By Andr static const char *_data_FX_MODE_NOISEMETER PROGMEM = " ♪ Noisemeter@Fade rate,Width=128;!,!;!"; -////////////////////// -// * PIXELS // -////////////////////// -uint16_t WS2812FX::mode_pixels(void) { // Pixels. By Andrew Tuline. - - um_data_t *um_data; - uint16_t *myVals = nullptr; - float sampleAgc = 0.0f; - if (usermods.getUMData(&um_data, USERMOD_ID_AUDIOREACTIVE)) { - sampleAgc = *(float*)um_data->u_data[2]; - myVals = (uint16_t*)um_data->u_data[14]; - } - if (!myVals) return mode_static(); - - fade_out(SEGMENT.speed); - - for (uint16_t i=0; i >16), byte(c>>8), byte(c), byte(c>>24));} inline void setPixelColor(uint16_t n, CRGB c) {setPixelColor(n, c.red, c.green, c.blue);} inline void setPixelColor(float i, uint32_t c, bool aa) {setPixelColor(i, byte(c>>16), byte(c>>8), byte(c), byte(c>>24), aa);} @@ -844,6 +925,12 @@ class WS2812FX { getLastShow(void), getPixelColor(uint16_t); + const char * + getModeData(uint8_t id = 0) { return id= 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; + //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 = 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 = 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/json.cpp b/wled00/json.cpp index 7cd09671..725a6f81 100644 --- a/wled00/json.cpp +++ b/wled00/json.cpp @@ -831,7 +831,7 @@ void serializeModeData(JsonArray fxdata) { for (size_t i = 0; i < MODE_COUNT; i++) { //String lineBuffer = (const char*)pgm_read_dword(&(WS2812FX::_modeData[i])); - String lineBuffer = WS2812FX::_modeData[i]; + String lineBuffer = strip.getModeData(i); if (lineBuffer.length() > 0) { uint8_t endPos = lineBuffer.indexOf('@'); if (endPos>0) fxdata.add(lineBuffer.substring(endPos)); @@ -845,10 +845,10 @@ void serializeModeData(JsonArray fxdata) void serializeModeNames(JsonArray arr) { for (size_t i = 0; i < MODE_COUNT; i++) { //String lineBuffer = (const char*)pgm_read_dword(&(WS2812FX::_modeData[i])); - String lineBuffer = WS2812FX::_modeData[i]; + String lineBuffer = strip.getModeData(i); if (lineBuffer.length() > 0) { uint8_t endPos = lineBuffer.indexOf('@'); - if (endPos>0) arr.add(lineBuffer.substring(0,endPos)); + if (endPos>0) arr.add(lineBuffer.substring(0, endPos)); else arr.add(lineBuffer); } } diff --git a/wled00/util.cpp b/wled00/util.cpp index 8b132672..80ca9267 100644 --- a/wled00/util.cpp +++ b/wled00/util.cpp @@ -237,7 +237,7 @@ uint8_t extractModeName(uint8_t mode, const char *src, char *dest, uint8_t maxLe if (mode < MODE_COUNT) { char lineBuffer[256]; //strcpy_P(lineBuffer, (const char*)pgm_read_dword(&(WS2812FX::_modeData[mode]))); - strcpy_P(lineBuffer, WS2812FX::_modeData[mode]); + strcpy_P(lineBuffer, strip.getModeData(mode)); if (strlen(lineBuffer) > 0) { size_t j = 0; for (; j < maxLen; j++) { @@ -287,7 +287,7 @@ uint8_t extractModeSlider(uint8_t mode, uint8_t slider, char *dest, uint8_t maxL dest[0] = '\0'; // start by clearing buffer if (mode < MODE_COUNT) { - String lineBuffer = WS2812FX::_modeData[mode]; + String lineBuffer = strip.getModeData(mode); if (lineBuffer.length() > 0) { int16_t start = lineBuffer.indexOf('@'); int16_t stop = lineBuffer.indexOf(';', start);