HitLib 1.5.0
VEX V5 LED animation library for PROS
Loading...
Searching...
No Matches
led_group.hpp
Go to the documentation of this file.
1#pragma once
2#include "led_strand.hpp"
3#include "led_profile.hpp"
4#include <cstddef>
5#include <vector>
6
11
12namespace hitlib {
13
14// ============================================================================
15
43class LedGroup {
44public:
45
46 // ========================================================================
49
61 void add(LedStrand* strand);
62
78 void init(uint32_t refreshMs = 20);
79
92 void start();
93
95
96 // ========================================================================
101
103 void off();
104
106 void setColor(uint32_t color);
107
109 void pulse(uint32_t color, uint8_t runLength, LedStrand::Speed speed,
110 uint32_t bgColor = 0x000000, bool invert = false, bool bounce = false);
111
113 void flash(uint32_t color, uint32_t onMs, uint32_t offMs, uint32_t bgColor = 0x000000);
114
116 void flow(uint32_t color1, uint32_t color2, LedStrand::Speed speed, bool invert = false,
117 bool seamless = true);
118
121
123 void twinkle(const std::vector<uint32_t>& colors, uint8_t densityPct = 30,
124 uint8_t fadeStep = 16, uint32_t bgColor = 0x000000);
125
127 void bitscroll(const std::vector<LedStrand::BitScrollSegment>& segments, LedStrand::Speed speed,
128 bool invert = false, uint32_t bgColor = 0x000000, bool bounce = false,
129 uint8_t spacing = 5, bool repeating = true);
130
132 void levelFill(uint32_t color, uint32_t color2 = 0x000000, bool gradient = false,
133 uint32_t bgColor = 0x000000, bool invert = false);
134
136 void setLevel(uint8_t level);
137
139 void levelSource(LedStrand::LevelFn read, double emptyAt, double fullAt, bool wrap = false,
140 uint8_t smoothing = 0);
141
144
146 void musicSync(const LedStrand::MusicTrack& track, uint32_t color, uint32_t color2 = 0x000000,
147 bool gradient = false, uint32_t bgColor = 0x000000, bool invert = false,
148 uint8_t sensitivity = 100, bool loop = false);
149
151 void musicSeek(uint32_t positionMs);
152
154 void musicPause(bool paused = true);
155
157 void setSensitivity(uint8_t pct);
158
160 void spliceMask(uint8_t sections, bool invert = false, bool alternating = false,
161 uint32_t altPeriodMs = 100, uint32_t bgColor = 0x000000,
162 bool useOverlay = false);
163
165 void spliceMaskCustom(const std::vector<LedStrand::SpliceRegion>& regions);
166
169
171 void setBrightness(uint8_t pct);
172
174
175 // ========================================================================
178
180 void overlaySetColor(uint32_t color);
181
183 void overlayPulse(uint32_t color, uint8_t runLength, LedStrand::Speed speed,
184 uint32_t bgColor = 0x000000);
185
187 void overlayFlash(uint32_t color, uint32_t onMs, uint32_t offMs,
188 uint32_t bgColor = 0x000000);
189
191 void overlayFlow(uint32_t color1, uint32_t color2, LedStrand::Speed speed, bool seamless = true);
192
195
197
198 // ========================================================================
201
203 void attachProfile(const Profile* profile);
204
207
209 void activateMode(uint8_t modeIdx);
210
212 void activateModeTimed(uint8_t modeIdx, uint32_t durationMs);
213
215 void deactivateMode(uint8_t modeIdx);
216
218
219 // ========================================================================
222
232
236 size_t size() const;
237
239
240private:
241 std::vector<LedStrand*> strands;
242 uint32_t refreshMs = 20;
243 bool initialized = false;
244 bool started = false;
245 // Guards the fields above, so add() can run while the task is going round
246 // the strands. The task holds it only to copy the list, never across a
247 // tick. See the lock order in led_group.cpp.
248 mutable platform::Mutex mutex;
249
250 void groupTask();
251 static void taskEntry(void* group);
252
253 // Calls fn(strand) for every strand, holding the lock across the loop.
254 template <typename Fn>
255 void forEach(Fn fn) {
256 mutex.take();
257 for (LedStrand* s : strands) fn(*s);
258 mutex.give();
259 }
260};
261
262} // namespace hitlib
Owns a set of LedStrand pointers and fans all animation commands out to each strand simultaneously.
Definition led_group.hpp:43
void levelFill(uint32_t color, uint32_t color2=0x000000, bool gradient=false, uint32_t bgColor=0x000000, bool invert=false)
Configure the strip as a level meter, and take manual control of it.
void flow(uint32_t color1, uint32_t color2, LedStrand::Speed speed, bool invert=false, bool seamless=true)
Scroll a two-color gradient across the strip.
void setBrightness(uint8_t pct)
Set global brightness for this strand.
void overlayFlow(uint32_t color1, uint32_t color2, LedStrand::Speed speed, bool seamless=true)
Scroll a gradient in the overlay buffer.
void overlaySetColor(uint32_t color)
Set the overlay buffer to a solid color.
void twinkle(const std::vector< uint32_t > &colors, uint8_t densityPct=30, uint8_t fadeStep=16, uint32_t bgColor=0x000000)
Spawn randomly fading sparkles from a color palette.
void overlayPulse(uint32_t color, uint8_t runLength, LedStrand::Speed speed, uint32_t bgColor=0x000000)
Animate a moving run in the overlay buffer.
LedStrand * operator[](size_t i)
Access an individual strand by index.
void levelSource(LedStrand::LevelFn read, double emptyAt, double fullAt, bool wrap=false, uint8_t smoothing=0)
Point the meter at a live value and let it follow it on its own.
void musicSync(const LedStrand::MusicTrack &track, uint32_t color, uint32_t color2=0x000000, bool gradient=false, uint32_t bgColor=0x000000, bool invert=false, uint8_t sensitivity=100, bool loop=false)
Fill the meter from a baked music envelope, and start playing it.
void setColor(uint32_t color)
Set all LEDs to a solid color.
void off()
Turn all LEDs off (set to black).
void overlayFlash(uint32_t color, uint32_t onMs, uint32_t offMs, uint32_t bgColor=0x000000)
Blink the overlay buffer on and off (see flash()).
void spliceMask(uint8_t sections, bool invert=false, bool alternating=false, uint32_t altPeriodMs=100, uint32_t bgColor=0x000000, bool useOverlay=false)
Apply a splice mask that overrides alternating equal-width bins.
size_t size() const
Return the number of strands in this group.
void overlayRainbow(LedStrand::Speed speed)
Scroll a rainbow in the overlay buffer.
void rainbow(LedStrand::Speed speed)
Scroll a full HSV rainbow across the strip.
void add(LedStrand *strand)
Register a strand with this group.
void init(uint32_t refreshMs=20)
Initialize hardware on all registered strands.
void pulse(uint32_t color, uint8_t runLength, LedStrand::Speed speed, uint32_t bgColor=0x000000, bool invert=false, bool bounce=false)
Animate a run of color moving across a background.
void bitscroll(const std::vector< LedStrand::BitScrollSegment > &segments, LedStrand::Speed speed, bool invert=false, uint32_t bgColor=0x000000, bool bounce=false, uint8_t spacing=5, bool repeating=true)
Scroll a pattern of colored segments across the strip.
void spliceMaskCustom(const std::vector< LedStrand::SpliceRegion > &regions)
Apply a splice mask made of independently placed/sized regions, each running its own animation.
void setLevel(uint8_t level)
Set how full the meter is.
void attachProfile(const Profile *profile)
Attach a Profile and reset the mode stack.
void setSensitivity(uint8_t pct)
Change the gain applied to envelope samples without restarting.
void start()
Start the group refresh task.
void clearSpliceMask()
Remove the active splice mask, whichever kind is active.
void activateModeTimed(uint8_t modeIdx, uint32_t durationMs)
Push a timed mode onto the mode stack.
void musicPause(bool paused=true)
Pause or resume playback, holding the meter where it is.
void detachProfile()
Detach the active profile and turn the strand off.
void clearLevelSource()
Stop following a levelSource() reader, leaving the fill where it is.
void musicSeek(uint32_t positionMs)
Jump playback to a position in the song.
void flash(uint32_t color, uint32_t onMs, uint32_t offMs, uint32_t bgColor=0x000000)
Blink the whole strip on and off.
void deactivateMode(uint8_t modeIdx)
Remove a mode from the stack immediately.
void activateMode(uint8_t modeIdx)
Push a persistent mode onto the mode stack.
Driver for a single WS2812B-compatible LED strip on a VEX ADI port.
Definition led_strand.hpp:53
double(*)() LevelFn
Signature for the reader a fill meter follows, see levelSource().
Definition led_strand.hpp:138
Non-recursive mutex, blocking take.
Definition platform.hpp:80
Profile and mode descriptors for the hitlib event-driven animation system.
Single addressable LED strip driver with layered animation engine.
Definition led_group.hpp:12
A song's intensity envelope, baked ahead of time into one 8-bit sample per frame.
Definition led_strand.hpp:267
How fast a moving animation travels: so many pixels, so often.
Definition led_strand.hpp:101
An immutable, statically-allocated collection of ProfileMode entries.
Definition led_profile.hpp:68