HitLib 1.5.0
VEX V5 LED animation library for PROS
Loading...
Searching...
No Matches
led_sequencer.hpp
Go to the documentation of this file.
1#pragma once
2#include <cstdint>
3
8
9namespace hitlib {
10
11class LedStrand;
12
13// ============================================================================
14
49class Sequencer {
50public:
52 static constexpr uint8_t MAX_STRANDS = 8;
53
54 // ------------------------------------------------------------------------
55
59 struct Phase {
60 uint32_t durationMs;
61 void (*startFn)(LedStrand&);
62 };
63
64 // ------------------------------------------------------------------------
65
73 constexpr Sequencer(const Phase* phases, uint8_t count)
74 : phases(phases), phaseCount(count) {}
75
76 // ------------------------------------------------------------------------
77
92 void start(LedStrand& strand);
93
100 void stop();
101
103 void stop(const LedStrand& strand);
104
114 void update(LedStrand& strand);
115
119 bool isRunning() const;
120
122 bool isRunning(const LedStrand& strand) const;
123
124private:
126 struct Run {
127 const LedStrand* strand;
128 uint32_t phaseStartMs;
129 uint32_t lastTouch;
130 uint8_t phase;
131 };
132
133 const Phase* phases;
134 uint8_t phaseCount;
135 Run runs[MAX_STRANDS] = {};
136 uint32_t touches = 0;
137
138 int8_t indexOf(const LedStrand& strand) const;
139};
140
141} // namespace hitlib
Driver for a single WS2812B-compatible LED strip on a VEX ADI port.
Definition led_strand.hpp:53
void stop()
Stop the sequence on every strand without advancing.
bool isRunning() const
Returns true if the sequence is running on any strand.
static constexpr uint8_t MAX_STRANDS
Strands one Sequencer can run on at the same time.
Definition led_sequencer.hpp:52
void update(LedStrand &strand)
Advance the sequence, call every tick from an onTick callback.
void start(LedStrand &strand)
Start the sequence on strand from phase 0.
bool isRunning(const LedStrand &strand) const
Returns true if the sequence is running on strand.
constexpr Sequencer(const Phase *phases, uint8_t count)
Construct a Sequencer from a static phase array.
Definition led_sequencer.hpp:73
void stop(const LedStrand &strand)
Stop the sequence on strand only. See stop().
Definition led_group.hpp:12
One phase in the animation sequence.
Definition led_sequencer.hpp:59
void(* startFn)(LedStrand &)
Called once when the phase begins.
Definition led_sequencer.hpp:61
uint32_t durationMs
How long this phase runs (milliseconds).
Definition led_sequencer.hpp:60