74 lines
2.4 KiB
C++
74 lines
2.4 KiB
C++
#pragma once
|
|
#include <map>
|
|
#include <functional>
|
|
#include <vector>
|
|
#include <Arduino.h>
|
|
|
|
/**
|
|
* PatternInfo structure containing all information needed for a pattern
|
|
*/
|
|
struct PatternInfo {
|
|
String name;
|
|
uint8_t type;
|
|
String description;
|
|
std::function<void()> updater;
|
|
std::function<void()> initializer;
|
|
bool requiresColor2;
|
|
bool supportsDirection;
|
|
|
|
// Default constructor for std::map compatibility
|
|
PatternInfo() : type(0), requiresColor2(false), supportsDirection(false) {}
|
|
|
|
// Parameterized constructor
|
|
PatternInfo(const String& n, uint8_t t, const String& desc,
|
|
std::function<void()> initFunc, std::function<void()> updateFunc = nullptr,
|
|
bool needsColor2 = false, bool supportsDir = true)
|
|
: name(n), type(t), description(desc), updater(updateFunc),
|
|
initializer(initFunc), requiresColor2(needsColor2), supportsDirection(supportsDir) {}
|
|
};
|
|
|
|
/**
|
|
* PatternRegistry class for centralized pattern management
|
|
*/
|
|
class PatternRegistry {
|
|
public:
|
|
using PatternMap = std::map<String, PatternInfo>;
|
|
using PatternTypeMap = std::map<uint8_t, String>;
|
|
|
|
PatternRegistry();
|
|
~PatternRegistry() = default;
|
|
|
|
// Pattern registration
|
|
void registerPattern(const PatternInfo& pattern);
|
|
void registerPattern(const String& name, uint8_t type, const String& description,
|
|
std::function<void()> initializer, std::function<void()> updater = nullptr,
|
|
bool requiresColor2 = false, bool supportsDirection = true);
|
|
|
|
// Pattern lookup
|
|
const PatternInfo* getPattern(const String& name) const;
|
|
const PatternInfo* getPattern(uint8_t type) const;
|
|
String getPatternName(uint8_t type) const;
|
|
uint8_t getPatternType(const String& name) const;
|
|
|
|
// Pattern enumeration
|
|
std::vector<String> getAllPatternNames() const;
|
|
std::vector<PatternInfo> getAllPatterns() const;
|
|
const PatternMap& getPatternMap() const { return patternMap_; }
|
|
|
|
// Pattern validation
|
|
bool isValidPattern(const String& name) const;
|
|
bool isValidPattern(uint8_t type) const;
|
|
|
|
// Pattern execution
|
|
void executePattern(const String& name) const;
|
|
void executePattern(uint8_t type) const;
|
|
void initializePattern(const String& name) const;
|
|
void initializePattern(uint8_t type) const;
|
|
|
|
private:
|
|
PatternMap patternMap_;
|
|
PatternTypeMap typeToNameMap_;
|
|
|
|
void updateTypeMap();
|
|
};
|