From 45ac0d5dc6ec8be19b7e1e5247588170ce5463c1 Mon Sep 17 00:00:00 2001 From: Frank <91616163+softhack007@users.noreply.github.com> Date: Sun, 2 Jul 2023 19:14:32 +0200 Subject: [PATCH] fix for #3276 due to `if (strip.isUpdating()) return;` reading the encoder did not happen in time if the strip was active - with high number of LEDs, this means "always updating". Similar observation that we had with the audioreactive usermod, and similar solution. --- .../usermod_v2_rotary_encoder_ui_ALT.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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 75494ded..b142f903 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 @@ -45,6 +45,10 @@ #define ENCODER_SW_PIN 19 #endif +#ifndef ENCODER_MAX_DELAY_MS // max delay between polling encoder pins +#define ENCODER_MAX_DELAY_MS 8 // 8 milliseconds => max 120 change impulses in 1 second, for full turn of a 30/30 encoder (4 changes per segment, 30 segments for one turn) +#endif + #ifndef USERMOD_USE_PCF8574 #undef USE_PCF8574 #define USE_PCF8574 false @@ -539,8 +543,9 @@ void RotaryEncoderUIUsermod::setup() */ void RotaryEncoderUIUsermod::loop() { - if (!enabled || strip.isUpdating()) return; + if (!enabled) return; unsigned long currentTime = millis(); // get the current elapsed time + if (strip.isUpdating() && ((currentTime - loopTime) < ENCODER_MAX_DELAY_MS)) return; // be nice, but not too nice // Initialize effectCurrentIndex and effectPaletteIndex to // current state. We do it here as (at least) effectCurrent