Refactor HardwareLed class to use FastLED library and template for GPIO pin specification
This commit is contained in:
@@ -1,21 +1,30 @@
|
||||
#pragma once
|
||||
|
||||
#include "hardware.pb.h"
|
||||
#include <Adafruit_NeoPixel.h>
|
||||
#include <FastLED.h>
|
||||
|
||||
/**
|
||||
* @class HardwareLed
|
||||
* @brief Manages an LED strip on ESP8266 using Adafruit NeoPixel library.
|
||||
* @brief Manages an LED strip on ESP8266 using FastLED library.
|
||||
* Supports animations defined by hardware_LedConfig (static, pulse, fade, flicker).
|
||||
* Template parameter PIN specifies the GPIO pin at compile time.
|
||||
*
|
||||
* @tparam PIN The GPIO pin connected to the LED strip (e.g., 2 for D2 on ESP8266).
|
||||
*/
|
||||
template<uint8_t PIN>
|
||||
class HardwareLed {
|
||||
public:
|
||||
using AnimationCallback = void (*)();
|
||||
|
||||
HardwareLed(uint8_t pin, uint8_t numPixels = 1);
|
||||
/**
|
||||
* @brief Constructor for HardwareLed.
|
||||
* @param numPixels Number of pixels in the strip (default: 1).
|
||||
*/
|
||||
HardwareLed(uint8_t numPixels = 1);
|
||||
~HardwareLed();
|
||||
void begin();
|
||||
void end();
|
||||
void update(); // Removed const
|
||||
void update();
|
||||
void set(const hardware_LedConfig& config);
|
||||
void setAnimationCallback(AnimationCallback cb) { m_callback = cb; }
|
||||
float estimateCurrent_mA() const;
|
||||
@@ -23,13 +32,15 @@ public:
|
||||
private:
|
||||
void applyStatic(const hardware_StaticParams& params);
|
||||
void applyPulse(const hardware_PulseParams& params);
|
||||
void applyFade(const hardware_FadeParams& params); // Removed const
|
||||
void applyFade(const hardware_FadeParams& params);
|
||||
void applyFlicker(const hardware_FlickerParams& params);
|
||||
void setColor(uint32_t color, uint8_t brightness = 255);
|
||||
uint32_t lerpColor(uint32_t color1, uint32_t color2, float t) const;
|
||||
|
||||
Adafruit_NeoPixel m_strip;
|
||||
CRGB* m_leds; // Dynamic array for pixel data
|
||||
uint8_t m_numPixels;
|
||||
hardware_LedConfig m_currentConfig = hardware_LedConfig_init_default;
|
||||
bool m_isActive;
|
||||
unsigned long m_startTime;
|
||||
uint8_t m_pulseState;
|
||||
unsigned long m_lastPulseTime;
|
||||
@@ -39,6 +50,5 @@ private:
|
||||
uint32_t m_fadeTargetColor;
|
||||
float m_fadeProgress;
|
||||
unsigned long m_fadeStartTime;
|
||||
bool m_isActive;
|
||||
AnimationCallback m_callback = nullptr;
|
||||
};
|
||||
Reference in New Issue
Block a user