4#include "pros/rtos.hpp"
236 LedStrand(uint8_t adiPort, uint8_t length, uint32_t refreshMs = 20);
246 LedStrand(uint8_t smartPort, uint8_t adiPort, uint8_t length, uint32_t refreshMs = 20);
302 void pulse(uint32_t color, uint8_t runLength, uint8_t speed,
303 uint32_t bgColor = 0x000000,
bool invert =
false,
bool bounce =
false);
321 void flash(uint32_t color, uint32_t onMs, uint32_t offMs, uint32_t bgColor = 0x000000);
334 void flow(uint32_t color1, uint32_t color2, uint8_t speed,
bool invert =
false,
335 bool seamless =
true);
355 void twinkle(
const std::vector<uint32_t>& colors, uint8_t densityPct = 30,
356 uint8_t fadeStep = 16, uint32_t bgColor = 0x000000);
371 void bitscroll(
const std::vector<BitScrollSegment>& segments, uint8_t speed,
372 bool invert =
false, uint32_t bgColor = 0x000000,
bool bounce =
false,
373 uint8_t spacing = 5,
bool repeating =
true);
422 void levelFill(uint32_t color, uint32_t color2 = 0x000000,
bool gradient =
false,
423 uint32_t bgColor = 0x000000,
bool invert =
false);
489 uint8_t smoothing = 0);
528 bool gradient =
false, uint32_t bgColor = 0x000000,
bool invert =
false,
529 uint8_t sensitivity = 100,
bool loop =
false);
546 bool musicPlaying()
const {
return musicTrack !=
nullptr && !musicPaused; }
585 void spliceMask(uint8_t sections,
bool invert =
false,
bool alternating =
false,
586 uint32_t altPeriodMs = 100, uint32_t bgColor = 0x000000,
587 bool useOverlay =
false);
683 uint32_t bgColor = 0x000000);
687 uint32_t bgColor = 0x000000);
695 void overlayFlow(uint32_t color1, uint32_t color2, uint8_t speed,
bool seamless =
true);
701 void overlayTwinkle(
const std::vector<uint32_t>& colors, uint8_t densityPct = 30,
702 uint8_t fadeStep = 16, uint32_t bgColor = 0x000000);
712 bool invert =
false, uint32_t bgColor = 0x000000,
713 uint8_t spacing = 5,
bool repeating =
true);
803 uint8_t smartPort = 0;
806 pros::adi::Led* led =
nullptr;
809 enum class AnimMode : uint8_t { STATIC, SHIFT,
TWINKLE,
FLASH, LEVEL };
812 AnimMode animMode = AnimMode::STATIC;
814 uint8_t shiftVariant = 0;
815 std::vector<uint32_t> buffer;
818 uint8_t pulseRunLen = 0;
819 uint32_t pulseColor = 0;
820 uint32_t pulseBg = 0;
821 uint8_t pulseSpeed = 1;
822 int16_t pulseOffset = 0;
827 uint32_t flashColor = 0;
828 uint32_t flashBgColor = 0;
829 uint16_t flashOnTicks = 1;
830 uint16_t flashOffTicks = 1;
831 uint16_t flashCounter = 0;
832 bool flashLit =
true;
835 std::vector<uint32_t> bitscrollMaster;
836 int16_t bounceScrollPos = 0;
837 int8_t bounceScrollDir = 1;
838 uint8_t bounceSpeed = 1;
843 struct TwinkleState {
844 std::vector<uint8_t> level;
845 std::vector<uint8_t> target;
846 std::vector<uint8_t> colorIdx;
847 std::vector<uint8_t> holdTicks;
848 std::vector<uint32_t> palette;
849 uint8_t densityPct = 30;
850 uint8_t fadeStep = 16;
851 uint32_t bgColor = 0x000000;
853 void reset(uint8_t width,
const std::vector<uint32_t>& colors, uint8_t density,
854 uint8_t fade, uint32_t bg);
856 static void advanceTwinkleInto(TwinkleState& t, std::vector<uint32_t>& buf);
858 TwinkleState twinkleState;
863 uint8_t levelValue = 0;
864 uint32_t levelBg = 0x000000;
865 bool levelInvert =
false;
872 double levelEmptyAt = 0.0;
873 double levelFullAt = 100.0;
874 bool levelWrap =
false;
875 uint8_t levelSmooth = 0;
876 bool levelPrimed =
false;
881 const MusicTrack* musicTrack =
nullptr;
882 uint32_t musicAnchorMs = 0;
883 uint32_t musicPausedAt = 0;
884 bool musicPaused =
false;
885 bool musicLoop =
false;
886 uint8_t musicSensitivity = 100;
889 enum class SpliceMode : uint8_t { SPLIT, CUSTOM };
894 struct SpliceRegionState {
896 std::vector<uint32_t> buffer;
898 uint8_t shiftSpeed = 0;
907 double levelEmptyAt = 0.0;
908 double levelFullAt = 100.0;
909 bool levelWrap =
false;
910 uint8_t levelSmooth = 0;
911 uint8_t levelValue = 0;
912 bool levelPrimed =
false;
913 bool gaugeInvert =
false;
916 uint32_t gaugeBg = 0x000000;
919 std::vector<std::pair<uint8_t, uint32_t>> gaugeStops;
922 bool flashing =
false;
923 uint32_t flashColor = 0;
924 uint32_t flashBgColor = 0;
925 uint16_t flashOnTicks = 1;
926 uint16_t flashOffTicks = 1;
927 uint16_t flashCounter = 0;
928 bool flashLit =
true;
931 bool twinkling =
false;
932 TwinkleState twinkle;
935 bool spliceActive =
false;
936 SpliceMode spliceMode = SpliceMode::SPLIT;
937 uint8_t spliceSections = 0;
938 bool spliceInvert =
false;
939 bool spliceAlternating =
false;
940 uint32_t spliceAltMs = 100;
941 uint32_t spliceBgColor = 0x000000;
942 bool spliceUseOverlay =
false;
943 bool spliceAltPhase =
false;
944 uint32_t spliceLastToggleMs = 0;
945 std::vector<bool> spliceShowAnim;
946 std::vector<uint32_t> splicePixelBg;
947 std::vector<bool> splicePixelUseOverlay;
948 std::vector<int16_t> splicePixelRegionIdx;
949 std::vector<SpliceRegionState> spliceRegions;
954 uint32_t spliceGeneration = 0;
957 AnimMode overlayAnimMode = AnimMode::STATIC;
958 int overlayShiftStep = 0;
959 uint8_t overlayShiftSpeed = 0;
960 std::vector<uint32_t> overlayBuffer;
963 uint32_t overlayFlashColor = 0;
964 uint32_t overlayFlashBgColor = 0;
965 uint16_t overlayFlashOnTicks = 1;
966 uint16_t overlayFlashOffTicks = 1;
967 uint16_t overlayFlashCounter = 0;
968 bool overlayFlashLit =
true;
971 TwinkleState overlayTwinkleState;
974 uint8_t brightnessPct = 100;
982 const Profile* activeProfile =
nullptr;
983 std::vector<ModeEntry> modeStack;
984 int16_t lastModeIdx = -1;
987 void setColorNL(uint32_t color);
988 void pulseNL(uint32_t color, uint8_t runLen, uint8_t speed, uint32_t bg,
bool invert,
bool bounce);
989 void flashNL(uint32_t color, uint32_t onMs, uint32_t offMs, uint32_t bg);
990 void flowNL(uint32_t c1, uint32_t c2, uint8_t speed,
bool invert,
bool seamless);
991 void rainbowNL(uint8_t speed);
992 void twinkleNL(
const std::vector<uint32_t>& colors, uint8_t densityPct,
993 uint8_t fadeStep, uint32_t bgColor);
994 void bitscrollNL(
const std::vector<BitScrollSegment>& segments, uint8_t speed,
bool invert,
995 uint32_t bgColor,
bool bounce, uint8_t spacing,
bool repeating);
997 void overlaySetColorNL(uint32_t color);
998 void overlayPulseNL(uint32_t color, uint8_t runLen, uint8_t speed, uint32_t bg);
999 void overlayFlashNL(uint32_t color, uint32_t onMs, uint32_t offMs, uint32_t bg);
1000 void overlayFlowNL(uint32_t c1, uint32_t c2, uint8_t speed,
bool seamless);
1001 void overlayRainbowNL(uint8_t speed);
1002 void overlayTwinkleNL(
const std::vector<uint32_t>& colors, uint8_t densityPct,
1003 uint8_t fadeStep, uint32_t bgColor);
1004 void overlayBitscrollNL(
const std::vector<BitScrollSegment>& segments, uint8_t speed,
1005 bool invert, uint32_t bgColor, uint8_t spacing,
bool repeating);
1007 void levelFillNL(uint32_t color, uint32_t color2,
bool gradient, uint32_t bg,
bool invert);
1012 static std::vector<uint32_t> buildBitscrollUnit(
const std::vector<BitScrollSegment>& segments,
1013 uint32_t bgColor, uint8_t spacing,
1014 size_t& contentLen);
1018 static uint8_t fillBitscrollBuffer(std::vector<uint32_t>& buf,
1019 const std::vector<uint32_t>& unit,
size_t contentLen,
1020 uint8_t width, uint32_t bgColor, uint8_t speed,
1021 bool invert,
bool repeating);
1023 void advanceLevel();
1024 void advanceFlash();
1025 void advanceOverlayFlash();
1026 void advancePulseBounce();
1027 void advanceBitscrollBounce();
1028 void fillBitscrollFromMaster();
1029 void advanceSpliceAlternating(uint32_t nowMs);
1030 void advanceSpliceRegions();
1031 void paintGaugeRegion(SpliceRegionState& state);
1032 void rebuildSpliceMask();
1035 void shiftOverlayBuffer();
1037 uint32_t levelPixel(uint8_t i, uint32_t full, uint8_t frac)
const;
1038 uint8_t sampleMusicNL(uint32_t positionMs)
const;
1039 uint8_t mapLevelNL(
double raw)
const;
1040 uint8_t smoothLevelNL(uint8_t target)
const;
1044 static uint8_t mapLevelTo(
double raw,
double emptyAt,
double fullAt,
bool wrap);
1045 static uint8_t smoothLevelTo(uint8_t target, uint8_t current, uint8_t smoothing,
bool wrap);
1046 static uint32_t gaugeColorAt(
const SpliceRegionState& state, uint8_t level);
1048 int16_t computeEffectiveMode()
const;
1049 void pruneExpired(uint32_t now);
1050 uint32_t applyBrightness(uint32_t color)
const;
1051 uint16_t msToTicks(uint32_t ms)
const;
1053 static std::vector<uint32_t> genGradient(uint32_t c1, uint32_t c2, uint8_t len,
1054 bool seamless =
false);
1055 static std::vector<uint32_t> genRainbow(uint8_t len);
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.
void overlayBitscroll(const std::vector< BitScrollSegment > &segments, uint8_t speed, bool invert=false, uint32_t bgColor=0x000000, uint8_t spacing=5, bool repeating=true)
Scroll a repeating bit pattern in the overlay buffer (see bitscroll()).
LedStrand(uint8_t smartPort, uint8_t adiPort, uint8_t length, uint32_t refreshMs=20)
Construct a strand on an ADI expander port.
void flash(uint32_t color, uint32_t onMs, uint32_t offMs, uint32_t bgColor=0x000000)
Blink the whole strip on and off.
void overlayRainbow(uint8_t speed)
Scroll a rainbow in the overlay buffer.
SpliceRegionAnimKind
What a custom splice mask region shows.
Definition led_strand.hpp:103
@ BITSCROLL
Definition led_strand.hpp:104
@ FLASH
Definition led_strand.hpp:104
@ FLOW
Definition led_strand.hpp:104
@ PULSE
Definition led_strand.hpp:104
@ TWINKLE
Definition led_strand.hpp:104
@ GAUGE
Definition led_strand.hpp:104
@ OFF
Definition led_strand.hpp:104
@ SOLID
Definition led_strand.hpp:104
@ RAINBOW
Definition led_strand.hpp:104
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 detachProfile()
Detach the active profile and turn the strand off.
void musicSeek(uint32_t positionMs)
Jump playback to a position in the song.
void spliceMaskCustom(const std::vector< SpliceRegion > ®ions)
Apply a splice mask made of independently placed/sized regions, each running its own animation.
void setSensitivity(uint8_t pct)
Change the gain applied to envelope samples without restarting.
void tick()
Advance one animation frame.
LedStrand(uint8_t adiPort, uint8_t length, uint32_t refreshMs=20)
Construct a strand on a standard ADI port.
void rainbow(uint8_t speed)
Scroll a full HSV rainbow across the strip.
uint32_t musicPositionMs() const
Current playback position in milliseconds.
void overlaySetColor(uint32_t color)
Set the overlay buffer to a solid color.
void setBrightness(uint8_t pct)
Set global brightness for this strand.
void attachProfile(const Profile *profile)
Attach a Profile and reset the mode stack.
void musicSync(const 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 flow(uint32_t color1, uint32_t color2, uint8_t speed, bool invert=false, bool seamless=true)
Scroll a two-color gradient across the strip.
bool levelSourceActive() const
Whether a levelSource() reader is currently driving the meter.
Definition led_strand.hpp:500
void setLevel(uint8_t level)
Set how full the meter is.
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.
static SpliceRegion motorHeatGauge(uint8_t start, uint8_t width, LevelFn read=nullptr)
A GAUGE region pre-loaded with the V5 motor's own heat schedule.
void init()
Initialize the hardware LED object.
void overlayFlow(uint32_t color1, uint32_t color2, uint8_t speed, bool seamless=true)
Scroll a gradient in the overlay buffer.
void clearSpliceMask()
Remove the active splice mask, whichever kind is active.
void deactivateMode(uint8_t modeIdx)
Remove a mode from the stack immediately.
void bitscroll(const std::vector< BitScrollSegment > &segments, uint8_t 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 off()
Turn all LEDs off (set to black).
void pulse(uint32_t color, uint8_t runLength, uint8_t speed, uint32_t bgColor=0x000000, bool invert=false, bool bounce=false)
Animate a run of color moving across a background.
void activateModeTimed(uint8_t modeIdx, uint32_t durationMs)
Push a timed mode onto the mode stack.
uint8_t getBrightness() const
Return the current brightness percentage.
Definition led_strand.hpp:735
double(*)() LevelFn
Signature for the reader a fill meter follows, see levelSource().
Definition led_strand.hpp:90
void overlayTwinkle(const std::vector< uint32_t > &colors, uint8_t densityPct=30, uint8_t fadeStep=16, uint32_t bgColor=0x000000)
Sparkle random pixels of the overlay buffer (see twinkle()).
uint8_t getLength() const
Return the number of LEDs in this strand.
Definition led_strand.hpp:792
void clearLevelSource()
Stop following a levelSource() reader, leaving the fill where it is.
void activateMode(uint8_t modeIdx)
Push a persistent mode onto the mode stack.
void levelSource(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 setColor(uint32_t color)
Set all LEDs to a solid color.
void musicPause(bool paused=true)
Pause or resume playback, holding the meter where it is.
GaugeStyle
How a GAUGE region turns its level into pixels.
Definition led_strand.hpp:128
@ HEAT
The whole region shows one color, picked off the scale.
Definition led_strand.hpp:129
@ BAR
The region fills proportionally, like a miniature levelFill().
Definition led_strand.hpp:130
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 setRegionLevel(uint8_t regionIdx, uint8_t level)
Set how full a hand-driven GAUGE region is.
void overlayPulse(uint32_t color, uint8_t runLength, uint8_t speed, uint32_t bgColor=0x000000)
Animate a moving run in the overlay buffer.
bool musicPlaying() const
Whether a MusicTrack is attached and not paused.
Definition led_strand.hpp:546
static constexpr uint8_t MAX_LEDS
Definition led_strand.hpp:798
GaugeBlend
How a GAUGE region moves between two stops.
Definition led_strand.hpp:136
@ STEP
Hold each stop's color until the next one is reached.
Definition led_strand.hpp:138
@ LERP
Blend smoothly, so a rising reading slides between colors.
Definition led_strand.hpp:137
uint8_t getLevel() const
Return the meter's current level (0-255).
Definition led_strand.hpp:438
Profile and mode descriptors for the hitlib event-driven animation system.
Definition led_group.hpp:11
One color on a GAUGE region's scale.
Definition led_strand.hpp:120
uint32_t color
Color shown at that reading (0xRRGGBB).
Definition led_strand.hpp:122
double at
Reading this color belongs to, in the source's units.
Definition led_strand.hpp:121
A song's intensity envelope, baked ahead of time into one 8-bit sample per frame.
Definition led_strand.hpp:217
uint16_t frameCount
Number of samples in samples.
Definition led_strand.hpp:219
uint16_t frameMs
Milliseconds between consecutive samples.
Definition led_strand.hpp:220
const uint8_t * samples
Intensity 0-255, one entry per frame.
Definition led_strand.hpp:218
One independently placed override region for a custom splice mask.
Definition led_strand.hpp:149
bool wrap
Cycle past fullAt instead of pinning at it.
Definition led_strand.hpp:185
GaugeStyle style
Whole-region color, or a bar.
Definition led_strand.hpp:187
uint8_t fadeStep
Brightness step per tick, so bigger is faster.
Definition led_strand.hpp:170
uint32_t color
Foreground color (SOLID/PULSE/FLASH/FLOW/BITSCROLL).
Definition led_strand.hpp:153
uint32_t bgColor
PULSE/FLASH/TWINKLE/BITSCROLL background, and a GAUGE BAR's unlit part.
Definition led_strand.hpp:155
uint8_t speed
PULSE/FLOW/RAINBOW/BITSCROLL animation speed.
Definition led_strand.hpp:157
bool repeating
Tile the pattern across the region, or scroll one copy.
Definition led_strand.hpp:176
std::vector< GaugeStop > stops
The scale, in the reading's own units.
Definition led_strand.hpp:192
uint8_t start
First pixel index covered by this region.
Definition led_strand.hpp:150
bool invert
Reverse direction: a BITSCROLL scrolls the other way, a GAUGE BAR fills from the far end of the regio...
Definition led_strand.hpp:163
uint32_t color2
FLOW end color.
Definition led_strand.hpp:154
std::vector< uint32_t > palette
Colors sparks are drawn from. An empty palette leaves the region dark.
Definition led_strand.hpp:168
uint8_t spacing
Background pixels between runs.
Definition led_strand.hpp:175
bool seamless
FLOW only.
Definition led_strand.hpp:160
uint32_t onMs
FLASH lit duration (ms).
Definition led_strand.hpp:158
uint8_t segmentWidth
Pixels per lit run.
Definition led_strand.hpp:174
SpliceRegionAnimKind kind
What this region shows.
Definition led_strand.hpp:152
uint8_t smoothing
0-99, as in levelSource().
Definition led_strand.hpp:186
uint8_t densityPct
Share of the region lit at once (0-100).
Definition led_strand.hpp:169
double fullAt
Reading at the top of it.
Definition led_strand.hpp:184
double emptyAt
Reading at the bottom of the scale.
Definition led_strand.hpp:183
uint8_t width
Number of pixels covered.
Definition led_strand.hpp:151
uint8_t runLength
PULSE run length.
Definition led_strand.hpp:156
LevelFn read
Value this gauge follows, polled once per tick.
Definition led_strand.hpp:182
GaugeBlend blend
Blend between stops, or hold each.
Definition led_strand.hpp:188
uint32_t offMs
FLASH blank duration (ms).
Definition led_strand.hpp:159
An immutable, statically-allocated collection of ProfileMode entries.
Definition led_profile.hpp:68