fix: neopattern example wdt reset
This commit is contained in:
@@ -4,7 +4,6 @@
|
||||
NeoPattern::NeoPattern(uint16_t pixels, uint8_t pin, uint8_t type, void (*callback)(int))
|
||||
: Adafruit_NeoPixel(pixels, pin, type)
|
||||
{
|
||||
frameBuffer = (uint8_t *)malloc(768);
|
||||
OnComplete = callback;
|
||||
TotalSteps = numPixels();
|
||||
begin();
|
||||
@@ -13,40 +12,21 @@ NeoPattern::NeoPattern(uint16_t pixels, uint8_t pin, uint8_t type, void (*callba
|
||||
NeoPattern::NeoPattern(uint16_t pixels, uint8_t pin, uint8_t type)
|
||||
: Adafruit_NeoPixel(pixels, pin, type)
|
||||
{
|
||||
frameBuffer = (uint8_t *)malloc(768);
|
||||
TotalSteps = numPixels();
|
||||
begin();
|
||||
}
|
||||
|
||||
NeoPattern::~NeoPattern() {
|
||||
if (frameBuffer) {
|
||||
free(frameBuffer);
|
||||
}
|
||||
// No frameBuffer to clean up
|
||||
}
|
||||
|
||||
void NeoPattern::handleStream(uint8_t *data, size_t len)
|
||||
{
|
||||
//const uint16_t *data16 = (uint16_t *)data;
|
||||
bufferSize = len;
|
||||
memcpy(frameBuffer, data, len);
|
||||
}
|
||||
|
||||
void NeoPattern::drawFrameBuffer(int w, uint8_t *frame, int length)
|
||||
{
|
||||
for (int i = 0; i < length; i++)
|
||||
{
|
||||
uint8_t r = frame[i];
|
||||
uint8_t g = frame[i + 1];
|
||||
uint8_t b = frame[i + 2];
|
||||
setPixelColor(i, r, g, b);
|
||||
}
|
||||
}
|
||||
// Removed unused handleStream and drawFrameBuffer functions
|
||||
|
||||
void NeoPattern::onCompleteDefault(int pixels)
|
||||
{
|
||||
//Serial.println("onCompleteDefault");
|
||||
// FIXME no specific code
|
||||
if (ActivePattern == THEATER_CHASE)
|
||||
if (ActivePattern == THEATER_CHASE || ActivePattern == RAINBOW_CYCLE)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -127,7 +107,12 @@ void NeoPattern::RainbowCycleUpdate()
|
||||
setPixelColor(i, Wheel(((i * 256 / numPixels()) + Index) & 255));
|
||||
}
|
||||
show();
|
||||
Increment();
|
||||
// RainbowCycle is continuous, just increment Index
|
||||
Index++;
|
||||
if (Index >= 255)
|
||||
{
|
||||
Index = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Initialize for a Theater Chase
|
||||
|
||||
@@ -50,19 +50,14 @@ class NeoPattern : public Adafruit_NeoPixel
|
||||
uint16_t completed = 0;
|
||||
|
||||
// Callback on completion of pattern
|
||||
void (*OnComplete)(int);
|
||||
|
||||
uint8_t *frameBuffer;
|
||||
int bufferSize = 0;
|
||||
void (*OnComplete)(int);
|
||||
|
||||
// Constructor - calls base-class constructor to initialize strip
|
||||
NeoPattern(uint16_t pixels, uint8_t pin, uint8_t type, void (*callback)(int));
|
||||
NeoPattern(uint16_t pixels, uint8_t pin, uint8_t type);
|
||||
~NeoPattern();
|
||||
|
||||
// Stream handling
|
||||
void handleStream(uint8_t *data, size_t len);
|
||||
void drawFrameBuffer(int w, uint8_t *frame, int length);
|
||||
// Stream handling functions removed
|
||||
|
||||
// Pattern completion
|
||||
void onCompleteDefault(int pixels);
|
||||
|
||||
@@ -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));
|
||||
|
||||
Reference in New Issue
Block a user