feat: rewrite NeoPattern example
This commit is contained in:
@@ -1,34 +1,87 @@
|
||||
#pragma once
|
||||
#include "spore/Service.h"
|
||||
#include "spore/core/TaskManager.h"
|
||||
#include "NeoPattern.cpp"
|
||||
#include "NeoPattern.h"
|
||||
#include "NeoPatternState.h"
|
||||
#include "NeoPixelConfig.h"
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <functional>
|
||||
|
||||
class NeoPatternService : public Service {
|
||||
public:
|
||||
NeoPatternService(TaskManager& taskMgr, uint16_t numPixels, uint8_t pin, uint8_t type);
|
||||
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(TaskManager& taskMgr, const NeoPixelConfig& config);
|
||||
~NeoPatternService();
|
||||
|
||||
void registerEndpoints(ApiServer& api) override;
|
||||
const char* getName() const override { return "NeoPattern"; }
|
||||
|
||||
void setBrightness(uint8_t b);
|
||||
// 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 registerTasks();
|
||||
void registerPatterns();
|
||||
std::vector<String> patternNamesVector();
|
||||
String currentPatternName();
|
||||
void update();
|
||||
|
||||
// Pattern updaters
|
||||
void updateRainbowCycle();
|
||||
void updateTheaterChase();
|
||||
void updateColorWipe();
|
||||
void updateScanner();
|
||||
void updateFade();
|
||||
void updateFire();
|
||||
void updateNone();
|
||||
|
||||
// Handlers
|
||||
// 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;
|
||||
|
||||
TaskManager& taskManager;
|
||||
NeoPattern pixels;
|
||||
NeoPattern* neoPattern;
|
||||
NeoPixelConfig config;
|
||||
NeoPatternState currentState;
|
||||
|
||||
std::map<String, std::function<void()>> patternUpdaters;
|
||||
std::map<String, NeoPatternType> nameToPatternMap;
|
||||
|
||||
NeoPatternType activePattern;
|
||||
NeoDirection direction;
|
||||
unsigned long updateIntervalMs;
|
||||
uint8_t brightness;
|
||||
std::map<String, std::function<void()>> patternSetters;
|
||||
unsigned long lastUpdateMs;
|
||||
bool initialized;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user