FastLED 3.9.7
Loading...
Searching...
No Matches
fl::FxEngine Class Reference

Detailed Description

Manages and renders multiple visual effects (Fx) for LED strips.

The FxEngine class is responsible for:

  • Storing and managing a collection of visual effects (Fx objects)
  • Handling transitions between effects
  • Rendering the current effect or transition to an output buffer
Examples
FxEngine.ino.

Definition at line 38 of file fx_engine.h.

#include <fx_engine.h>

Public Types

typedef fl::FixedMap< int, FxPtr, FASTLED_FX_ENGINE_MAX_FX > IntFxMap
 

Public Member Functions

 FxEngine (uint16_t numLeds, bool interpolate=true)
 Constructs an FxEngine with the specified number of LEDs.
 
 ~FxEngine ()
 Destructor for FxEngine.
 
int addFx (FxPtr effect)
 Adds a new effect to the engine.
 
int addFx (Fx &effect)
 Adds a new effect to the engine.
 
FxPtr removeFx (int index)
 Requests removal of an effect from the engine, which might not happen immediately (for example the Fx needs to finish a transition).
 
FxPtr getFx (int index)
 Retrieves an effect from the engine without removing it.
 
int getCurrentFxId () const
 
bool draw (uint32_t now, CRGB *outputBuffer)
 Renders the current effect or transition to the output buffer.
 
bool nextFx (uint16_t transition_ms=500)
 Transitions to the next effect in the sequence.
 
bool setNextFx (int index, uint16_t duration)
 Sets the next effect to transition to.
 
IntFxMap_getEffects ()
 
void setSpeed (float scale)
 Sets the speed of the fx engine, which will impact the speed of all effects.
 

Member Typedef Documentation

◆ IntFxMap

typedef fl::FixedMap<int, FxPtr, FASTLED_FX_ENGINE_MAX_FX> fl::FxEngine::IntFxMap

Definition at line 40 of file fx_engine.h.

Constructor & Destructor Documentation

◆ FxEngine()

fl::FxEngine::FxEngine ( uint16_t numLeds,
bool interpolate = true )

Constructs an FxEngine with the specified number of LEDs.

Parameters
numLedsThe number of LEDs in the strip.

Definition at line 7 of file fx_engine.cpp.

◆ ~FxEngine()

fl::FxEngine::~FxEngine ( )

Destructor for FxEngine.

Definition at line 14 of file fx_engine.cpp.

Member Function Documentation

◆ _getEffects()

IntFxMap & fl::FxEngine::_getEffects ( )
inline

Definition at line 110 of file fx_engine.h.

◆ addFx() [1/2]

int fl::FxEngine::addFx ( Fx & effect)
inline

Adds a new effect to the engine.

Allocate from static memory. This is not reference tracked and an object passed in must never be deleted, as the engine will use a non tracking Ptr which may outlive a call to removeFx() and the engine will thefore not know that an object has been deleted. But if it's a static object that's then the object probably wasn't going to be deleted anyway.

Definition at line 68 of file fx_engine.h.

◆ addFx() [2/2]

int fl::FxEngine::addFx ( FxPtr effect)

Adds a new effect to the engine.

Parameters
effectPointer to the effect to be added.
Returns
The index of the added effect, or -1 if the effect couldn't be added.

Definition at line 16 of file fx_engine.cpp.

◆ draw()

bool fl::FxEngine::draw ( uint32_t now,
CRGB * outputBuffer )

Renders the current effect or transition to the output buffer.

Parameters
nowThe current time in milliseconds.
outputBufferThe buffer to render the effect into.

Definition at line 84 of file fx_engine.cpp.

◆ getCurrentFxId()

int fl::FxEngine::getCurrentFxId ( ) const
inline

Definition at line 85 of file fx_engine.h.

◆ getFx()

FxPtr fl::FxEngine::getFx ( int index)

Retrieves an effect from the engine without removing it.

Parameters
indexThe id of the effect to retrieve.
Returns
A pointer to the effect, or nullptr if the index was invalid.

Definition at line 75 of file fx_engine.cpp.

◆ nextFx()

bool fl::FxEngine::nextFx ( uint16_t transition_ms = 500)

Transitions to the next effect in the sequence.

Parameters
durationThe duration of the transition in milliseconds.
Returns
True if the transition was initiated, false otherwise.

Definition at line 35 of file fx_engine.cpp.

◆ removeFx()

FxPtr fl::FxEngine::removeFx ( int index)

Requests removal of an effect from the engine, which might not happen immediately (for example the Fx needs to finish a transition).

Parameters
indexThe index of the effect to remove.
Returns
A pointer to the removed effect, or nullptr if the index was invalid.

Definition at line 54 of file fx_engine.cpp.

◆ setNextFx()

bool fl::FxEngine::setNextFx ( int index,
uint16_t duration )

Sets the next effect to transition to.

Parameters
indexThe index of the effect to transition to.
durationThe duration of the transition in milliseconds.
Returns
True if the transition was set, false if the index was invalid.

Definition at line 44 of file fx_engine.cpp.

◆ setSpeed()

void fl::FxEngine::setSpeed ( float scale)
inline

Sets the speed of the fx engine, which will impact the speed of all effects.

Parameters
timeScaleThe new time scale value.

Definition at line 116 of file fx_engine.h.


The documentation for this class was generated from the following files: