From 7fe0123c637650eb3bc4deeff738ea4bd81c033c Mon Sep 17 00:00:00 2001 From: tonyxforce Date: Wed, 23 Aug 2023 18:13:15 +0200 Subject: [PATCH 01/17] modified: wled00/FX.cpp modified: wled00/FX.h --- wled00/FX.cpp | 91 +++++++++++++++++++++++++++++++++++++++++++++++++++ wled00/FX.h | 4 ++- 2 files changed, 94 insertions(+), 1 deletion(-) diff --git a/wled00/FX.cpp b/wled00/FX.cpp index dc92c216..47545c5a 100644 --- a/wled00/FX.cpp +++ b/wled00/FX.cpp @@ -1915,6 +1915,96 @@ uint16_t mode_pride_2015(void) { } static const char _data_FX_MODE_PRIDE_2015[] PROGMEM = "Pride 2015@!;;"; +////////////////////// +// JBL // +////////////////////// + + +uint16_t pos = 0; +uint8_t hue = 0; +int hueDelay = 0; + +uint8_t red(uint32_t c) +{ + return (c >> 16); +} +uint8_t green(uint32_t c) +{ + return (c >> 8); +} +uint8_t blue(uint32_t c) +{ + return (c); +} + +uint16_t mode_jbl() +{ + + um_data_t *um_data; + if (!usermods.getUMData(&um_data, USERMOD_ID_AUDIOREACTIVE)) { + // add support for no audio + um_data = simulateSound(SEGMENT.soundSim); + } + uint8_t samplePeak = *(uint8_t*)um_data->u_data[3]; + uint8_t *maxVol = (uint8_t*)um_data->u_data[6]; + uint8_t *binNum = (uint8_t*)um_data->u_data[7]; + float volumeSmth = *(float*) um_data->u_data[0]; + + + + + hueDelay++; + + if (hue > 254) + { + hue = 0; + } + + if (hueDelay > SEGMENT.custom1) + { + hueDelay = 0; + hue++; + } + + float speed = 0; + + uint16_t counter = 0; + + if (volumeSmth * SEGMENT.intensity > (255 - SEGMENT.speed)) + { + speed = 1000; + } + else + { + speed = 20; + }; + + pos += speed; + + counter = pos; + counter = counter >> 8; + + for (uint16_t i = 0; i < SEGLEN; i++) + { + uint8_t colorIndex = (i * 255 / SEGLEN) - counter; + + uint32_t paletteColor = SEGMENT.color_from_palette(colorIndex, false, true, 255); + + uint8_t r = red(paletteColor); + uint8_t g = green(paletteColor); + uint8_t b = blue(paletteColor); + + uint8_t activeColor = max(r, max(g, b)); + + CRGB rgb(CHSV(hue, 255, activeColor)); + + SEGMENT.setPixelColor(i, rgb.r, rgb.g, rgb.b); + }; + + return FRAMETIME; +} // mode_jbl() + +static const char _data_FX_MODE_JBL[] PROGMEM = "JBL@Sensitivity 1,Sensivity 2,Color change speed;!,!;!;1v;c1=8,c2=48,m12=0,si=0"; //eight colored dots, weaving in and out of sync with each other uint16_t mode_juggle(void) { @@ -8060,6 +8150,7 @@ void WS2812FX::setupEffectData() { // --- 1D audio effects --- addEffect(FX_MODE_PIXELS, &mode_pixels, _data_FX_MODE_PIXELS); addEffect(FX_MODE_PIXELWAVE, &mode_pixelwave, _data_FX_MODE_PIXELWAVE); + addEffect(FX_MODE_JBL, &mode_jbl, _data_FX_MODE_JBL); addEffect(FX_MODE_JUGGLES, &mode_juggles, _data_FX_MODE_JUGGLES); addEffect(FX_MODE_MATRIPIX, &mode_matripix, _data_FX_MODE_MATRIPIX); addEffect(FX_MODE_GRAVIMETER, &mode_gravimeter, _data_FX_MODE_GRAVIMETER); diff --git a/wled00/FX.h b/wled00/FX.h index 1175157e..c68c2694 100644 --- a/wled00/FX.h +++ b/wled00/FX.h @@ -335,7 +335,9 @@ void strip_wait_until_idle(String whoCalledMe); // WLEDMM implemented in FX_fcn. #define FX_MODE_2DAKEMI 186 #define FX_MODE_ARTIFX 187 //WLEDMM ARTIFX -#define MODE_COUNT 188 +#define FX_MODE_JBL 188 + +#define MODE_COUNT 189 typedef enum mapping1D2D { M12_Pixels = 0, From 05f5237971581d3ea9e9900e4061c8984d88488b Mon Sep 17 00:00:00 2001 From: tonyxforce Date: Wed, 23 Aug 2023 21:37:35 +0200 Subject: [PATCH 02/17] modified: wled00/FX.cpp --- wled00/FX.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/wled00/FX.cpp b/wled00/FX.cpp index 47545c5a..7bbd3e06 100644 --- a/wled00/FX.cpp +++ b/wled00/FX.cpp @@ -1960,7 +1960,7 @@ uint16_t mode_jbl() hue = 0; } - if (hueDelay > SEGMENT.custom1) + if (hueDelay > SEGMENT.speed) { hueDelay = 0; hue++; @@ -1970,7 +1970,7 @@ uint16_t mode_jbl() uint16_t counter = 0; - if (volumeSmth * SEGMENT.intensity > (255 - SEGMENT.speed)) + if (volumeSmth * 2 > (255 - SEGMENT.intensity)) { speed = 1000; } @@ -2004,7 +2004,7 @@ uint16_t mode_jbl() return FRAMETIME; } // mode_jbl() -static const char _data_FX_MODE_JBL[] PROGMEM = "JBL@Sensitivity 1,Sensivity 2,Color change speed;!,!;!;1v;c1=8,c2=48,m12=0,si=0"; +static const char _data_FX_MODE_JBL[] PROGMEM = "JBL@Sensitivity 1,Sensivity 2;!,!;!;1v;c1=8,c2=48,m12=0,si=0"; //eight colored dots, weaving in and out of sync with each other uint16_t mode_juggle(void) { From d64b6b3511de98daaf472de9409d81e4306f4f2c Mon Sep 17 00:00:00 2001 From: tonyxforce Date: Wed, 23 Aug 2023 21:46:35 +0200 Subject: [PATCH 03/17] fixed slider names --- wled00/FX.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wled00/FX.cpp b/wled00/FX.cpp index 7bbd3e06..c7216be3 100644 --- a/wled00/FX.cpp +++ b/wled00/FX.cpp @@ -2004,7 +2004,7 @@ uint16_t mode_jbl() return FRAMETIME; } // mode_jbl() -static const char _data_FX_MODE_JBL[] PROGMEM = "JBL@Sensitivity 1,Sensivity 2;!,!;!;1v;c1=8,c2=48,m12=0,si=0"; +static const char _data_FX_MODE_JBL[] PROGMEM = "JBL@Color change speed,Sensivity;!,!;!;1v;c1=8,c2=48,m12=0,si=0"; //eight colored dots, weaving in and out of sync with each other uint16_t mode_juggle(void) { From 1d61351903b8344f895254cdaada36c37e2690b7 Mon Sep 17 00:00:00 2001 From: tonyxforce Date: Thu, 24 Aug 2023 20:19:41 +0200 Subject: [PATCH 04/17] Code improvement changes --- wled00/FX.cpp | 70 +++++++++++++++++++-------------------------------- 1 file changed, 26 insertions(+), 44 deletions(-) diff --git a/wled00/FX.cpp b/wled00/FX.cpp index c7216be3..5811e687 100644 --- a/wled00/FX.cpp +++ b/wled00/FX.cpp @@ -1920,25 +1920,16 @@ static const char _data_FX_MODE_PRIDE_2015[] PROGMEM = "Pride 2015@!;;"; ////////////////////// -uint16_t pos = 0; -uint8_t hue = 0; -int hueDelay = 0; -uint8_t red(uint32_t c) -{ - return (c >> 16); -} -uint8_t green(uint32_t c) -{ - return (c >> 8); -} -uint8_t blue(uint32_t c) -{ - return (c); -} +uint16_t mode_jbl() { -uint16_t mode_jbl() -{ + static uint16_t mode_jbl_pos = 0; + + /* + * use of persistent variables: + * aux0: hueDelay + * aux1: hue + */ um_data_t *um_data; if (!usermods.getUMData(&um_data, USERMOD_ID_AUDIOREACTIVE)) { @@ -1950,53 +1941,44 @@ uint16_t mode_jbl() uint8_t *binNum = (uint8_t*)um_data->u_data[7]; float volumeSmth = *(float*) um_data->u_data[0]; + SEGENV.aux0++; - - - hueDelay++; - - if (hue > 254) - { - hue = 0; + if (SEGENV.aux1 > 254) { + SEGENV.aux1 = 0; } - if (hueDelay > SEGMENT.speed) - { - hueDelay = 0; - hue++; + if (SEGENV.aux0 > SEGMENT.speed) { + SEGENV.aux1 = 0; + SEGENV.aux0++; } - float speed = 0; + uint_fast32_t speed = 0; uint16_t counter = 0; - if (volumeSmth * 2 > (255 - SEGMENT.intensity)) - { + if (volumeSmth * 2 > (255 - SEGMENT.intensity)) { speed = 1000; - } - else - { + } else { speed = 20; }; - pos += speed; + mode_jbl_pos += speed; - counter = pos; - counter = counter >> 8; + counter = mode_jbl_pos >> 8; + + for (uint16_t i = 0; i < SEGLEN; i++) { - for (uint16_t i = 0; i < SEGLEN; i++) - { uint8_t colorIndex = (i * 255 / SEGLEN) - counter; uint32_t paletteColor = SEGMENT.color_from_palette(colorIndex, false, true, 255); - uint8_t r = red(paletteColor); - uint8_t g = green(paletteColor); - uint8_t b = blue(paletteColor); + uint8_t r = R(paletteColor); + uint8_t g = G(paletteColor); + uint8_t b = B(paletteColor); uint8_t activeColor = max(r, max(g, b)); - CRGB rgb(CHSV(hue, 255, activeColor)); + CRGB rgb(CHSV(SEGENV.aux1, 255, activeColor)); SEGMENT.setPixelColor(i, rgb.r, rgb.g, rgb.b); }; @@ -2031,7 +2013,7 @@ static const char _data_FX_MODE_JUGGLE[] PROGMEM = "Juggle@!,Trail;;!;;sx=64,ix= uint16_t mode_palette() { - uint16_t counter = 0; + uint16_t counter = 0; if (SEGMENT.speed != 0) { counter = (strip.now * ((SEGMENT.speed >> 3) +1)) & 0xFFFF; From 7f0191bd118b7a1fae6b130e87475095f4cd7e30 Mon Sep 17 00:00:00 2001 From: tonyxforce Date: Thu, 24 Aug 2023 23:47:57 +0200 Subject: [PATCH 05/17] Minor code modifications/clean up --- wled00/FX.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/wled00/FX.cpp b/wled00/FX.cpp index 5811e687..1e74b4c7 100644 --- a/wled00/FX.cpp +++ b/wled00/FX.cpp @@ -1923,12 +1923,18 @@ static const char _data_FX_MODE_PRIDE_2015[] PROGMEM = "Pride 2015@!;;"; uint16_t mode_jbl() { - static uint16_t mode_jbl_pos = 0; - + if (SEGENV.call == 0) { + SEGMENT.fill(BLACK); // clear LEDs + SEGENV.aux0 = 0; + SEGENV.aux1 = 0; + SEGENV.step = 0; + } + /* * use of persistent variables: * aux0: hueDelay * aux1: hue + * step: pos */ um_data_t *um_data; @@ -1962,9 +1968,9 @@ uint16_t mode_jbl() { speed = 20; }; - mode_jbl_pos += speed; + SEGENV.step += speed; - counter = mode_jbl_pos >> 8; + counter = SEGENV.step >> 8; for (uint16_t i = 0; i < SEGLEN; i++) { From 350e20544dfb6b40c750e898ed6174664727660b Mon Sep 17 00:00:00 2001 From: tonyxforce Date: Fri, 25 Aug 2023 00:04:05 +0200 Subject: [PATCH 06/17] Fixing effect speed issues --- .vscode/extensions.json | 10 ---------- wled00/FX.cpp | 8 ++++---- 2 files changed, 4 insertions(+), 14 deletions(-) delete mode 100644 .vscode/extensions.json diff --git a/.vscode/extensions.json b/.vscode/extensions.json deleted file mode 100644 index 080e70d0..00000000 --- a/.vscode/extensions.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - // See http://go.microsoft.com/fwlink/?LinkId=827846 - // for the documentation about the extensions.json format - "recommendations": [ - "platformio.platformio-ide" - ], - "unwantedRecommendations": [ - "ms-vscode.cpptools-extension-pack" - ] -} diff --git a/wled00/FX.cpp b/wled00/FX.cpp index 1e74b4c7..757e618b 100644 --- a/wled00/FX.cpp +++ b/wled00/FX.cpp @@ -1953,7 +1953,7 @@ uint16_t mode_jbl() { SEGENV.aux1 = 0; } - if (SEGENV.aux0 > SEGMENT.speed) { + if (SEGENV.aux0 > SEGMENT.custom1) { SEGENV.aux1 = 0; SEGENV.aux0++; } @@ -1963,9 +1963,9 @@ uint16_t mode_jbl() { uint16_t counter = 0; if (volumeSmth * 2 > (255 - SEGMENT.intensity)) { - speed = 1000; + speed = SEGMENT.speed * 50; } else { - speed = 20; + speed = SEGMENT.speed; }; SEGENV.step += speed; @@ -1992,7 +1992,7 @@ uint16_t mode_jbl() { return FRAMETIME; } // mode_jbl() -static const char _data_FX_MODE_JBL[] PROGMEM = "JBL@Color change speed,Sensivity;!,!;!;1v;c1=8,c2=48,m12=0,si=0"; +static const char _data_FX_MODE_JBL[] PROGMEM = "JBL@Effect speed,Sensivity,Color change speed;!,!;!;1v;c1=8,c2=48,m12=0,si=0"; //eight colored dots, weaving in and out of sync with each other uint16_t mode_juggle(void) { From 3499c38fed243409a1840adf156230a8b8f94e74 Mon Sep 17 00:00:00 2001 From: tonyxforce <77063724+tonyxforce@users.noreply.github.com> Date: Fri, 25 Aug 2023 01:03:14 +0200 Subject: [PATCH 07/17] Fix deleted file --- .vscode/extensions.json | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 .vscode/extensions.json diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 00000000..080e70d0 --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,10 @@ +{ + // See http://go.microsoft.com/fwlink/?LinkId=827846 + // for the documentation about the extensions.json format + "recommendations": [ + "platformio.platformio-ide" + ], + "unwantedRecommendations": [ + "ms-vscode.cpptools-extension-pack" + ] +} From 6a37f814653b820d0be254455273198cdf068db6 Mon Sep 17 00:00:00 2001 From: tonyxforce Date: Fri, 25 Aug 2023 01:03:40 +0200 Subject: [PATCH 08/17] Renamed the effect, biased the sliders, so it looks best with all sliders in the middle, added option to change the effect speed multiplier --- wled00/FX.cpp | 18 +++++++++--------- wled00/FX.h | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/wled00/FX.cpp b/wled00/FX.cpp index 757e618b..737e97ee 100644 --- a/wled00/FX.cpp +++ b/wled00/FX.cpp @@ -1916,12 +1916,12 @@ uint16_t mode_pride_2015(void) { static const char _data_FX_MODE_PRIDE_2015[] PROGMEM = "Pride 2015@!;;"; ////////////////////// -// JBL // +// PARTYBOX // ////////////////////// -uint16_t mode_jbl() { +uint16_t mode_partybox() { if (SEGENV.call == 0) { SEGMENT.fill(BLACK); // clear LEDs @@ -1953,9 +1953,9 @@ uint16_t mode_jbl() { SEGENV.aux1 = 0; } - if (SEGENV.aux0 > SEGMENT.custom1) { - SEGENV.aux1 = 0; - SEGENV.aux0++; + if (SEGENV.aux0 > map(255-SEGMENT.custom1, 0, 255, 0, 140)) { + SEGENV.aux0 = 0; + SEGENV.aux1++; } uint_fast32_t speed = 0; @@ -1963,7 +1963,7 @@ uint16_t mode_jbl() { uint16_t counter = 0; if (volumeSmth * 2 > (255 - SEGMENT.intensity)) { - speed = SEGMENT.speed * 50; + speed = SEGMENT.speed * map(SEGMENT.custom2, 0, 255, 0, 100); } else { speed = SEGMENT.speed; }; @@ -1990,9 +1990,9 @@ uint16_t mode_jbl() { }; return FRAMETIME; -} // mode_jbl() +} // mode_partybox() -static const char _data_FX_MODE_JBL[] PROGMEM = "JBL@Effect speed,Sensivity,Color change speed;!,!;!;1v;c1=8,c2=48,m12=0,si=0"; +static const char _data_FX_MODE_PARTYBOX[] PROGMEM = "partybox@Effect speed,Sensivity,Color change speed,Effect speed active multiplier;!,!;!;1v;c1=8,c2=48,m12=0,si=0"; //eight colored dots, weaving in and out of sync with each other uint16_t mode_juggle(void) { @@ -8138,7 +8138,7 @@ void WS2812FX::setupEffectData() { // --- 1D audio effects --- addEffect(FX_MODE_PIXELS, &mode_pixels, _data_FX_MODE_PIXELS); addEffect(FX_MODE_PIXELWAVE, &mode_pixelwave, _data_FX_MODE_PIXELWAVE); - addEffect(FX_MODE_JBL, &mode_jbl, _data_FX_MODE_JBL); + addEffect(FX_MODE_PARTYBOX, &mode_partybox, _data_FX_MODE_PARTYBOX); addEffect(FX_MODE_JUGGLES, &mode_juggles, _data_FX_MODE_JUGGLES); addEffect(FX_MODE_MATRIPIX, &mode_matripix, _data_FX_MODE_MATRIPIX); addEffect(FX_MODE_GRAVIMETER, &mode_gravimeter, _data_FX_MODE_GRAVIMETER); diff --git a/wled00/FX.h b/wled00/FX.h index c68c2694..c9de50cd 100644 --- a/wled00/FX.h +++ b/wled00/FX.h @@ -335,7 +335,7 @@ void strip_wait_until_idle(String whoCalledMe); // WLEDMM implemented in FX_fcn. #define FX_MODE_2DAKEMI 186 #define FX_MODE_ARTIFX 187 //WLEDMM ARTIFX -#define FX_MODE_JBL 188 +#define FX_MODE_PARTYBOX 188 #define MODE_COUNT 189 From e5ca80c035aa58ab4d067bb0770dcfc5fc951221 Mon Sep 17 00:00:00 2001 From: tonyxforce Date: Fri, 25 Aug 2023 01:18:05 +0200 Subject: [PATCH 09/17] Bias value changes --- wled00/FX.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wled00/FX.cpp b/wled00/FX.cpp index 737e97ee..aef9f69b 100644 --- a/wled00/FX.cpp +++ b/wled00/FX.cpp @@ -1953,7 +1953,7 @@ uint16_t mode_partybox() { SEGENV.aux1 = 0; } - if (SEGENV.aux0 > map(255-SEGMENT.custom1, 0, 255, 0, 140)) { + if (SEGENV.aux0 > map(SEGMENT.custom1, 0, 255, 0, 14)) { SEGENV.aux0 = 0; SEGENV.aux1++; } From c07a8ae263eb451ceaf36139bc60ad4e7384ba03 Mon Sep 17 00:00:00 2001 From: tonyxforce Date: Fri, 25 Aug 2023 20:26:16 +0200 Subject: [PATCH 10/17] Fixed possible naming legal issues --- wled00/FX.cpp | 10 +++++----- wled00/FX.h | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/wled00/FX.cpp b/wled00/FX.cpp index aef9f69b..96a2726d 100644 --- a/wled00/FX.cpp +++ b/wled00/FX.cpp @@ -1916,12 +1916,12 @@ uint16_t mode_pride_2015(void) { static const char _data_FX_MODE_PRIDE_2015[] PROGMEM = "Pride 2015@!;;"; ////////////////////// -// PARTYBOX // +// PARTYJERK // ////////////////////// -uint16_t mode_partybox() { +uint16_t mode_partyjerk() { if (SEGENV.call == 0) { SEGMENT.fill(BLACK); // clear LEDs @@ -1990,9 +1990,9 @@ uint16_t mode_partybox() { }; return FRAMETIME; -} // mode_partybox() +} // mode_partyjerk() -static const char _data_FX_MODE_PARTYBOX[] PROGMEM = "partybox@Effect speed,Sensivity,Color change speed,Effect speed active multiplier;!,!;!;1v;c1=8,c2=48,m12=0,si=0"; +static const char _data_FX_MODE_PARTYJERK[] PROGMEM = "Party jerk@Effect speed,Sensivity,Color change speed,Effect speed active multiplier;!,!;!;1v;c1=8,c2=48,m12=0,si=0"; //eight colored dots, weaving in and out of sync with each other uint16_t mode_juggle(void) { @@ -8138,7 +8138,7 @@ void WS2812FX::setupEffectData() { // --- 1D audio effects --- addEffect(FX_MODE_PIXELS, &mode_pixels, _data_FX_MODE_PIXELS); addEffect(FX_MODE_PIXELWAVE, &mode_pixelwave, _data_FX_MODE_PIXELWAVE); - addEffect(FX_MODE_PARTYBOX, &mode_partybox, _data_FX_MODE_PARTYBOX); + addEffect(FX_MODE_PARTYJERK, &mode_partyjerk, _data_FX_MODE_PARTYJERK); addEffect(FX_MODE_JUGGLES, &mode_juggles, _data_FX_MODE_JUGGLES); addEffect(FX_MODE_MATRIPIX, &mode_matripix, _data_FX_MODE_MATRIPIX); addEffect(FX_MODE_GRAVIMETER, &mode_gravimeter, _data_FX_MODE_GRAVIMETER); diff --git a/wled00/FX.h b/wled00/FX.h index c9de50cd..ff9ee811 100644 --- a/wled00/FX.h +++ b/wled00/FX.h @@ -335,7 +335,7 @@ void strip_wait_until_idle(String whoCalledMe); // WLEDMM implemented in FX_fcn. #define FX_MODE_2DAKEMI 186 #define FX_MODE_ARTIFX 187 //WLEDMM ARTIFX -#define FX_MODE_PARTYBOX 188 +#define FX_MODE_PARTYJERK 188 #define MODE_COUNT 189 From e14d5e6975681c56b33944e33a798dd80b32bdab Mon Sep 17 00:00:00 2001 From: Frank Date: Tue, 5 Dec 2023 21:30:29 +0100 Subject: [PATCH 11/17] sound sync: replace magic numbers with constants --- usermods/audioreactive/audio_reactive.h | 47 +++++++++++++++---------- 1 file changed, 28 insertions(+), 19 deletions(-) diff --git a/usermods/audioreactive/audio_reactive.h b/usermods/audioreactive/audio_reactive.h index cfce06fd..72ab6c47 100644 --- a/usermods/audioreactive/audio_reactive.h +++ b/usermods/audioreactive/audio_reactive.h @@ -91,8 +91,14 @@ #define PLOT_FLUSH() #endif +// audiosync modes +#define AUDIOSYNC_NONE 0x00 // UDP sound sync off +#define AUDIOSYNC_SEND 0x01 // UDP sound sync - send mode +#define AUDIOSYNC_REC 0x02 // UDP sound sync - receiver mode +#define AUDIOSYNC_REC_PLUS 0x06 // UDP sound sync - receiver + local mode (uses local input if no receiving udp sound) + static volatile bool disableSoundProcessing = false; // if true, sound processing (FFT, filters, AGC) will be suspended. "volatile" as its shared between tasks. -static uint8_t audioSyncEnabled = 0; // bit field: bit 0 - send, bit 1 - receive (config value) +static uint8_t audioSyncEnabled = AUDIOSYNC_NONE; // bit field: bit 0 - send, bit 1 - receive, bit 2 - use local if not receiving static bool udpSyncConnected = false; // UDP connection status -> true if connected to multicast group #define NUM_GEQ_CHANNELS 16 // number of frequency channels. Don't change !! @@ -116,7 +122,7 @@ static float FFT_Magnitude = 0.0f; // FFT: volume (magnitude) of pe static bool samplePeak = false; // Boolean flag for peak - used in effects. Responding routine may reset this flag. Auto-reset after strip.getMinShowDelay() static bool udpSamplePeak = false; // Boolean flag for peak. Set at the same time as samplePeak, but reset by transmitAudioData static unsigned long timeOfPeak = 0; // time of last sample peak detection. -volatile bool haveNewFFTResult = false; // flag to directly inform UDP sound sender when new FFT results are availeable (to reduce latency). Flag is reset at next UDP send +volatile bool haveNewFFTResult = false; // flag to directly inform UDP sound sender when new FFT results are available (to reduce latency). Flag is reset at next UDP send static uint8_t fftResult[NUM_GEQ_CHANNELS]= {0}; // Our calculated freq. channel result table to be used by effects static float fftCalc[NUM_GEQ_CHANNELS] = {0.0f}; // Try and normalize fftBin values to a max of 4096, so that 4096/16 = 256. (also used by dynamics limiter) @@ -449,7 +455,7 @@ void FFTcode(void * parameter) // taskYIELD(), yield(), vTaskDelay() and esp_task_wdt_feed() didn't seem to work. // Don't run FFT computing code if we're in Receive mode or in realtime mode - if (disableSoundProcessing || (audioSyncEnabled & 0x02)) { + if (disableSoundProcessing || (audioSyncEnabled == AUDIOSYNC_REC)) { isFirstRun = false; vTaskDelayUntil( &xLastWakeTime, xFrequency); // release CPU, and let I2S fill its buffers continue; @@ -1067,7 +1073,7 @@ class AudioReactive : public Usermod { //////////////////// void logAudio() { - if (disableSoundProcessing && (!udpSyncConnected || ((audioSyncEnabled & 0x02) == 0))) return; // no audio available + if (disableSoundProcessing && (!udpSyncConnected || ((audioSyncEnabled & AUDIOSYNC_REC) == 0))) return; // no audio available #ifdef MIC_LOGGER // Debugging functions for audio input and sound processing. Comment out the values you want to see PLOT_PRINT("volumeSmth:"); PLOT_PRINT(volumeSmth + 256.0f); PLOT_PRINT("\t"); // +256 to move above other lines @@ -1961,8 +1967,8 @@ class AudioReactive : public Usermod { disableSoundProcessing = false; } - if (audioSyncEnabled & 0x02) disableSoundProcessing = true; // make sure everything is disabled IF in audio Receive mode - if (audioSyncEnabled & 0x01) disableSoundProcessing = false; // keep running audio IF we're in audio Transmit mode + if (audioSyncEnabled == AUDIOSYNC_REC) disableSoundProcessing = true; // make sure everything is disabled IF in audio Receive mode + if (audioSyncEnabled & AUDIOSYNC_SEND) disableSoundProcessing = false; // keep running audio IF we're in audio Transmit mode #ifdef ARDUINO_ARCH_ESP32 if (!audioSource->isInitialized()) disableSoundProcessing = true; // no audio source @@ -1977,7 +1983,7 @@ class AudioReactive : public Usermod { #endif // Only run the sampling code IF we're not in Receive mode or realtime mode - if (!(audioSyncEnabled & 0x02) && !disableSoundProcessing) { + if (!(audioSyncEnabled & AUDIOSYNC_REC) && !disableSoundProcessing) { if (soundAgc > AGC_NUM_PRESETS) soundAgc = 0; // make sure that AGC preset is valid (to avoid array bounds violation) unsigned long t_now = millis(); // remember current time @@ -2034,7 +2040,7 @@ class AudioReactive : public Usermod { connectUDPSoundSync(); // ensure we have a connection - if needed // UDP Microphone Sync - receive mode - if ((audioSyncEnabled & 0x02) && udpSyncConnected) { + if ((audioSyncEnabled & AUDIOSYNC_REC) && udpSyncConnected) { // Only run the audio listener code if we're in Receive mode static float syncVolumeSmth = 0; bool have_new_sample = false; @@ -2055,7 +2061,7 @@ class AudioReactive : public Usermod { receivedFormat = 0; } - if ( (audioSyncEnabled & 0x02) // receive mode + if ( (audioSyncEnabled & AUDIOSYNC_REC) // receive mode && udpSyncConnected // connected && (receivedFormat > 0) // we actually received something in the past && ((millis() - last_UDPTime) > 25000)) { // close connection after 25sec idle @@ -2102,9 +2108,9 @@ class AudioReactive : public Usermod { #ifdef ARDUINO_ARCH_ESP32 //UDP Microphone Sync - transmit mode #if defined(WLEDMM_FASTPATH) - if ((audioSyncEnabled & 0x01) && (haveNewFFTResult || (millis() - lastTime > 24))) { // fastpath: send data once results are ready, or each 25ms as fallback (max sampling time is 23ms) + if ((audioSyncEnabled & AUDIOSYNC_SEND) && (haveNewFFTResult || (millis() - lastTime > 24))) { // fastpath: send data once results are ready, or each 25ms as fallback (max sampling time is 23ms) #else - if ((audioSyncEnabled & 0x01) && (millis() - lastTime > 20)) { // standard: send data each 20ms + if ((audioSyncEnabled & AUDIOSYNC_SEND) && (millis() - lastTime > 20)) { // standard: send data each 20ms #endif haveNewFFTResult = false; // reset notification // Only run the transmit code IF we're in Transmit mode @@ -2283,7 +2289,7 @@ class AudioReactive : public Usermod { // The following can be used for troubleshooting user errors and is so not enclosed in #ifdef WLED_DEBUG // current Audio input infoArr = user.createNestedArray(F("Audio Source")); - if (audioSyncEnabled & 0x02) { + if (audioSyncEnabled & AUDIOSYNC_REC) { // UDP sound sync - receive mode infoArr.add(F("UDP sound sync")); if (udpSyncConnected) { @@ -2335,13 +2341,13 @@ class AudioReactive : public Usermod { } // AGC or manual Gain - if ((soundAgc==0) && (disableSoundProcessing == false) && !(audioSyncEnabled & 0x02)) { + if ((soundAgc==0) && (disableSoundProcessing == false) && !(audioSyncEnabled & AUDIOSYNC_REC)) { infoArr = user.createNestedArray(F("Manual Gain")); float myGain = ((float)sampleGain/40.0f * (float)inputLevel/128.0f) + 1.0f/16.0f; // non-AGC gain from presets infoArr.add(roundf(myGain*100.0f) / 100.0f); infoArr.add("x"); } - if (soundAgc && (disableSoundProcessing == false) && !(audioSyncEnabled & 0x02)) { + if (soundAgc && (disableSoundProcessing == false) && !(audioSyncEnabled & AUDIOSYNC_REC)) { infoArr = user.createNestedArray(F("AGC Gain")); infoArr.add(roundf(multAgc*100.0f) / 100.0f); infoArr.add("x"); @@ -2350,10 +2356,10 @@ class AudioReactive : public Usermod { // UDP Sound Sync status infoArr = user.createNestedArray(F("UDP Sound Sync")); if (audioSyncEnabled) { - if (audioSyncEnabled & 0x01) { + if (audioSyncEnabled & AUDIOSYNC_SEND) { infoArr.add(F("send mode")); if ((udpSyncConnected) && (millis() - lastTime < 2500)) infoArr.add(F(" v2")); - } else if (audioSyncEnabled & 0x02) { + } else if (audioSyncEnabled & AUDIOSYNC_REC) { infoArr.add(F("receive mode")); } } else @@ -2751,11 +2757,14 @@ class AudioReactive : public Usermod { oappend(SET_F("addInfo('AudioReactive:frequency:profile',1,'☾');")); #endif oappend(SET_F("dd=addDropdown('AudioReactive','sync:mode');")); - oappend(SET_F("addOption(dd,'Off',0);")); + oappend(SET_F("addOption(dd,'Off',0);")); // AUDIOSYNC_NONE #ifdef ARDUINO_ARCH_ESP32 - oappend(SET_F("addOption(dd,'Send',1);")); + oappend(SET_F("addOption(dd,'Send',1);")); // AUDIOSYNC_SEND +#endif + oappend(SET_F("addOption(dd,'Receive',2);")); // AUDIOSYNC_REC +#ifdef ARDUINO_ARCH_ESP32 + oappend(SET_F("addOption(dd,'Receive or Local',6);")); // AUDIOSYNC_REC_PLUS #endif - oappend(SET_F("addOption(dd,'Receive',2);")); oappend(SET_F("addInfo('AudioReactive:sync:mode',1,'
Sync audio data with other WLEDs');")); oappend(SET_F("addInfo('AudioReactive:digitalmic:type',1,'requires reboot!');")); // 0 is field type, 1 is actual field From d2fc1f7bf9c3b6d4ebaf9736ed96e4b733b371a8 Mon Sep 17 00:00:00 2001 From: Frank Date: Tue, 5 Dec 2023 23:46:01 +0100 Subject: [PATCH 12/17] experimental: Souns Sync "receive or local" mode new "Receive or Local" mode: if UDP sound is missing or interrupted for too long, switch back to local audio input. UDP sound resumes when a fresh packet is received again. --> still needs testing, and even more regression testing. --- usermods/audioreactive/audio_reactive.h | 82 +++++++++++++++++-------- wled00/wled.h | 2 +- 2 files changed, 58 insertions(+), 26 deletions(-) diff --git a/usermods/audioreactive/audio_reactive.h b/usermods/audioreactive/audio_reactive.h index 72ab6c47..acef3adc 100644 --- a/usermods/audioreactive/audio_reactive.h +++ b/usermods/audioreactive/audio_reactive.h @@ -91,11 +91,12 @@ #define PLOT_FLUSH() #endif -// audiosync modes -#define AUDIOSYNC_NONE 0x00 // UDP sound sync off -#define AUDIOSYNC_SEND 0x01 // UDP sound sync - send mode -#define AUDIOSYNC_REC 0x02 // UDP sound sync - receiver mode -#define AUDIOSYNC_REC_PLUS 0x06 // UDP sound sync - receiver + local mode (uses local input if no receiving udp sound) +// audiosync constants +#define AUDIOSYNC_NONE 0x00 // UDP sound sync off +#define AUDIOSYNC_SEND 0x01 // UDP sound sync - send mode +#define AUDIOSYNC_REC 0x02 // UDP sound sync - receiver mode +#define AUDIOSYNC_REC_PLUS 0x06 // UDP sound sync - receiver + local mode (uses local input if no receiving udp sound) +#define AUDIOSYNC_IDLE_MS 2500 // timeout for "receiver idle" (milliseconds) static volatile bool disableSoundProcessing = false; // if true, sound processing (FFT, filters, AGC) will be suspended. "volatile" as its shared between tasks. static uint8_t audioSyncEnabled = AUDIOSYNC_NONE; // bit field: bit 0 - send, bit 1 - receive, bit 2 - use local if not receiving @@ -925,7 +926,7 @@ static void autoResetPeak(void) { uint16_t MinShowDelay = MAX(50, strip.getMinShowDelay()); // Fixes private class variable compiler error. Unsure if this is the correct way of fixing the root problem. -THATDONFC if (millis() - timeOfPeak > MinShowDelay) { // Auto-reset of samplePeak after a complete frame has passed. samplePeak = false; - if (audioSyncEnabled == 0) udpSamplePeak = false; // this is normally reset by transmitAudioData + if (audioSyncEnabled == AUDIOSYNC_NONE) udpSamplePeak = false; // this is normally reset by transmitAudioData } } @@ -1493,7 +1494,7 @@ class AudioReactive : public Usermod { // necessary as we also want to transmit in "AP Mode", but the standard "connected()" callback only reacts on STA connection static unsigned long last_connection_attempt = 0; - if ((audioSyncPort <= 0) || ((audioSyncEnabled & 0x03) == 0)) return; // Sound Sync not enabled + if ((audioSyncPort <= 0) || (audioSyncEnabled == AUDIOSYNC_NONE)) return; // Sound Sync not enabled if (!(apActive || WLED_CONNECTED || interfacesInited)) { if (udpSyncConnected) { udpSyncConnected = false; @@ -1898,7 +1899,7 @@ class AudioReactive : public Usermod { DEBUGSR_PRINTLN(F("AR connected(): old UDP connection closed.")); } - if (audioSyncPort > 0 && (audioSyncEnabled & 0x03)) { + if ((audioSyncPort > 0) && (audioSyncEnabled > AUDIOSYNC_NONE)) { #ifdef ARDUINO_ARCH_ESP32 udpSyncConnected = fftUdp.beginMulticast(IPAddress(239, 0, 0, 1), audioSyncPort); #else @@ -1941,6 +1942,17 @@ class AudioReactive : public Usermod { // We cannot wait indefinitely before processing audio data if (strip.isServicing() && (millis() - lastUMRun < 2)) return; // WLEDMM isServicing() is the critical part (be nice, but not too nice) + // sound sync "receive or local" + bool useNetworkAudio = false; + if (audioSyncEnabled > AUDIOSYNC_SEND) { // we are in "receive" or "receive+local" mode + if (udpSyncConnected && ((millis() - last_UDPTime) <= AUDIOSYNC_IDLE_MS)) + useNetworkAudio = true; + else + useNetworkAudio = false; + if (audioSyncEnabled == AUDIOSYNC_REC) + useNetworkAudio = true; // don't fall back to local audio in standard "receive mode" + } + // suspend local sound processing when "real time mode" is active (E131, UDP, ADALIGHT, ARTNET) if ( (realtimeOverride == REALTIME_OVERRIDE_NONE) // please add other overrides here if needed &&( (realtimeMode == REALTIME_MODE_GENERIC) @@ -1950,27 +1962,32 @@ class AudioReactive : public Usermod { ||(realtimeMode == REALTIME_MODE_ARTNET) ) ) // please add other modes here if needed { #ifdef WLED_DEBUG - if ((disableSoundProcessing == false) && (audioSyncEnabled == 0)) { // we just switched to "disabled" + if ((disableSoundProcessing == false) && (audioSyncEnabled < AUDIOSYNC_REC)) { // we just switched to "disabled" DEBUG_PRINTLN("[AR userLoop] realtime mode active - audio processing suspended."); DEBUG_PRINTF( " RealtimeMode = %d; RealtimeOverride = %d\n", int(realtimeMode), int(realtimeOverride)); } #endif disableSoundProcessing = true; + useNetworkAudio = false; } else { #if defined(ARDUINO_ARCH_ESP32) && defined(WLED_DEBUG) - if ((disableSoundProcessing == true) && (audioSyncEnabled == 0) && audioSource->isInitialized()) { // we just switched to "enabled" + if ((disableSoundProcessing == true) && (audioSyncEnabled < AUDIOSYNC_REC) && audioSource->isInitialized()) { // we just switched to "enabled" DEBUG_PRINTLN("[AR userLoop] realtime mode ended - audio processing resumed."); DEBUG_PRINTF( " RealtimeMode = %d; RealtimeOverride = %d\n", int(realtimeMode), int(realtimeOverride)); } #endif - if ((disableSoundProcessing == true) && (audioSyncEnabled == 0)) lastUMRun = millis(); // just left "realtime mode" - update timekeeping + if ((disableSoundProcessing == true) && (audioSyncEnabled < AUDIOSYNC_REC)) lastUMRun = millis(); // just left "realtime mode" - update timekeeping disableSoundProcessing = false; } - if (audioSyncEnabled == AUDIOSYNC_REC) disableSoundProcessing = true; // make sure everything is disabled IF in audio Receive mode + if (audioSyncEnabled == AUDIOSYNC_REC) disableSoundProcessing = true; // make sure everything is disabled IF in audio Receive mode if (audioSyncEnabled & AUDIOSYNC_SEND) disableSoundProcessing = false; // keep running audio IF we're in audio Transmit mode #ifdef ARDUINO_ARCH_ESP32 - if (!audioSource->isInitialized()) disableSoundProcessing = true; // no audio source + if (!audioSource->isInitialized()) { // no audio source + disableSoundProcessing = true; + if (audioSyncEnabled > AUDIOSYNC_SEND) useNetworkAudio = true; + } + if ((audioSyncEnabled == AUDIOSYNC_REC_PLUS) && useNetworkAudio) disableSoundProcessing = true; // UDP sound receiving - disable local audio #ifdef SR_DEBUG // debug info in case that task stack usage changes @@ -1983,7 +2000,7 @@ class AudioReactive : public Usermod { #endif // Only run the sampling code IF we're not in Receive mode or realtime mode - if (!(audioSyncEnabled & AUDIOSYNC_REC) && !disableSoundProcessing) { + if ((audioSyncEnabled != AUDIOSYNC_REC) && !disableSoundProcessing && !useNetworkAudio) { if (soundAgc > AGC_NUM_PRESETS) soundAgc = 0; // make sure that AGC preset is valid (to avoid array bounds violation) unsigned long t_now = millis(); // remember current time @@ -1993,7 +2010,7 @@ class AudioReactive : public Usermod { #if defined(SR_DEBUG) // complain when audio userloop has been delayed for long time. Currently we need userloop running between 500 and 1500 times per second. // softhack007 disabled temporarily - avoid serial console spam with MANY LEDs and low FPS - //if ((userloopDelay > /*23*/ 65) && !disableSoundProcessing && (audioSyncEnabled == 0)) { + //if ((userloopDelay > /*23*/ 65) && !disableSoundProcessing && (audioSyncEnabled == AUDIOSYNC_NONE)) { //DEBUG_PRINTF("[AR userLoop] hiccup detected -> was inactive for last %d millis!\n", userloopDelay); //} #endif @@ -2046,17 +2063,22 @@ class AudioReactive : public Usermod { bool have_new_sample = false; if (millis() - lastTime > delayMs) { have_new_sample = receiveAudioData(); - if (have_new_sample) last_UDPTime = millis(); + if (have_new_sample) { + last_UDPTime = millis(); + useNetworkAudio = true; // UDP input arrived - use it + } lastTime = millis(); } else { #ifdef ARDUINO_ARCH_ESP32 fftUdp.flush(); // WLEDMM: Flush this if we haven't read it. Does not work on 8266. #endif } - if (have_new_sample) syncVolumeSmth = volumeSmth; // remember received sample - else volumeSmth = syncVolumeSmth; // restore originally received sample for next run of dynamics limiter - limitSampleDynamics(); // run dynamics limiter on received volumeSmth, to hide jumps and hickups - limitGEQDynamics(have_new_sample); // WLEDMM experimental: smooth FFT (GEQ) samples + if (useNetworkAudio) { + if (have_new_sample) syncVolumeSmth = volumeSmth; // remember received sample + else volumeSmth = syncVolumeSmth; // restore originally received sample for next run of dynamics limiter + limitSampleDynamics(); // run dynamics limiter on received volumeSmth, to hide jumps and hickups + limitGEQDynamics(have_new_sample); // WLEDMM experimental: smooth FFT (GEQ) samples + } } else { receivedFormat = 0; } @@ -2262,7 +2284,15 @@ class AudioReactive : public Usermod { infoArr.add(uiDomString); if (enabled) { + bool audioSyncIDLE = false; // true if sound sync is not receiving + #ifdef ARDUINO_ARCH_ESP32 + // audio sync status + if ((audioSyncEnabled & AUDIOSYNC_REC) && (!udpSyncConnected || (millis() - last_UDPTime > AUDIOSYNC_IDLE_MS))) // connected and nothing received in 2.5sec + audioSyncIDLE = true; + if ((audioSource == nullptr) || (!audioSource->isInitialized())) // local audio not configured + audioSyncIDLE = false; + // Input Level Slider if (disableSoundProcessing == false) { // only show slider when audio processing is running if (soundAgc > 0) { @@ -2289,11 +2319,11 @@ class AudioReactive : public Usermod { // The following can be used for troubleshooting user errors and is so not enclosed in #ifdef WLED_DEBUG // current Audio input infoArr = user.createNestedArray(F("Audio Source")); - if (audioSyncEnabled & AUDIOSYNC_REC) { + if ((audioSyncEnabled == AUDIOSYNC_REC) || (!audioSyncIDLE && (audioSyncEnabled == AUDIOSYNC_REC_PLUS))){ // UDP sound sync - receive mode infoArr.add(F("UDP sound sync")); if (udpSyncConnected) { - if (millis() - last_UDPTime < 2500) + if (millis() - last_UDPTime < AUDIOSYNC_IDLE_MS) infoArr.add(F(" - receiving")); else infoArr.add(F(" - idle")); @@ -2358,14 +2388,16 @@ class AudioReactive : public Usermod { if (audioSyncEnabled) { if (audioSyncEnabled & AUDIOSYNC_SEND) { infoArr.add(F("send mode")); - if ((udpSyncConnected) && (millis() - lastTime < 2500)) infoArr.add(F(" v2")); - } else if (audioSyncEnabled & AUDIOSYNC_REC) { + if ((udpSyncConnected) && (millis() - lastTime < AUDIOSYNC_IDLE_MS)) infoArr.add(F(" v2")); + } else if (audioSyncEnabled == AUDIOSYNC_REC) { infoArr.add(F("receive mode")); + } else if (audioSyncEnabled == AUDIOSYNC_REC_PLUS) { + infoArr.add(F("receive+local mode")); } } else infoArr.add("off"); if (audioSyncEnabled && !udpSyncConnected) infoArr.add(" (unconnected)"); - if (audioSyncEnabled && udpSyncConnected && (millis() - last_UDPTime < 2500)) { + if (audioSyncEnabled && udpSyncConnected && (millis() - last_UDPTime < AUDIOSYNC_IDLE_MS)) { if (receivedFormat == 1) infoArr.add(F(" v1")); if (receivedFormat == 2) infoArr.add(F(" v2")); } diff --git a/wled00/wled.h b/wled00/wled.h index 3b0cffe6..032a3a4f 100644 --- a/wled00/wled.h +++ b/wled00/wled.h @@ -8,7 +8,7 @@ */ // version code in format yymmddb (b = daily build) -#define VERSION 2311290 +#define VERSION 2312050 //WLEDMM + Moustachauve/Wled-Native // You can define custom product info from build flags. From 6cd9d80dbe8c21ed392cc0c2c4243aa260f4e4c1 Mon Sep 17 00:00:00 2001 From: Frank <91616163+softhack007@users.noreply.github.com> Date: Wed, 6 Dec 2023 12:32:57 +0100 Subject: [PATCH 13/17] small fixie for audioreactive (info page) info page was not showing "AGC gain" when local mic was in use during "receive or local" mode. --- usermods/audioreactive/audio_reactive.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/usermods/audioreactive/audio_reactive.h b/usermods/audioreactive/audio_reactive.h index acef3adc..e4bf2a76 100644 --- a/usermods/audioreactive/audio_reactive.h +++ b/usermods/audioreactive/audio_reactive.h @@ -2371,13 +2371,13 @@ class AudioReactive : public Usermod { } // AGC or manual Gain - if ((soundAgc==0) && (disableSoundProcessing == false) && !(audioSyncEnabled & AUDIOSYNC_REC)) { + if ((soundAgc == 0) && (disableSoundProcessing == false) && !(audioSyncEnabled == AUDIOSYNC_REC)) { infoArr = user.createNestedArray(F("Manual Gain")); float myGain = ((float)sampleGain/40.0f * (float)inputLevel/128.0f) + 1.0f/16.0f; // non-AGC gain from presets infoArr.add(roundf(myGain*100.0f) / 100.0f); infoArr.add("x"); } - if (soundAgc && (disableSoundProcessing == false) && !(audioSyncEnabled & AUDIOSYNC_REC)) { + if ((soundAgc > 0) && (disableSoundProcessing == false) && !(audioSyncEnabled == AUDIOSYNC_REC)) { infoArr = user.createNestedArray(F("AGC Gain")); infoArr.add(roundf(multAgc*100.0f) / 100.0f); infoArr.add("x"); From 782628b6aae2cc4ec81bba3db0b7151e02dcc373 Mon Sep 17 00:00:00 2001 From: Frank <91616163+softhack007@users.noreply.github.com> Date: Sun, 10 Dec 2023 14:40:36 +0100 Subject: [PATCH 14/17] UM battery: changed default for auto-off feature to "disabled" Especially on 8266, the usermod can cause unexpected shut-downs in default configuration, when A0 is not connected to a battery voltage measurement circuit. --- usermods/Battery/battery_defaults.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/usermods/Battery/battery_defaults.h b/usermods/Battery/battery_defaults.h index c1e3c6bb..60dd4c4b 100644 --- a/usermods/Battery/battery_defaults.h +++ b/usermods/Battery/battery_defaults.h @@ -56,7 +56,7 @@ // auto-off feature #ifndef USERMOD_BATTERY_AUTO_OFF_ENABLED - #define USERMOD_BATTERY_AUTO_OFF_ENABLED true + #define USERMOD_BATTERY_AUTO_OFF_ENABLED false #endif #ifndef USERMOD_BATTERY_AUTO_OFF_THRESHOLD @@ -78,4 +78,4 @@ #ifndef USERMOD_BATTERY_LOW_POWER_INDICATOR_DURATION #define USERMOD_BATTERY_LOW_POWER_INDICATOR_DURATION 5 -#endif \ No newline at end of file +#endif From 90b52b3a0d3e39578cf5925b29b61c5fde8d2277 Mon Sep 17 00:00:00 2001 From: Frank <91616163+softhack007@users.noreply.github.com> Date: Sun, 10 Dec 2023 14:54:35 +0100 Subject: [PATCH 15/17] Changed some usermods to be "disabled" by default Some usermods may cause unexpected behaviour if not configured properly. * Battery: can cause unexpected shutdowns if no voltage measurement circuit connected * RTC: can cause unexpected time &date changes if no RTC connected to I2C * mcu temp: can cause hight CPU load, and may cause instabilities due to use of an "unsupported" API from espressif --- wled00/usermods_list.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/wled00/usermods_list.cpp b/wled00/usermods_list.cpp index 95ebfb5d..74afd5de 100644 --- a/wled00/usermods_list.cpp +++ b/wled00/usermods_list.cpp @@ -225,7 +225,7 @@ void registerUsermods() */ //usermods.add(new MyExampleUsermod()); #ifdef USERMOD_BATTERY - usermods.add(new UsermodBattery("Battery", true)); + usermods.add(new UsermodBattery("Battery", false)); // WLEDMM #endif #ifdef USERMOD_DALLASTEMPERATURE @@ -293,7 +293,7 @@ void registerUsermods() #endif #ifdef USERMOD_RTC - usermods.add(new RTCUsermod("RTC", true)); + usermods.add(new RTCUsermod("RTC", false)); //WLEDMM #endif #ifdef USERMOD_ELEKSTUBE_IPS @@ -385,7 +385,7 @@ void registerUsermods() #endif #ifdef USERMOD_MCUTEMP - usermods.add(new mcuTemp("MCUTemp", true)); + usermods.add(new mcuTemp("MCUTemp", false)); #endif //#ifdef USERMOD_INTERNAL_TEMPERATURE From e4cb0929c322a6ed7df8cde161264ecde4d63ddf Mon Sep 17 00:00:00 2001 From: Frank Date: Sun, 10 Dec 2023 16:49:13 +0100 Subject: [PATCH 16/17] PartyJerk: minor code style improvements * fix some too-long tabs *author info added * shrunk number of blank lines * removed unused audio variables * colorIndex : better accuracy by first doing multiply, then divide --- wled00/FX.cpp | 35 +++++++++++------------------------ wled00/FX.h | 3 +-- 2 files changed, 12 insertions(+), 26 deletions(-) diff --git a/wled00/FX.cpp b/wled00/FX.cpp index 84bd4a8c..a5926f4b 100644 --- a/wled00/FX.cpp +++ b/wled00/FX.cpp @@ -1921,21 +1921,20 @@ uint16_t mode_pride_2015(void) { } static const char _data_FX_MODE_PRIDE_2015[] PROGMEM = "Pride 2015@!;;"; + ////////////////////// // PARTYJERK // ////////////////////// - - - +// by @tonyxforce +// NB: This effects expects a palette that starts with black and then ramps up brightness. +// Currently works best with the "color gradient" and the "colors 1&2" palettes uint16_t mode_partyjerk() { - if (SEGENV.call == 0) { SEGMENT.fill(BLACK); // clear LEDs SEGENV.aux0 = 0; SEGENV.aux1 = 0; SEGENV.step = 0; } - /* * use of persistent variables: * aux0: hueDelay @@ -1948,24 +1947,18 @@ uint16_t mode_partyjerk() { // add support for no audio um_data = simulateSound(SEGMENT.soundSim); } - uint8_t samplePeak = *(uint8_t*)um_data->u_data[3]; - uint8_t *maxVol = (uint8_t*)um_data->u_data[6]; - uint8_t *binNum = (uint8_t*)um_data->u_data[7]; - float volumeSmth = *(float*) um_data->u_data[0]; + float volumeSmth = *(float*) um_data->u_data[0]; SEGENV.aux0++; - if (SEGENV.aux1 > 254) { SEGENV.aux1 = 0; } - if (SEGENV.aux0 > map(SEGMENT.custom1, 0, 255, 0, 14)) { SEGENV.aux0 = 0; SEGENV.aux1++; } uint_fast32_t speed = 0; - uint16_t counter = 0; if (volumeSmth * 2 > (255 - SEGMENT.intensity)) { @@ -1975,30 +1968,24 @@ uint16_t mode_partyjerk() { }; SEGENV.step += speed; - counter = SEGENV.step >> 8; - for (uint16_t i = 0; i < SEGLEN; i++) { - - uint8_t colorIndex = (i * 255 / SEGLEN) - counter; - - uint32_t paletteColor = SEGMENT.color_from_palette(colorIndex, false, true, 255); - + for (unsigned i = 0; i < SEGLEN; i++) { + uint8_t colorIndex = ((i * 255) / SEGLEN) - counter; + uint32_t paletteColor = SEGMENT.color_from_palette(colorIndex, false, PALETTE_MOVING_WRAP, 255); uint8_t r = R(paletteColor); uint8_t g = G(paletteColor); uint8_t b = B(paletteColor); - uint8_t activeColor = max(r, max(g, b)); CRGB rgb(CHSV(SEGENV.aux1, 255, activeColor)); - - SEGMENT.setPixelColor(i, rgb.r, rgb.g, rgb.b); + SEGMENT.setPixelColor((uint16_t)i, rgb.r, rgb.g, rgb.b); }; return FRAMETIME; } // mode_partyjerk() +static const char _data_FX_MODE_PARTYJERK[] PROGMEM = "Party jerk@Effect speed,Sensitivity,Color change speed,Effect speed active multiplier;!,!;!;1v;c1=8,c2=48,m12=0,si=0"; -static const char _data_FX_MODE_PARTYJERK[] PROGMEM = "Party jerk@Effect speed,Sensivity,Color change speed,Effect speed active multiplier;!,!;!;1v;c1=8,c2=48,m12=0,si=0"; //eight colored dots, weaving in and out of sync with each other uint16_t mode_juggle(void) { @@ -2025,7 +2012,7 @@ static const char _data_FX_MODE_JUGGLE[] PROGMEM = "Juggle@!,Trail;;!;;sx=64,ix= uint16_t mode_palette() { - uint16_t counter = 0; + uint16_t counter = 0; if (SEGMENT.speed != 0) { counter = (strip.now * ((SEGMENT.speed >> 3) +1)) & 0xFFFF; diff --git a/wled00/FX.h b/wled00/FX.h index 353b40b8..ac72422e 100644 --- a/wled00/FX.h +++ b/wled00/FX.h @@ -334,8 +334,7 @@ void strip_wait_until_idle(String whoCalledMe); // WLEDMM implemented in FX_fcn. #define FX_MODE_ROCKTAVES 185 #define FX_MODE_2DAKEMI 186 #define FX_MODE_ARTIFX 187 //WLEDMM ARTIFX - -#define FX_MODE_PARTYJERK 188 +#define FX_MODE_PARTYJERK 188 #define MODE_COUNT 189 From d2c9c9ee71ae52de9b6b4de0e3fd3e02f3f47603 Mon Sep 17 00:00:00 2001 From: Frank Date: Sun, 10 Dec 2023 16:50:49 +0100 Subject: [PATCH 17/17] fix small typo --- wled00/FX.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wled00/FX.h b/wled00/FX.h index ac72422e..3e4df0e7 100644 --- a/wled00/FX.h +++ b/wled00/FX.h @@ -398,7 +398,7 @@ typedef struct Segment { uint16_t aux0; // custom var uint16_t aux1; // custom var byte* data = nullptr; // effect data pointer // WLEDMM initialize to nullptr - CRGB* ledsrgb = nullptr; // local leds[] array (may be a pointer to global) //WLEDMM rename to ledsrgb to search on them (temp?), and initialilize to nullptr + CRGB* ledsrgb = nullptr; // local leds[] array (may be a pointer to global) //WLEDMM rename to ledsrgb to search on them (temp?), and initialize to nullptr size_t ledsrgbSize; //WLEDMM static CRGB *_globalLeds; // global leds[] array static uint16_t maxWidth, maxHeight; // these define matrix width & height (max. segment dimensions)