FastFX  1.1.0
LED Strip Animation and Effects Framework for Arduino
FFXBase Class Referenceabstract

#include <FFXBase.h>

+ Inheritance diagram for FFXBase:

Public Types

enum  MovementType {
  MVT_FORWARD =1, MVT_BACKWARD =2, MVT_BACKFORTH =3, MVT_RANDOM =4,
  MVT_STILL =5
}
 
enum  FadeType { LINEAR =1, GAMMA =2, CUBIC =3 }
 

Public Member Functions

 FFXBase (uint16_t initSize, unsigned long initInterval, unsigned long minRefresh, unsigned long maxRefresh)
 
 FFXBase (uint16_t initSize, unsigned long initInterval)
 
 FFXBase (uint16_t initSize, uint8_t initSpeed, unsigned long minRefresh, unsigned long maxRefresh)
 
 FFXBase (uint16_t initSize, uint8_t initSpeed)
 
 FFXBase (uint16_t initSize)
 
void initialize (uint16_t initSize)
 
String getFXName ()
 
uint8_t getFXID ()
 
virtual void setInterval (unsigned long newInterval) override
 
virtual void setColor (CRGB newColor)
 
MovementType getMovement ()
 
FFXBase::MovementType getCurrMovement (uint16_t cycle)
 
void setMovement (MovementType newMovement)
 
FFXColorgetFXColor ()
 
CRGB getColor ()
 
void setFXColor (FFXColor &newColor)
 
uint16_t mirror (uint16_t index)
 
void rotateForward (CRGB *bufLeds, uint16_t steps)
 
void rotateBackward (CRGB *bufLeds, uint16_t steps)
 
uint16_t addOffsetWithWrap (uint16_t index, uint16_t offset)
 
uint16_t subtractOffsetWithWrap (uint16_t index, uint16_t offset)
 
uint16_t getNextPhase ()
 
uint16_t getNextVPhase ()
 
uint16_t getPrevPhase ()
 
uint16_t getPrevVphase ()
 
uint16_t getCurrPhase ()
 
uint16_t getCurrVPhase ()
 
unsigned long getCurrCycle ()
 
unsigned long getCurrVCycle ()
 
uint16_t getMovementPhase ()
 
uint16_t getMovementVPhase ()
 
uint16_t getNumLeds ()
 
uint16_t getVCycleRange ()
 
uint16_t setVCycleRange (uint16_t newRange)
 
virtual int timingDelta (uint8_t phase, unsigned long sourceMillis)
 
int timingDelta (unsigned long sourceMillis)
 
virtual void onEachSecond (unsigned long secsRunning)
 
virtual void onCycleStart (CRGB *currFrame)
 
virtual void onCycleEnd (CRGB *currFrame)
 
virtual void whileFrozen (CRGB *currFrame)
 
virtual void onVCycleStart (CRGB *currFrame)
 
virtual void onVCycleEnd (CRGB *currFrame)
 
virtual void onBrightness (uint8_t newBrightness)
 
virtual void initLeds (CRGB *bufLeds)
 
virtual void writeNextFrame (CRGB *frameBuffer)=0
 
void vCycleStart (CRGB *currFrame)
 
void vCycleEnd (CRGB *currFrame)
 
void cycleStart (CRGB *currFrame)
 
void cycleEnd (CRGB *currFrame)
 
void freeze ()
 
void unFreeze ()
 
bool isFrozen ()
 
void update (CRGB *frameBuffer)
 
boolean isUpdated ()
 
void setUpdated (boolean newValue)
 
- Public Member Functions inherited from FFXStateNotifier
 FFXStateNotifier ()
 
virtual ~FFXStateNotifier ()
 
void addObserver (FFXStateObserver *obs)
 
void notify (String source, String attribute, String value)
 
- Public Member Functions inherited from FlexTimer
 FlexTimer (unsigned long minInterval, unsigned long maxInterval, unsigned long initInterval, boolean initStart)
 
 FlexTimer (unsigned long initInterval, boolean initStart)
 
 FlexTimer (unsigned long initInterval)
 
 FlexTimer (unsigned long minInterval, unsigned long maxInterval, bool initStart, uint8_t initSpeed)
 
