From 64bc716c747ab8183cf84b1f240d25e0d6d5e5bb Mon Sep 17 00:00:00 2001 From: Shane Aronson Date: Fri, 22 Nov 2024 16:07:02 -0800 Subject: [PATCH] Pattern Fixes for spark, some are core --- VortexEngine/src/Leds/LedTypes.h | 5 ++++ VortexEngine/src/Leds/Leds.cpp | 24 ++++++++++------ VortexEngine/src/Menus/Menu.cpp | 9 ++++++ .../src/Patterns/Multi/FillPattern.cpp | 6 ++-- .../src/Patterns/Multi/HueShiftPattern.cpp | 16 ++++++++--- .../src/Patterns/Multi/PulsishPattern.cpp | 18 ++++++------ .../src/Patterns/Multi/SnowballPattern.cpp | 2 +- .../Patterns/Multi/SparkleTracePattern.cpp | 11 ++++++-- .../src/Patterns/Multi/SparkleTracePattern.h | 1 + .../Patterns/Multi/TheaterChasePattern.cpp | 18 ++++++------ .../src/Patterns/Multi/VortexPattern.cpp | 8 ++++-- .../src/Patterns/Multi/VortexWipePattern.cpp | 28 +++++++------------ .../src/Patterns/Multi/WarpPattern.cpp | 4 +-- .../src/Patterns/Multi/WarpWormPattern.cpp | 2 +- .../src/Patterns/Multi/ZigzagPattern.cpp | 16 ++++++----- 15 files changed, 102 insertions(+), 66 deletions(-) diff --git a/VortexEngine/src/Leds/LedTypes.h b/VortexEngine/src/Leds/LedTypes.h index c9954295dc..4671b53402 100644 --- a/VortexEngine/src/Leds/LedTypes.h +++ b/VortexEngine/src/Leds/LedTypes.h @@ -161,6 +161,11 @@ inline LedPos ledmapGetNextLed(LedMap map, LedPos pos) #define MAP_PAIR_EVEN_EVENS (MAP_PAIR_EVEN(PAIR_3) | MAP_PAIR_EVEN(PAIR_1)) #define MAP_PAIR_EVEN_ODDS (MAP_PAIR_ODD(PAIR_3) | MAP_PAIR_ODD(PAIR_1)) +// bitmaps specific to Sparks +#define MAP_OPPOSITES_1 (MAP_LED(LED_0) | MAP_LED(LED_3)) +#define MAP_OPPOSITES_2 (MAP_LED(LED_1) | MAP_LED(LED_4)) +#define MAP_OPPOSITES_3 (MAP_LED(LED_2) | MAP_LED(LED_5)) + // set a single led inline void ledmapSetLed(LedMap &map, LedPos pos) { diff --git a/VortexEngine/src/Leds/Leds.cpp b/VortexEngine/src/Leds/Leds.cpp index 52765557b3..55e46d0edb 100644 --- a/VortexEngine/src/Leds/Leds.cpp +++ b/VortexEngine/src/Leds/Leds.cpp @@ -91,8 +91,10 @@ void Leds::setRangeEvens(Pair first, Pair last, RGBColor col) void Leds::setAllEvens(RGBColor col) { - for (Pair pos = PAIR_FIRST; pos <= PAIR_LAST; pos++) { - setIndex(pairEven(pos), col); + for (LedPos pos = LED_FIRST; pos <= LED_LAST; pos++) { + if (pos % 2) { + setIndex(pos, col); + } } } @@ -105,8 +107,10 @@ void Leds::setRangeOdds(Pair first, Pair last, RGBColor col) void Leds::setAllOdds(RGBColor col) { - for (Pair pos = PAIR_FIRST; pos <= PAIR_LAST; pos++) { - setIndex(pairOdd(pos), col); + for (LedPos pos = LED_FIRST; pos <= LED_LAST; pos++) { + if (!(pos % 2)) { + setIndex(pos, col); + } } } @@ -119,8 +123,10 @@ void Leds::clearRangeEvens(Pair first, Pair last) void Leds::clearAllEvens() { - for (Pair pos = PAIR_FIRST; pos <= PAIR_LAST; pos++) { - clearIndex(pairEven(pos)); + for (LedPos pos = LED_FIRST; pos <= LED_LAST; pos++) { + if (pos % 2) { + clearIndex(pos); + } } } @@ -133,8 +139,10 @@ void Leds::clearRangeOdds(Pair first, Pair last) void Leds::clearAllOdds() { - for (Pair pos = PAIR_FIRST; pos <= PAIR_LAST; pos++) { - clearIndex(pairOdd(pos)); + for (LedPos pos = LED_FIRST; pos <= LED_LAST; pos++) { + if (!(pos % 2)) { + clearIndex(pos); + } } } diff --git a/VortexEngine/src/Menus/Menu.cpp b/VortexEngine/src/Menus/Menu.cpp index 44a5ca91cc..6e76e7a93c 100644 --- a/VortexEngine/src/Menus/Menu.cpp +++ b/VortexEngine/src/Menus/Menu.cpp @@ -140,6 +140,15 @@ void Menu::nextBulbSelection() m_targetLeds = MAP_PAIR_ODDS; break; case MAP_PAIR_ODDS: + m_targetLeds = MAP_OPPOSITES_1; + break; + case MAP_OPPOSITES_1: + m_targetLeds = MAP_OPPOSITES_2; + break; + case MAP_OPPOSITES_2: + m_targetLeds = MAP_OPPOSITES_3; + break; + case MAP_OPPOSITES_3: m_targetLeds = MAP_LED(LED_FIRST); break; case MAP_LED(LED_LAST): diff --git a/VortexEngine/src/Patterns/Multi/FillPattern.cpp b/VortexEngine/src/Patterns/Multi/FillPattern.cpp index 87e034e4c1..50a88eefa3 100644 --- a/VortexEngine/src/Patterns/Multi/FillPattern.cpp +++ b/VortexEngine/src/Patterns/Multi/FillPattern.cpp @@ -28,13 +28,13 @@ void FillPattern::init() void FillPattern::blinkOn() { - Leds::setPairs(PAIR_FIRST, (Pair)m_progress, m_colorset.peekNext()); - Leds::setPairs((Pair)m_progress, PAIR_COUNT, m_colorset.cur()); + Leds::setRange(LED_FIRST, (LedPos)m_progress, m_colorset.peekNext()); + Leds::setRange((LedPos)m_progress, LED_LAST, m_colorset.cur()); } void FillPattern::poststep() { - m_progress = (m_progress + 1) % PAIR_COUNT; + m_progress = (m_progress + 1) % LED_COUNT; if (m_progress == 0) { m_colorset.getNext(); } diff --git a/VortexEngine/src/Patterns/Multi/HueShiftPattern.cpp b/VortexEngine/src/Patterns/Multi/HueShiftPattern.cpp index d86a35810f..0a39133551 100644 --- a/VortexEngine/src/Patterns/Multi/HueShiftPattern.cpp +++ b/VortexEngine/src/Patterns/Multi/HueShiftPattern.cpp @@ -75,9 +75,17 @@ void HueShiftPattern::play() m_cur.hue += sign; } HSVColor showColor = HSVColor(m_cur.hue, 255, 255); - // set the target led with the current HSV color - for (LedPos pos = LED_FIRST; pos < LED_COUNT; ++pos) { - Leds::setIndex(pos, hsv_to_rgb_generic(showColor)); - showColor.hue = (showColor.hue + 5) % 256; + + // variable amount to shift, more LEDs should have smaller shifts + uint8_t shiftAmount = 108 / LED_COUNT; + // if you increment color with each led index there's a sharp contrast between the first and last led + // instead this creates a perfectly looped gradient between the first and last led which is better + for (LedPos pos = LED_FIRST; pos < (LED_COUNT / 2) + 1; ++pos) { + if (((LED_COUNT / 2) + pos) != LED_COUNT) { + // set the target led with the current HSV color + Leds::setIndex((LedPos)((LED_COUNT / 2) + pos), hsv_to_rgb_generic(showColor)); + } + Leds::setIndex((LedPos)((LED_COUNT / 2) - pos), hsv_to_rgb_generic(showColor)); + showColor.hue = (showColor.hue + shiftAmount) % 256; } } diff --git a/VortexEngine/src/Patterns/Multi/PulsishPattern.cpp b/VortexEngine/src/Patterns/Multi/PulsishPattern.cpp index 9c9e9b49b9..93c5fc6da6 100644 --- a/VortexEngine/src/Patterns/Multi/PulsishPattern.cpp +++ b/VortexEngine/src/Patterns/Multi/PulsishPattern.cpp @@ -55,16 +55,16 @@ void PulsishPattern::play() { // when the step timer triggers if (m_stepTimer.alarm() == 0) { - m_progress = (m_progress + 1) % PAIR_COUNT; + m_progress = (m_progress + 1) % LED_COUNT; } switch (m_blinkTimer.alarm()) { case -1: // just return return; case 0: // turn on the leds - for (Pair pair = PAIR_FIRST; pair < PAIR_COUNT; ++pair) { - if (pair != m_progress) { - Leds::setPair(pair, m_colorset.cur()); + for (LedPos pos = LED_FIRST; pos < LED_COUNT; ++pos) { + if (pos != m_progress) { + Leds::setIndex(pos, m_colorset.cur()); } } m_colorset.skip(); @@ -73,9 +73,9 @@ void PulsishPattern::play() } break; case 1: - for (Pair pair = PAIR_FIRST; pair < PAIR_COUNT; ++pair) { - if (pair != m_progress) { - Leds::clearPair(pair); + for (LedPos pos = LED_FIRST; pos < LED_COUNT; ++pos) { + if (pos != m_progress) { + Leds::clearIndex(pos); } } break; @@ -85,10 +85,10 @@ void PulsishPattern::play() case -1: // just return return; case 0: // turn on the leds - Leds::setPair((Pair)m_progress, m_colorset.get(0)); + Leds::setIndex((LedPos)m_progress, m_colorset.get(0)); break; case 1: - Leds::clearPair((Pair)m_progress); + Leds::clearIndex((LedPos)m_progress); break; } } diff --git a/VortexEngine/src/Patterns/Multi/SnowballPattern.cpp b/VortexEngine/src/Patterns/Multi/SnowballPattern.cpp index 32d7121c17..92667b4ca2 100644 --- a/VortexEngine/src/Patterns/Multi/SnowballPattern.cpp +++ b/VortexEngine/src/Patterns/Multi/SnowballPattern.cpp @@ -2,7 +2,7 @@ #include "../../Leds/Leds.h" -#define WORM_SIZE 6 +#define WORM_SIZE LED_COUNT / 3 SnowballPattern::SnowballPattern(const PatternArgs &args) : BlinkStepPattern(args), diff --git a/VortexEngine/src/Patterns/Multi/SparkleTracePattern.cpp b/VortexEngine/src/Patterns/Multi/SparkleTracePattern.cpp index 2221850d58..f2a778724b 100644 --- a/VortexEngine/src/Patterns/Multi/SparkleTracePattern.cpp +++ b/VortexEngine/src/Patterns/Multi/SparkleTracePattern.cpp @@ -21,10 +21,17 @@ void SparkleTracePattern::blinkOn() Leds::setAll(m_colorset.get(0)); } +void SparkleTracePattern::blinkOff() +{ + //this empty overriden function must be here to prevent the base + //blinkOff function from causing the ribbon in the blinkOn function + //to strobe instead +} + void SparkleTracePattern::poststep() { - for (uint8_t dot = 0; dot < 4; ++dot) { - Leds::setPair((Pair)m_randCtx.next8(PAIR_FIRST, PAIR_LAST), m_colorset.cur()); + for (uint8_t dot = 0; dot < LED_COUNT / 6; ++dot) { + Leds::setIndex((LedPos)m_randCtx.next8(LED_FIRST, LED_LAST), m_colorset.cur()); } m_colorset.skip(); if (m_colorset.curIndex() == 0) { diff --git a/VortexEngine/src/Patterns/Multi/SparkleTracePattern.h b/VortexEngine/src/Patterns/Multi/SparkleTracePattern.h index ef03a71827..13f8804021 100644 --- a/VortexEngine/src/Patterns/Multi/SparkleTracePattern.h +++ b/VortexEngine/src/Patterns/Multi/SparkleTracePattern.h @@ -13,6 +13,7 @@ class SparkleTracePattern : public BlinkStepPattern protected: virtual void blinkOn() override; + virtual void blinkOff() override; virtual void poststep() override; Random m_randCtx; diff --git a/VortexEngine/src/Patterns/Multi/TheaterChasePattern.cpp b/VortexEngine/src/Patterns/Multi/TheaterChasePattern.cpp index fbd527c7db..2398365301 100644 --- a/VortexEngine/src/Patterns/Multi/TheaterChasePattern.cpp +++ b/VortexEngine/src/Patterns/Multi/TheaterChasePattern.cpp @@ -2,7 +2,7 @@ #include "../../Leds/Leds.h" -#define THEATER_CHASE_STEPS 10 +#define THEATER_CHASE_STEPS (LED_COUNT / 2) TheaterChasePattern::TheaterChasePattern(const PatternArgs &args) : BlinkStepPattern(args), @@ -21,7 +21,7 @@ void TheaterChasePattern::init() { BlinkStepPattern::init(); // starts on odd evens - m_ledPositions = MAP_PAIR_ODD_EVENS; + m_ledPositions = MAP_OPPOSITES_1; m_stepCounter = 0; } @@ -32,12 +32,14 @@ void TheaterChasePattern::blinkOn() void TheaterChasePattern::poststep() { - // the first 5 steps are odd evens/odds alternating each step - if (m_stepCounter < 5) { - m_ledPositions = (m_stepCounter % 2) ? MAP_PAIR_ODD_ODDS : MAP_PAIR_ODD_EVENS; - } else { - // the end 5 steps are even evens/odds alternating each step - m_ledPositions = (m_stepCounter % 2) ? MAP_PAIR_EVEN_ODDS : MAP_PAIR_EVEN_EVENS; + if (m_stepCounter == 0) { + m_ledPositions = MAP_OPPOSITES_1; + } + if (m_stepCounter == 1) { + m_ledPositions = MAP_OPPOSITES_2; + } + if (m_stepCounter == 2) { + m_ledPositions = MAP_OPPOSITES_3; } // increment step counter m_stepCounter = (m_stepCounter + 1) % THEATER_CHASE_STEPS; diff --git a/VortexEngine/src/Patterns/Multi/VortexPattern.cpp b/VortexEngine/src/Patterns/Multi/VortexPattern.cpp index b879687b11..deedf0304b 100644 --- a/VortexEngine/src/Patterns/Multi/VortexPattern.cpp +++ b/VortexEngine/src/Patterns/Multi/VortexPattern.cpp @@ -33,14 +33,16 @@ void VortexPattern::init() void VortexPattern::blinkOn() { // Sets an LED at opposite ends of the strip and progresses towards the center - Leds::setIndex((LedPos)m_progress, m_colorset.peekNext()); - Leds::setIndex((LedPos)(LED_LAST - m_progress), m_colorset.peekNext()); + if (MIDDLE_POINT + m_progress != LED_COUNT) { + Leds::setIndex((LedPos)(MIDDLE_POINT + m_progress), m_colorset.cur()); + } + Leds::setIndex((LedPos)(MIDDLE_POINT - m_progress), m_colorset.cur()); } void VortexPattern::poststep() { // step till the middle point - m_progress = (m_progress + 1) % MIDDLE_POINT; + m_progress = (m_progress + 1) % (MIDDLE_POINT + 1); // each cycle progress to the next color if (m_progress == 0) { m_colorset.getNext(); diff --git a/VortexEngine/src/Patterns/Multi/VortexWipePattern.cpp b/VortexEngine/src/Patterns/Multi/VortexWipePattern.cpp index 1a2b19b185..23d92e7e07 100644 --- a/VortexEngine/src/Patterns/Multi/VortexWipePattern.cpp +++ b/VortexEngine/src/Patterns/Multi/VortexWipePattern.cpp @@ -5,19 +5,8 @@ #include "../../Leds/Leds.h" #include "../../Log/Log.h" -const LedPos VortexWipePattern::ledStepPositions[] = { - LED_9, - LED_7, - LED_5, - LED_3, - LED_1, - - LED_0, - LED_2, - LED_4, - LED_6, - LED_8 -}; +// add 1 to prevent the middle point from being led 0 +#define MIDDLE_POINT ((LED_COUNT + 1) / 2) VortexWipePattern::VortexWipePattern(const PatternArgs &args) : BlinkStepPattern(args), @@ -43,17 +32,20 @@ void VortexWipePattern::init() void VortexWipePattern::blinkOn() { - for (int index = 0; index < m_progress; ++index) { - Leds::setIndex(ledStepPositions[index], m_colorset.peekNext()); + Leds::setAll(m_colorset.cur()); + if (!m_progress) { + // none } - for (int index = m_progress; index < LED_COUNT; ++index) { - Leds::setIndex(ledStepPositions[index], m_colorset.cur()); + if (m_progress) { + Leds::setRange((LedPos)(MIDDLE_POINT - (m_progress - 1)), (LedPos)(MIDDLE_POINT + (m_progress - 1)), m_colorset.peekNext()); } } void VortexWipePattern::poststep() { - m_progress = (m_progress + 1) % LED_COUNT; + // step till the middle point + m_progress = (m_progress + 1) % (MIDDLE_POINT + 1); + // each cycle progress to the next color if (m_progress == 0) { m_colorset.getNext(); } diff --git a/VortexEngine/src/Patterns/Multi/WarpPattern.cpp b/VortexEngine/src/Patterns/Multi/WarpPattern.cpp index 24770e4328..318250b313 100644 --- a/VortexEngine/src/Patterns/Multi/WarpPattern.cpp +++ b/VortexEngine/src/Patterns/Multi/WarpPattern.cpp @@ -30,12 +30,12 @@ void WarpPattern::init() void WarpPattern::blinkOn() { Leds::setAll(m_colorset.cur()); - Leds::setPair((Pair)m_progress, m_colorset.peekNext()); + Leds::setIndex((LedPos)m_progress, m_colorset.peekNext()); } void WarpPattern::poststep() { - m_progress = (m_progress + 1) % PAIR_COUNT; + m_progress = (m_progress + 1) % LED_COUNT; if (m_progress == 0) { m_colorset.getNext(); } diff --git a/VortexEngine/src/Patterns/Multi/WarpWormPattern.cpp b/VortexEngine/src/Patterns/Multi/WarpWormPattern.cpp index b6311ad339..d50190ddd8 100644 --- a/VortexEngine/src/Patterns/Multi/WarpWormPattern.cpp +++ b/VortexEngine/src/Patterns/Multi/WarpWormPattern.cpp @@ -29,7 +29,7 @@ void WarpWormPattern::init() void WarpWormPattern::blinkOn() { - int wormSize = 6; + int wormSize = LED_COUNT / 3; Leds::setAll(m_colorset.get(0)); for (int body = 0; body < wormSize; ++body) { if (body + m_progress < LED_COUNT) { diff --git a/VortexEngine/src/Patterns/Multi/ZigzagPattern.cpp b/VortexEngine/src/Patterns/Multi/ZigzagPattern.cpp index 02062917eb..a5cb0d80b3 100644 --- a/VortexEngine/src/Patterns/Multi/ZigzagPattern.cpp +++ b/VortexEngine/src/Patterns/Multi/ZigzagPattern.cpp @@ -8,17 +8,19 @@ // The lights runs across evens, then back across odds. // Index this array with m_step in order to get correct LedPos const LedPos ZigzagPattern::ledStepPositions[] = { - LED_1, + LED_0, LED_3, - LED_5, - LED_7, - LED_9, - - LED_8, - LED_6, + LED_1, LED_4, LED_2, + + LED_5, + LED_3, LED_0, + LED_4, + LED_1, + LED_5, + LED_2 }; // There just happens to be LED_COUNT steps in the pattern