FastLED 3.9.7
Loading...
Searching...
No Matches
fx_engine.h
1#pragma once
2
3#include <stdint.h>
4#include <string.h>
5
6
7#include "crgb.h"
8#include "fl/map.h"
9#include "fx/fx.h"
10#include "fx/detail/fx_compositor.h"
11#include "fx/detail/fx_layer.h"
12#include "fl/namespace.h"
13#include "fl/ptr.h"
14#include "fl/ui.h"
15#include "fx/time.h"
16#include "fx/video.h"
17#include "fl/xymap.h"
18
19
20// Forward declaration
21class TimeFunction;
22
23#ifndef FASTLED_FX_ENGINE_MAX_FX
24#define FASTLED_FX_ENGINE_MAX_FX 64
25#endif
26
27namespace fl {
28
38class FxEngine {
39 public:
45 FxEngine(uint16_t numLeds, bool interpolate=true);
46
50 ~FxEngine();
51
57 int addFx(FxPtr effect);
58
59
68 int addFx(Fx& effect) { return addFx(fl::Ptr<Fx>::NoTracking(effect)); }
69
76 FxPtr removeFx(int index);
77
83 FxPtr getFx(int index);
84
85 int getCurrentFxId() const { return mCurrId; }
86
92 bool draw(uint32_t now, CRGB *outputBuffer);
93
99 bool nextFx(uint16_t transition_ms = 500);
100
107 bool setNextFx(int index, uint16_t duration);
108
109
110 IntFxMap& _getEffects() { return mEffects; }
111
116 void setSpeed(float scale) { mTimeFunction.setScale(scale); }
117
118 private:
119 int mCounter = 0;
120 TimeScale mTimeFunction; // FxEngine controls the clock, to allow "time-bending" effects.
121 IntFxMap mEffects;
122 FxCompositor mCompositor;
123 int mCurrId;
124 uint16_t mDuration = 0;
125 bool mDurationSet = false;
126 bool mInterpolate = true;
127};
128
129} // namespace fl
Manages and renders multiple visual effects (Fx) for LED strips.
Definition fx_engine.h:38
int addFx(FxPtr effect)
Adds a new effect to the engine.
Definition fx_engine.cpp:16
void setSpeed(float scale)
Sets the speed of the fx engine, which will impact the speed of all effects.
Definition fx_engine.h:116
~FxEngine()
Destructor for FxEngine.
Definition fx_engine.cpp:14
bool nextFx(uint16_t transition_ms=500)
Transitions to the next effect in the sequence.
Definition fx_engine.cpp:35
bool setNextFx(int index, uint16_t duration)
Sets the next effect to transition to.
Definition fx_engine.cpp:44
FxEngine(uint16_t numLeds, bool interpolate=true)
Constructs an FxEngine with the specified number of LEDs.
Definition fx_engine.cpp:7
bool draw(uint32_t now, CRGB *outputBuffer)
Renders the current effect or transition to the output buffer.
Definition fx_engine.cpp:84
FxPtr removeFx(int index)
Requests removal of an effect from the engine, which might not happen immediately (for example the Fx...
Definition fx_engine.cpp:54
FxPtr getFx(int index)
Retrieves an effect from the engine without removing it.
Definition fx_engine.cpp:75
int addFx(Fx &effect)
Adds a new effect to the engine.
Definition fx_engine.h:68
Definition fx.h:18
Definition ptr.h:102
Defines the red, green, and blue (RGB) pixel struct.
Implements the FastLED namespace macros.
Implements a simple red square effect for 2D LED grids.
Definition crgb.h:16
Representation of an RGB pixel (Red, Green, Blue)
Definition crgb.h:54