HitLib 1.5.0
VEX V5 LED animation library for PROS
Loading...
Searching...
No Matches
hitlib::Sequencer Class Reference

Forward declaration. More...

#include <led_sequencer.hpp>

Classes

struct  Phase
 One phase in the animation sequence. More...

Public Member Functions

constexpr Sequencer (const Phase *phases, uint8_t count)
 Construct a Sequencer from a static phase array.
void start (LedStrand &strand)
 Start the sequence on strand from phase 0.
void stop ()
 Stop the sequence on every strand without advancing.
void stop (const LedStrand &strand)
 Stop the sequence on strand only. See stop().
void update (LedStrand &strand)
 Advance the sequence, call every tick from an onTick callback.
bool isRunning () const
 Returns true if the sequence is running on any strand.
bool isRunning (const LedStrand &strand) const
 Returns true if the sequence is running on strand.

Static Public Attributes

static constexpr uint8_t MAX_STRANDS
 Strands one Sequencer can run on at the same time.

Detailed Description

Forward declaration.

Drives a looping sequence of timed animation phases on a LedStrand.

A Sequencer holds a pointer to a statically-allocated array of Phase descriptors, and keeps each strand's place in it separately: one Sequencer can run on several strands at once, each at its own phase. That is what a profile attached to a whole LedGroup needs, since every strand in the group calls the same onActivate and onTick, and so the same Sequencer. Up to MAX_STRANDS strands can run at a time; see start() for what happens past that.

Typical usage inside a Profile

static void phase1(hitlib::LedStrand& s) { s.flash(0xFFFF00, 150, 150); }
static void phase2(hitlib::LedStrand& s) { s.rainbow(2); }
static const hitlib::Sequencer::Phase egPhases[] = {
{2000, phase1},
{8000, phase2},
};
static hitlib::Sequencer endgameSeq(egPhases, 2);
static void egActivate(hitlib::LedStrand& s) { endgameSeq.start(s); }
static void egTick (hitlib::LedStrand& s) { endgameSeq.update(s); }
static const hitlib::ProfileMode modes[] = {
{"Endgame", 100, egActivate, egTick},
};
Driver for a single WS2812B-compatible LED strip on a VEX ADI port.
Definition led_strand.hpp:53
void flash(uint32_t color, uint32_t onMs, uint32_t offMs, uint32_t bgColor=0x000000)
Blink the whole strip on and off.
void rainbow(Speed speed)
Scroll a full HSV rainbow across the strip.
One phase in the animation sequence.
Definition led_sequencer.hpp:59
Note
start(), update() and stop() may be called from different tasks, as they are when two groups share a profile. The phases' startFn runs with no lock held, so it is free to call any LedStrand method.

Constructor & Destructor Documentation

◆ Sequencer()

hitlib::Sequencer::Sequencer ( const Phase * phases,
uint8_t count )
inlineconstexpr

Construct a Sequencer from a static phase array.

Parameters
phasesPointer to a statically-allocated Phase array. Must remain valid for the lifetime of the Sequencer.
countNumber of elements in phases.

Member Function Documentation

◆ start()

void hitlib::Sequencer::start ( LedStrand & strand)

Start the sequence on strand from phase 0.

Calls phases[0].startFn(strand) immediately. Typically called from a ProfileMode onActivate callback. Restarts strand's run if it already has one, and leaves every other strand's alone.

With MAX_STRANDS strands already running, the one that has gone longest without an update() - normally one whose mode has since been replaced - gives its place up to strand, and stops.

Parameters
strandThe strand to animate.

◆ stop() [1/2]

void hitlib::Sequencer::stop ( )

Stop the sequence on every strand without advancing.

The strands' animations are not changed, they simply stop being updated.

◆ stop() [2/2]

void hitlib::Sequencer::stop ( const LedStrand & strand)

Stop the sequence on strand only. See stop().

◆ update()

void hitlib::Sequencer::update ( LedStrand & strand)

Advance the sequence, call every tick from an onTick callback.

Checks whether strand's current phase has expired. If so, advances it to the next phase (wrapping to 0) and calls that phase's startFn. Does nothing if the sequence is not running on strand.

Parameters
strandThe strand to animate.

◆ isRunning() [1/2]

bool hitlib::Sequencer::isRunning ( ) const

Returns true if the sequence is running on any strand.

◆ isRunning() [2/2]

bool hitlib::Sequencer::isRunning ( const LedStrand & strand) const

Returns true if the sequence is running on strand.

Member Data Documentation

◆ MAX_STRANDS

uint8_t hitlib::Sequencer::MAX_STRANDS
staticconstexpr

Strands one Sequencer can run on at the same time.