feat: services (#2)
This commit is contained in:
67
examples/neopixel/NeoPixelService.h
Normal file
67
examples/neopixel/NeoPixelService.h
Normal file
@@ -0,0 +1,67 @@
|
||||
#pragma once
|
||||
#include "services/Service.h"
|
||||
#include "TaskManager.h"
|
||||
#include <Adafruit_NeoPixel.h>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
class NeoPixelService : public Service {
|
||||
public:
|
||||
enum class Pattern {
|
||||
Off,
|
||||
ColorWipe,
|
||||
Rainbow,
|
||||
RainbowCycle,
|
||||
TheaterChase,
|
||||
TheaterChaseRainbow
|
||||
};
|
||||
|
||||
NeoPixelService(TaskManager& taskMgr, uint16_t numPixels, uint8_t pin, neoPixelType type);
|
||||
void registerEndpoints(ApiServer& api) override;
|
||||
const char* getName() const override { return "NeoPixel"; }
|
||||
|
||||
void setPatternByName(const String& name);
|
||||
void setBrightness(uint8_t b);
|
||||
|
||||
private:
|
||||
void registerTasks();
|
||||
void registerPatterns();
|
||||
std::vector<String> patternNamesVector() const;
|
||||
String currentPatternName() const;
|
||||
Pattern nameToPattern(const String& name) const;
|
||||
void resetStateForPattern(Pattern p);
|
||||
void update();
|
||||
|
||||
// Pattern updaters
|
||||
void updateOff();
|
||||
void updateColorWipe();
|
||||
void updateRainbow();
|
||||
void updateRainbowCycle();
|
||||
void updateTheaterChase();
|
||||
void updateTheaterChaseRainbow();
|
||||
|
||||
// Handlers
|
||||
void handleStatusRequest(AsyncWebServerRequest* request);
|
||||
void handlePatternsRequest(AsyncWebServerRequest* request);
|
||||
void handleControlRequest(AsyncWebServerRequest* request);
|
||||
|
||||
TaskManager& taskManager;
|
||||
Adafruit_NeoPixel strip;
|
||||
|
||||
std::map<String, std::function<void()>> patternUpdaters;
|
||||
|
||||
Pattern currentPattern;
|
||||
unsigned long updateIntervalMs;
|
||||
unsigned long lastUpdateMs;
|
||||
|
||||
// State for patterns
|
||||
uint16_t wipeIndex;
|
||||
uint32_t wipeColor;
|
||||
uint8_t rainbowJ;
|
||||
uint8_t cycleJ;
|
||||
int chaseJ;
|
||||
int chaseQ;
|
||||
bool chasePhaseOn;
|
||||
uint32_t chaseColor;
|
||||
uint8_t brightness;
|
||||
};
|
||||
Reference in New Issue
Block a user