virtual void onStart (unsigned long currMillis) override
 
virtual void onStep (unsigned long currMillis) override
 
void setStartExpired (boolean newVal)
 
boolean getStartExpired ()
 
unsigned long getRangeMin ()
 
unsigned long getRangeMax ()
 
void setRange (unsigned long minInterval, unsigned long maxInterval)
 
virtual void setSpeed (uint8_t newSpeed)
 
virtual uint8_t getSpeed ()
 
void addDelta (long delta)
 
virtual unsigned long getLastUp () override
 
unsigned long getCurrInterval ()
 
unsigned long getSteps ()
 
- Public Member Functions inherited from StepTimer
 StepTimer ()
 
 StepTimer (unsigned long initInterval, boolean startImmediate)
 
 StepTimer (unsigned long initInterval)
 
virtual ~StepTimer ()
 
void start ()
 
void start (unsigned long currMillis)
 
void step ()
 
void step (unsigned long currMillis)
 
void stop ()
 
bool isStarted ()
 
bool isUp (unsigned long currMillis)
 
bool isUp ()
 
unsigned long nextUp ()
 
unsigned long timeRemaining (unsigned long currMillis)
 
unsigned long timeRemaining ()
 
unsigned long getRollovers ()
 
unsigned long timeSinceStarted (unsigned long currMillis)
 
unsigned long timeSinceStarted ()
 
unsigned long timeSinceTriggered (unsigned long currMillis)
 
unsigned long timeSinceTriggered ()
 
virtual void setIntervalImmediate (unsigned long newInterval)
 
unsigned long getInterval ()
 

Static Public Member Functions

static String movementTypeStr (MovementType mvt)
 
static String fadeMethodStr (FadeType value)
 
static uint8_t alphaBlend (uint8_t a, uint8_t b, uint8_t alpha)
 
static CRGB alphaBlend (CRGB &a, CRGB &b, uint8_t alpha, FadeType ftUp=LINEAR, FadeType ftDown=LINEAR)
 
static void alphaBlend (CRGB *a, CRGB *b, CRGB *dest, uint16_t num, uint8_t alpha, FadeType ftUp=LINEAR, FadeType ftDown=LINEAR)
 
static uint16_t mirror (uint16_t index, uint16_t range)
 
static void rotateBufferForwardWithWrap (CRGB *source, CRGB *dest, uint8_t numLeds, uint8_t steps)
 
static void rotateBufferBackwardWithWrap (CRGB *source, CRGB *dest, uint16_t numLeds, uint16_t steps)
 
- Static Public Member Functions inherited from FlexTimer
static uint8_t intervalToSpeed (unsigned long intv, unsigned long rMin, unsigned long rMax)
 
static unsigned long speedToInterval (uint8_t speed, unsigned long rMin, unsigned long rMax)
 
- Static Public Member Functions inherited from StepTimer
static unsigned long addOffsetWithWrap (unsigned long index, unsigned long offset, unsigned long maximum)
 
static unsigned long addOffsetWithWrap (unsigned long index, unsigned long offset)
 
static unsigned long subtractOffsetWithWrap (unsigned long index, unsigned long offset, unsigned long maximum)
 

Protected Attributes

uint8_t fxid = 0
 
String fxName = ""
 
FFXColor currColor = FFXColor()
 
uint16_t numLeds
 
MovementType currMovement = MVT_FORWARD
 
uint16_t currPhase = 1
 
uint16_t currVPhase = 1
 
unsigned long currCycle = 1
 
unsigned long currVCycle = 1
 
uint16_t vCycleRange
 
bool changed = true
 
bool initialized = false
 
unsigned long defaultFrameRefresh = 50
 
unsigned long secondsElapsed = 0
 
bool frozen = false
 
