fix: neopattern example wdt reset

This commit is contained in:
2025-10-18 13:49:39 +02:00
parent b404852fc7
commit ce70830678
3 changed files with 47 additions and 45 deletions

View File

@@ -339,9 +339,31 @@ void NeoPatternService::setPattern(NeoPatternType pattern) {
currentState.pattern = static_cast<uint>(pattern);
neoPattern->ActivePattern = static_cast<::pattern>(pattern);
resetStateForPattern(pattern);
// Initialize the pattern using the registry
patternRegistry.initializePattern(static_cast<uint8_t>(pattern));
// Set up pattern-specific parameters
switch (pattern) {
case NeoPatternType::RAINBOW_CYCLE:
neoPattern->RainbowCycle(updateIntervalMs, static_cast<::direction>(direction));
break;
case NeoPatternType::THEATER_CHASE:
neoPattern->TheaterChase(currentState.color, currentState.color2, updateIntervalMs, static_cast<::direction>(direction));
break;
case NeoPatternType::COLOR_WIPE:
neoPattern->ColorWipe(currentState.color, updateIntervalMs, static_cast<::direction>(direction));
break;
case NeoPatternType::SCANNER:
neoPattern->Scanner(currentState.color, updateIntervalMs);
break;
case NeoPatternType::FADE:
neoPattern->Fade(currentState.color, currentState.color2, currentState.totalSteps, updateIntervalMs, static_cast<::direction>(direction));
break;
case NeoPatternType::FIRE:
// Fire pattern doesn't need setup
break;
case NeoPatternType::NONE:
// None pattern doesn't need setup
break;
}
}
void NeoPatternService::setPatternByName(const String& name) {
@@ -425,7 +447,7 @@ void NeoPatternService::registerPatterns() {
"rainbow_cycle",
static_cast<uint8_t>(NeoPatternType::RAINBOW_CYCLE),
"Rainbow cycle pattern",
[this]() { neoPattern->RainbowCycle(updateIntervalMs, static_cast<::direction>(direction)); },
nullptr, // No initializer needed, state is set up in setPattern
[this]() { updateRainbowCycle(); },
false, // doesn't require color2
true // supports direction
@@ -435,7 +457,7 @@ void NeoPatternService::registerPatterns() {
"theater_chase",
static_cast<uint8_t>(NeoPatternType::THEATER_CHASE),
"Theater chase pattern",
[this]() { neoPattern->TheaterChase(currentState.color, currentState.color2, updateIntervalMs, static_cast<::direction>(direction)); },
nullptr, // No initializer needed, state is set up in setPattern
[this]() { updateTheaterChase(); },
true, // requires color2
true // supports direction
@@ -445,7 +467,7 @@ void NeoPatternService::registerPatterns() {
"color_wipe",
static_cast<uint8_t>(NeoPatternType::COLOR_WIPE),
"Color wipe pattern",
[this]() { neoPattern->ColorWipe(currentState.color, updateIntervalMs, static_cast<::direction>(direction)); },
nullptr, // No initializer needed, state is set up in setPattern
[this]() { updateColorWipe(); },
false, // doesn't require color2
true // supports direction
@@ -455,7 +477,7 @@ void NeoPatternService::registerPatterns() {
"scanner",
static_cast<uint8_t>(NeoPatternType::SCANNER),
"Scanner pattern",
[this]() { neoPattern->Scanner(currentState.color, updateIntervalMs); },
nullptr, // No initializer needed, state is set up in setPattern
[this]() { updateScanner(); },
false, // doesn't require color2
false // doesn't support direction
@@ -465,7 +487,7 @@ void NeoPatternService::registerPatterns() {
"fade",
static_cast<uint8_t>(NeoPatternType::FADE),
"Fade pattern",
[this]() { neoPattern->Fade(currentState.color, currentState.color2, currentState.totalSteps, updateIntervalMs, static_cast<::direction>(direction)); },
nullptr, // No initializer needed, state is set up in setPattern
[this]() { updateFade(); },
true, // requires color2
true // supports direction
@@ -475,7 +497,7 @@ void NeoPatternService::registerPatterns() {
"fire",
static_cast<uint8_t>(NeoPatternType::FIRE),
"Fire effect pattern",
[this]() { neoPattern->Fire(50, 120); },
nullptr, // No initializer needed, state is set up in setPattern
[this]() { updateFire(); },
false, // doesn't require color2
false // doesn't support direction
@@ -499,7 +521,7 @@ void NeoPatternService::resetStateForPattern(NeoPatternType pattern) {
neoPattern->Index = 0;
neoPattern->Direction = static_cast<::direction>(direction);
neoPattern->completed = 0;
lastUpdateMs = 0;
// Don't reset lastUpdateMs to 0, keep the current timing
}
uint32_t NeoPatternService::parseColor(const String& colorStr) const {
@@ -537,10 +559,10 @@ String NeoPatternService::getPatternDescription(const String& name) const {
void NeoPatternService::update() {
if (!initialized) return;
//unsigned long now = millis();
//if (now - lastUpdateMs < updateIntervalMs) return;
//lastUpdateMs = now;
unsigned long now = millis();
if (now - lastUpdateMs < updateIntervalMs) return;
lastUpdateMs = now;
// Use pattern registry to execute the current pattern
patternRegistry.executePattern(static_cast<uint8_t>(activePattern));