43 lines
965 B
C++
43 lines
965 B
C++
#pragma once
|
|
|
|
#include <Arduino.h>
|
|
#include <Adafruit_NeoPixel.h>
|
|
#include <algorithm>
|
|
#include <cstddef>
|
|
#include "spore/core/NodeContext.h"
|
|
#include "spore/util/Logging.h"
|
|
|
|
struct PixelStreamConfig {
|
|
uint8_t pin;
|
|
uint16_t pixelCount;
|
|
uint8_t brightness;
|
|
uint16_t matrixWidth;
|
|
bool matrixSerpentine;
|
|
neoPixelType pixelType;
|
|
};
|
|
|
|
class PixelStreamController {
|
|
public:
|
|
PixelStreamController(NodeContext& ctx, const PixelStreamConfig& config);
|
|
void begin();
|
|
|
|
private:
|
|
struct FrameComponents {
|
|
uint8_t red;
|
|
uint8_t green;
|
|
uint8_t blue;
|
|
};
|
|
|
|
bool tryParsePixel(const String& payload, std::size_t startIndex, FrameComponents& components) const;
|
|
void handleEvent(void* data);
|
|
bool applyFrame(const String& payload);
|
|
uint16_t mapPixelIndex(uint16_t logicalIndex) const;
|
|
static int hexToNibble(char c);
|
|
|
|
NodeContext& ctx;
|
|
PixelStreamConfig config;
|
|
Adafruit_NeoPixel pixels;
|
|
};
|
|
|
|
|