Files
spore/examples/neopixel/NeoPixelService.h
Patrick Balsiger 554c6ff38d refactor: reorganize project structure with modern C++ namespace organization
- Restructure include/ and src/ directories with logical grouping
- Move core components to spore/core/ (NodeContext, NetworkManager, TaskManager, ClusterManager, ApiServer)
- Move services to spore/services/ (NodeService, NetworkService, ClusterService, TaskService)
- Move types to spore/types/ (NodeInfo, ApiTypes, Config)
- Move internal components to spore/internal/ (Globals)
- Update all #include statements to use new namespace paths
- Update platformio.ini build filters for all environments
- Update all example files to use new include paths
- Maintain backward compatibility for public API
- Improve code organization, maintainability, and scalability

This reorganization follows modern C++ project structure patterns and provides
clear separation between public API, internal implementation, and utilities.
All examples compile successfully with the new structure.
2025-09-13 21:30:07 +02:00

68 lines
1.7 KiB
C++

#pragma once
#include "spore/Service.h"
#include "spore/core/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;
};