Skip to content

Commit

Permalink
Pattern Fixes for spark, some are core
Browse files Browse the repository at this point in the history
  • Loading branch information
LivingSynthesis committed Nov 23, 2024
1 parent 02f08be commit 64bc716
Show file tree
Hide file tree
Showing 15 changed files with 102 additions and 66 deletions.
5 changes: 5 additions & 0 deletions VortexEngine/src/Leds/LedTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
24 changes: 16 additions & 8 deletions VortexEngine/src/Leds/Leds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}

Expand All @@ -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);
}
}
}

Expand All @@ -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);
}
}
}

Expand All @@ -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);
}
}
}

Expand Down
9 changes: 9 additions & 0 deletions VortexEngine/src/Menus/Menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
6 changes: 3 additions & 3 deletions VortexEngine/src/Patterns/Multi/FillPattern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
16 changes: 12 additions & 4 deletions VortexEngine/src/Patterns/Multi/HueShiftPattern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
18 changes: 9 additions & 9 deletions VortexEngine/src/Patterns/Multi/PulsishPattern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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;
Expand All @@ -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;
}
}
2 changes: 1 addition & 1 deletion VortexEngine/src/Patterns/Multi/SnowballPattern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
11 changes: 9 additions & 2 deletions VortexEngine/src/Patterns/Multi/SparkleTracePattern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions VortexEngine/src/Patterns/Multi/SparkleTracePattern.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class SparkleTracePattern : public BlinkStepPattern

protected:
virtual void blinkOn() override;
virtual void blinkOff() override;
virtual void poststep() override;

Random m_randCtx;
Expand Down
18 changes: 10 additions & 8 deletions VortexEngine/src/Patterns/Multi/TheaterChasePattern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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;
}

Expand All @@ -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;
Expand Down
8 changes: 5 additions & 3 deletions VortexEngine/src/Patterns/Multi/VortexPattern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
28 changes: 10 additions & 18 deletions VortexEngine/src/Patterns/Multi/VortexWipePattern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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();
}
Expand Down
4 changes: 2 additions & 2 deletions VortexEngine/src/Patterns/Multi/WarpPattern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
2 changes: 1 addition & 1 deletion VortexEngine/src/Patterns/Multi/WarpWormPattern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
16 changes: 9 additions & 7 deletions VortexEngine/src/Patterns/Multi/ZigzagPattern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 64bc716

Please sign in to comment.