- Protected Attributes inherited from StepTimer
unsigned long interval =DEFAULT_TIMER_INTERVAL
 
unsigned long started =0
 
unsigned long nextUpMillis =0
 
uint16_t rollovers = 0
 
unsigned long pendInterval = 0
 

Additional Inherited Members

- Static Public Attributes inherited from FlexTimer
static const unsigned long MIN_INTERVAL = 1
 
static const unsigned long MAX_INTERVAL = 5000U
 

Detailed Description

FFXBase - Base class for all LED Strip animation effects.

All static and animated effects should inherit from this class. The 2 key functions to override/implement in descendant classes are:

initLeds( CRGB *buffer ) writeNextFrame( CRGB *buffer )

Most effects can be written by simply overriding one or both of the above methods (see FXCoreEffects.h for examples).

FFXBase is a descendent of the FlexTimer class which allows for setting the speed/timing of the animation. FXBase also inherits from FXStateNotifier, which provides a means for sending state notification changes to any descendant of the FXStateObserver class (defined here as well). FXSegment, which is the "container" for all FXBase objects, is a descendent of FXStateObserver, so changes to timing or other state info can be pushed back to the "parent" segment.

Phase/Cycle - Each effect has a phase and a cycle, the cycle is one complete iteration from 1 to numLeds - the phase being the current index of that iteration.

