100 lines
2.9 KiB
C++
100 lines
2.9 KiB
C++
#pragma once
|
|
#include "spore/Service.h"
|
|
#include "spore/core/TaskManager.h"
|
|
#include "spore/core/NodeContext.h"
|
|
#include "NeoPattern.h"
|
|
#include "NeoPatternState.h"
|
|
#include "NeoPixelConfig.h"
|
|
#include "PatternRegistry.h"
|
|
#include <map>
|
|
#include <functional>
|
|
|
|
class NeoPatternService : public Service {
|
|
public:
|
|
enum class NeoPatternType {
|
|
NONE = 0,
|
|
RAINBOW_CYCLE = 1,
|
|
THEATER_CHASE = 2,
|
|
COLOR_WIPE = 3,
|
|
SCANNER = 4,
|
|
FADE = 5,
|
|
FIRE = 6
|
|
};
|
|
|
|
enum class NeoDirection {
|
|
FORWARD,
|
|
REVERSE
|
|
};
|
|
|
|
NeoPatternService(NodeContext& ctx, TaskManager& taskMgr, const NeoPixelConfig& config);
|
|
~NeoPatternService();
|
|
|
|
void registerEndpoints(ApiServer& api) override;
|
|
void registerTasks(TaskManager& taskManager) override;
|
|
const char* getName() const override { return "NeoPattern"; }
|
|
|
|
// Pattern control methods
|
|
void setPattern(NeoPatternType pattern);
|
|
void setPatternByName(const String& name);
|
|
void setColor(uint32_t color);
|
|
void setColor2(uint32_t color2);
|
|
void setBrightness(uint8_t brightness);
|
|
void setTotalSteps(uint16_t steps);
|
|
void setDirection(NeoDirection direction);
|
|
void setUpdateInterval(unsigned long interval);
|
|
|
|
// State management
|
|
void setState(const NeoPatternState& state);
|
|
NeoPatternState getState() const;
|
|
|
|
private:
|
|
void registerPatterns();
|
|
void update();
|
|
void registerEventHandlers();
|
|
bool applyControlParams(const JsonObject& obj);
|
|
|
|
// Pattern updaters
|
|
void updateRainbowCycle();
|
|
void updateTheaterChase();
|
|
void updateColorWipe();
|
|
void updateScanner();
|
|
void updateFade();
|
|
void updateFire();
|
|
void updateNone();
|
|
|
|
// API handlers
|
|
void handleStatusRequest(AsyncWebServerRequest* request);
|
|
void handlePatternsRequest(AsyncWebServerRequest* request);
|
|
void handleControlRequest(AsyncWebServerRequest* request);
|
|
void handleStateRequest(AsyncWebServerRequest* request);
|
|
|
|
// Utility methods
|
|
std::vector<String> patternNamesVector() const;
|
|
String currentPatternName() const;
|
|
NeoPatternType nameToPattern(const String& name) const;
|
|
void resetStateForPattern(NeoPatternType pattern);
|
|
uint32_t parseColor(const String& colorStr) const;
|
|
|
|
// Pattern validation methods
|
|
bool isValidPattern(const String& name) const;
|
|
bool isValidPattern(NeoPatternType type) const;
|
|
bool patternRequiresColor2(const String& name) const;
|
|
bool patternSupportsDirection(const String& name) const;
|
|
String getPatternDescription(const String& name) const;
|
|
|
|
TaskManager& taskManager;
|
|
NodeContext& ctx;
|
|
NeoPattern* neoPattern;
|
|
NeoPixelConfig config;
|
|
NeoPatternState currentState;
|
|
|
|
// Pattern registry for centralized pattern management
|
|
PatternRegistry patternRegistry;
|
|
|
|
NeoPatternType activePattern;
|
|
NeoDirection direction;
|
|
unsigned long updateIntervalMs;
|
|
unsigned long lastUpdateMs;
|
|
bool initialized;
|
|
};
|