Separate FreeRTOS task for LED
This commit is contained in:
@@ -1,55 +0,0 @@
|
||||
|
||||
// overall layout:
|
||||
// queue for each led stripe
|
||||
//
|
||||
|
||||
enum class EffectID
|
||||
{
|
||||
OFF,
|
||||
STATIC,
|
||||
CIRCLE,
|
||||
CIRCLE_WAVE,
|
||||
COLOR_FADE,
|
||||
RAINBOW_FADE,
|
||||
};
|
||||
|
||||
struct EffectCircularConfig
|
||||
{
|
||||
float speed; // in degrees per second
|
||||
float width; // width in degrees
|
||||
float brightnessFalloffFactor;
|
||||
};
|
||||
|
||||
template <typename TLedStrip>
|
||||
class AbstractEffect
|
||||
{
|
||||
public:
|
||||
virtual int operator()(TLedStrip &s) = 0;
|
||||
};
|
||||
|
||||
template <typename TLedStrip>
|
||||
class EffectCircle : public AbstractEffect<TLedStrip>
|
||||
{
|
||||
public:
|
||||
EffectCircle(const EffectCircularConfig &cfg) : config_(cfg) {}
|
||||
int operator()(TLedStrip &s) override;
|
||||
|
||||
private:
|
||||
EffectCircularConfig config_;
|
||||
float currentPosition_; // between 0 and 1
|
||||
};
|
||||
|
||||
unsigned char effectStorage[128];
|
||||
|
||||
template <typename TLedStrip>
|
||||
AbstractEffect<TLedStrip> *makeEffect(const char *buffer)
|
||||
{
|
||||
const EffectID &effectId = *reinterpret_cast<const EffectID *>(buffer);
|
||||
if (effectId == EffectID::CIRCLE)
|
||||
{
|
||||
auto cfg = reinterpret_cast<const EffectCircularConfig *>(buffer + sizeof(EffectID));
|
||||
return new (effectStorage) EffectCircle<TLedStrip>(*cfg);
|
||||
}
|
||||
// read effect id code from buffer
|
||||
// read config from buffer
|
||||
}
|
||||
@@ -75,6 +75,13 @@ void setLedRGBW(LedStripRGBW<TNumLeds> &s, int idx, const ColorRGBW &c)
|
||||
s.set(idx, c.r, c.g, c.b, c.w);
|
||||
}
|
||||
|
||||
template <int TNumLeds>
|
||||
void setLedRGBW(LedStripRGBW<TNumLeds> &s, int beginIdx, int endIdx, const ColorRGBW &c)
|
||||
{
|
||||
for (int i = beginIdx; i < endIdx; ++i)
|
||||
s.set(i, c.r, c.g, c.b, c.w);
|
||||
}
|
||||
|
||||
template <int TNumLeds>
|
||||
void clear(LedStripRGBW<TNumLeds> &s)
|
||||
{
|
||||
|
||||
@@ -17,6 +17,7 @@ class EffectCircular
|
||||
public:
|
||||
static constexpr auto NUM_LEDS = numLeds<TLedStrip>();
|
||||
static constexpr int DELAY_MS = 10;
|
||||
using ConfigType = EffectCircularConfig;
|
||||
|
||||
EffectCircular(const EffectCircularConfig &cfg, TLedStrip &ledStrip)
|
||||
: config_(cfg),
|
||||
@@ -72,3 +73,22 @@ private:
|
||||
int widthInLeds_;
|
||||
float invWidth_;
|
||||
};
|
||||
|
||||
// Traits
|
||||
template <>
|
||||
struct EffectIdToConfig<EffectId::CIRCULAR>
|
||||
{
|
||||
using type = EffectCircularConfig;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct EffectConfigToId<EffectCircularConfig>
|
||||
{
|
||||
static constexpr auto id = EffectId::CIRCULAR;
|
||||
};
|
||||
|
||||
template <typename TLedStrip>
|
||||
struct EffectIdToClass<EffectId::CIRCULAR, TLedStrip>
|
||||
{
|
||||
using type = EffectCircular<TLedStrip>;
|
||||
};
|
||||
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
enum class EffectID
|
||||
enum class EffectId
|
||||
{
|
||||
OFF,
|
||||
STATIC,
|
||||
CIRCULAR,
|
||||
CIRCLE_WAVE,
|
||||
@@ -9,9 +9,17 @@ enum class EffectID
|
||||
RAINBOW_FADE,
|
||||
};
|
||||
|
||||
template <typename TLedStrip>
|
||||
class AbstractEffect
|
||||
template <EffectId id>
|
||||
struct EffectIdToConfig
|
||||
{
|
||||
};
|
||||
|
||||
template <typename EffectConfig>
|
||||
struct EffectConfigToId
|
||||
{
|
||||
};
|
||||
|
||||
template <EffectId id, typename TLedStrip>
|
||||
struct EffectIdToClass
|
||||
{
|
||||
public:
|
||||
virtual int operator()(TLedStrip &s) = 0;
|
||||
};
|
||||
51
espmusicmouse/lib/ledtl/effects/Static.h
Normal file
51
espmusicmouse/lib/ledtl/effects/Static.h
Normal file
@@ -0,0 +1,51 @@
|
||||
#pragma once
|
||||
|
||||
#include "effects/Common.h"
|
||||
#include "helpers/ColorRGBW.h"
|
||||
|
||||
struct EffectStaticConfig
|
||||
{
|
||||
ColorRGBW color;
|
||||
};
|
||||
|
||||
template <typename TLedStrip>
|
||||
class EffectStatic
|
||||
{
|
||||
public:
|
||||
static constexpr auto NUM_LEDS = numLeds<TLedStrip>();
|
||||
|
||||
EffectStatic(const EffectStaticConfig &cfg, TLedStrip &ledStrip)
|
||||
: config_(cfg),
|
||||
ledStrip_(ledStrip)
|
||||
{
|
||||
}
|
||||
|
||||
int operator()()
|
||||
{
|
||||
setLedRGBW(ledStrip_, 0, NUM_LEDS, config_.color);
|
||||
return 10000; // nothing changing, return some large time to sleep
|
||||
}
|
||||
|
||||
private:
|
||||
EffectStaticConfig config_;
|
||||
TLedStrip &ledStrip_;
|
||||
};
|
||||
|
||||
// Traits
|
||||
template <>
|
||||
struct EffectIdToConfig<EffectId::STATIC>
|
||||
{
|
||||
using type = EffectStaticConfig;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct EffectConfigToId<EffectStaticConfig>
|
||||
{
|
||||
static constexpr auto id = EffectId::STATIC;
|
||||
};
|
||||
|
||||
template <typename TLedStrip>
|
||||
struct EffectIdToClass<EffectId::STATIC, TLedStrip>
|
||||
{
|
||||
using type = EffectStatic<TLedStrip>;
|
||||
};
|
||||
Reference in New Issue
Block a user