VPhase/VCycle - We can also define a "virtual" phase and cycle which allows have a cycle that is larger or smaller than the number of LEDs on a strip. A larger VCycle is useful if we want to do additional things at either end of a cycle (i.e. where an animation will scroll off the end of the strip without wrapping around immediately. A smaller VCycle can be used if an animation needs fewer phases to complete (ex: quickly switching between to colors, jiggling back and forth, etc.) A VCycle is established by calling setVCycleRange()

MovementType is defined here, then used by descendant classes to determine the type of movement for a given effect.

FFXBase also provides several "utility" methods for performing common operations used in animated effects:

Rotate pixels within a CRGB Buffer, wrapping around at the ends: rotateBufferForwardwithWrap( ... ) rotateBufferBackwardWithWrap( ... )

Calculate the "mirror" image position of a given pixel (i.e. same distance from center, on the other side):

mirror( uint16_t position )

Several virtual methods are provided, which can be overriden in descendent classes

onEachSecond(unsigned long) // called for each elapsed second while effect is running (udpate() called within a loop) onCycleStart() onCycleEnd() onVCycleStart() onVCycleEnd() onBrightness() // called when brightness is changed (by FXXSegment) whileFrozen() // called each time update() is called while effect is "Frozen"/paused

Member Enumeration Documentation

◆ FadeType

Enumerator
LINEAR 
GAMMA 
CUBIC 

◆ MovementType

Enumerator
MVT_FORWARD 
MVT_BACKWARD 
MVT_BACKFORTH 
MVT_RANDOM 
MVT_STILL 

Constructor & Destructor Documentation

◆ FFXBase() [1/5]

FFXBase::FFXBase ( uint16_t  initSize,
unsigned long  initInterval,
unsigned long  minRefresh,
unsigned long  maxRefresh 
)

◆ FFXBase() [2/5]

FFXBase::FFXBase ( uint16_t  initSize,
unsigned long  initInterval 
)
inline

◆ FFXBase() [3/5]

FFXBase::FFXBase ( uint16_t  initSize,
uint8_t  initSpeed,
unsigned long  minRefresh,
unsigned long  maxRefresh 
)
inline

◆ FFXBase() [4/5]

FFXBase::FFXBase ( uint16_t  initSize,
uint8_t  initSpeed 
)
inline

◆ FFXBase() [5/5]

FFXBase::FFXBase ( uint16_t  initSize)

Member Function Documentation

◆ addOffsetWithWrap()

uint16_t FFXBase::addOffsetWithWrap ( uint16_t  index,
uint16_t  offset 
)
inline

◆ alphaBlend() [1/3]

CRGB FFXBase::alphaBlend ( CRGB &  a,
CRGB &  b,
uint8_t  alpha,
FadeType  ftUp = LINEAR,
FadeType  ftDown = LINEAR 
)
static

◆ alphaBlend() [2/3]

static void FFXBase::alphaBlend ( CRGB *  a,
CRGB *  b,
CRGB *  dest,
uint16_t  num,
uint8_t  alpha,
FadeType  ftUp = LINEAR,
FadeType  ftDown = LINEAR 
)
inlinestatic

◆ alphaBlend() [3/3]

static uint8_t FFXBase::alphaBlend ( uint8_t  a,
uint8_t  b,
uint8_t  alpha 
)
inlinestatic

◆ cycleEnd()

void FFXBase::cycleEnd ( CRGB *  currFrame)
inline

◆ cycleStart()

void FFXBase::cycleStart ( CRGB *  currFrame)
inline

◆ fadeMethodStr()

String FFXBase::fadeMethodStr ( FadeType  value)
static

◆ freeze()

void FFXBase::freeze ( )
inline

◆ getColor()

CRGB FFXBase::getColor ( )
inline

◆ getCurrCycle()

unsigned long FFXBase::getCurrCycle ( )
inline

◆ getCurrMovement()

FFXBase::MovementType FFXBase::getCurrMovement ( uint16_t  cycle)

Returns the current movement resulting from the MovementType setting - only differs from getMovement when using back and forth movement - this will return the current direction

◆ getCurrPhase()

uint16_t FFXBase::getCurrPhase ( )
inline

◆ getCurrVCycle()

unsigned long FFXBase::getCurrVCycle ( )
inline

◆ getCurrVPhase()

uint16_t FFXBase::getCurrVPhase ( )
inline

◆ getFXColor()

FFXColor& FFXBase::getFXColor ( )
inline

◆ getFXID()

uint8_t FFXBase::getFXID ( )
inline

◆ getFXName()

String FFXBase::getFXName ( )
inline

◆ getMovement()

MovementType FFXBase::getMovement ( )
inline

◆ getMovementPhase()

uint16_t FFXBase::getMovementPhase ( )

◆ getMovementVPhase()

uint16_t FFXBase::getMovementVPhase ( )

◆ getNextPhase()

uint16_t FFXBase::getNextPhase ( )
inline

◆ getNextVPhase()

uint16_t FFXBase::getNextVPhase ( )
inline

◆ getNumLeds()

uint16_t FFXBase::getNumLeds ( )
inline

◆ getPrevPhase()

uint16_t FFXBase::getPrevPhase ( )
inline

◆ getPrevVphase()

uint16_t FFXBase::getPrevVphase ( )
inline

◆ getVCycleRange()

uint16_t FFXBase::getVCycleRange ( )
inline

◆ initialize()

void FFXBase::initialize ( uint16_t  initSize)

◆ initLeds()

virtual void FFXBase::initLeds ( CRGB *  bufLeds)
inlinevirtual

◆ isFrozen()

bool FFXBase::isFrozen ( )
inline

◆ isUpdated()

boolean FFXBase::isUpdated ( )
inline

◆ mirror() [1/2]

uint16_t FFXBase::mirror ( uint16_t  index)
inline

◆ mirror() [2/2]

static uint16_t FFXBase::mirror ( uint16_t  index,
uint16_t  range 
)
inlinestatic

◆ movementTypeStr()

String FFXBase::movementTypeStr ( MovementType  mvt)
static

◆ onBrightness()

virtual void FFXBase::onBrightness ( uint8_t  newBrightness)
inlinevirtual

Reimplemented in DimUsingPaletteFX.

◆ onCycleEnd()

virtual void FFXBase::onCycleEnd ( CRGB *  currFrame)
inlinevirtual

◆ onCycleStart()

virtual void FFXBase::onCycleStart ( CRGB *  currFrame)
inlinevirtual

◆ onEachSecond()

virtual void FFXBase::onEachSecond ( unsigned long  secsRunning)
inlinevirtual

◆ onVCycleEnd()

virtual void FFXBase::onVCycleEnd ( CRGB *  currFrame)
inlinevirtual

Reimplemented in FFXOverlay.

◆ onVCycleStart()

virtual void FFXBase::onVCycleStart ( CRGB *  currFrame)
inlinevirtual

Reimplemented in ZipOverlayFX.

◆ rotateBackward()

void FFXBase::rotateBackward ( CRGB *  bufLeds,
uint16_t  steps 
)
inline

◆ rotateBufferBackwardWithWrap()

static void FFXBase::rotateBufferBackwardWithWrap ( CRGB *  source,
CRGB *  dest,
uint16_t  numLeds,
uint16_t  steps 
)
inlinestatic

◆ rotateBufferForwardWithWrap()

void FFXBase::rotateBufferForwardWithWrap ( CRGB *  source,
CRGB *  dest,
uint8_t  numLeds,
uint8_t  steps 
)
static

◆ rotateForward()

void FFXBase::rotateForward ( CRGB *  bufLeds,
uint16_t  steps 
)
inline

◆ setColor()

void FFXBase::setColor ( CRGB  newColor)
virtual

Reimplemented in FFXRotate.

◆ setFXColor()

void FFXBase::setFXColor ( FFXColor newColor)
inline

◆ setInterval()

virtual void FFXBase::setInterval ( unsigned long  newInterval)
inlineoverridevirtual

Reimplemented from FlexTimer.

◆ setMovement()

void FFXBase::setMovement ( MovementType  newMovement)
inline

◆ setUpdated()

void FFXBase::setUpdated ( boolean  newValue)
inline

◆ setVCycleRange()

uint16_t FFXBase::setVCycleRange ( uint16_t  newRange)
inline

◆ subtractOffsetWithWrap()

uint16_t FFXBase::subtractOffsetWithWrap ( uint16_t  index,
uint16_t  offset 
)
inline

◆ timingDelta() [1/2]

virtual int FFXBase::timingDelta ( uint8_t  phase,
unsigned long  sourceMillis 
)
inlinevirtual

◆ timingDelta() [2/2]

int FFXBase::timingDelta ( unsigned long  sourceMillis)
inline

◆ unFreeze()

void FFXBase::unFreeze ( )
inline

◆ update()

void FFXBase::update ( CRGB *  frameBuffer)

◆ vCycleEnd()

void FFXBase::vCycleEnd ( CRGB *  currFrame)
inline

◆ vCycleStart()

void FFXBase::vCycleStart ( CRGB *  currFrame)
inline

◆ whileFrozen()

virtual void FFXBase::whileFrozen ( CRGB *  currFrame)
inlinevirtual

Reimplemented in FFXOverlay.

◆ writeNextFrame()

virtual void FFXBase::writeNextFrame ( CRGB *  frameBuffer)
pure virtual

Member Data Documentation

◆ changed

bool FFXBase::changed = true
protected

◆ currColor

FFXColor FFXBase::currColor = FFXColor()
protected

◆ currCycle

unsigned long FFXBase::currCycle = 1
protected

◆ currMovement

MovementType FFXBase::currMovement = MVT_FORWARD
protected

◆ currPhase

uint16_t FFXBase::currPhase = 1
protected

◆ currVCycle

unsigned long FFXBase::currVCycle = 1
protected

◆ currVPhase

uint16_t FFXBase::currVPhase = 1
protected

◆ defaultFrameRefresh

unsigned long FFXBase::defaultFrameRefresh = 50
protected

◆ frozen

bool FFXBase::frozen = false
protected

◆ fxid

uint8_t FFXBase::fxid = 0
protected

◆ fxName

String FFXBase::fxName = ""
protected

◆ initialized

bool FFXBase::initialized = false
protected

◆ numLeds

uint16_t FFXBase::numLeds
protected

◆ secondsElapsed

unsigned long FFXBase::secondsElapsed = 0
protected

◆ vCycleRange

uint16_t FFXBase::vCycleRange
protected