Skip to content

Commit

Permalink
Fixes for chromadeck patterns
Browse files Browse the repository at this point in the history
  • Loading branch information
LivingSynthesis committed Dec 19, 2024
1 parent 4830a24 commit 6a62435
Show file tree
Hide file tree
Showing 17 changed files with 85 additions and 60 deletions.
7 changes: 7 additions & 0 deletions VortexEngine/src/Leds/LedTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,13 @@ inline LedPos ledmapGetNextLed(LedMap map, LedPos pos)
#define MAP_LINE_4 (MAP_LED(LED_3) | MAP_LED(LED_13) | MAP_LED(LED_18) | MAP_LED(LED_8))
#define MAP_LINE_5 (MAP_LED(LED_4) | MAP_LED(LED_14) | MAP_LED(LED_19) | MAP_LED(LED_9))

//Chromadeck bitmap
#define MAP_OPPOSITES_1 (MAP_LED(LED_0) | MAP_LED(LED_5) | MAP_LED(LED_10) | MAP_LED(LED_15))
#define MAP_OPPOSITES_2 (MAP_LED(LED_1) | MAP_LED(LED_6) | MAP_LED(LED_11) | MAP_LED(LED_16))
#define MAP_OPPOSITES_3 (MAP_LED(LED_2) | MAP_LED(LED_7) | MAP_LED(LED_12) | MAP_LED(LED_17))
#define MAP_OPPOSITES_4 (MAP_LED(LED_3) | MAP_LED(LED_8) | MAP_LED(LED_13) | MAP_LED(LED_18))
#define MAP_OPPOSITES_5 (MAP_LED(LED_4) | MAP_LED(LED_9) | MAP_LED(LED_14) | MAP_LED(LED_19))

// set a single led
inline void ledmapSetLed(LedMap &map, LedPos pos)
{
Expand Down
2 changes: 1 addition & 1 deletion VortexEngine/src/Menus/MenuList/PatternSelect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ void PatternSelect::nextPatternID()
beginList = PATTERN_MULTI_FIRST;
}
#endif
m_newPatternID = (PatternID)((m_newPatternID + 1) % endList);
m_newPatternID = (PatternID)((m_newPatternID + 1) % (endList + 1));
if (m_newPatternID > endList || m_newPatternID < beginList) {
m_newPatternID = beginList;
}
Expand Down
2 changes: 1 addition & 1 deletion VortexEngine/src/Modes/DefaultModes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const default_mode_entry default_modes[MAX_MODES] = {
}
},
{
PATTERN_FILL, 2, {
PATTERN_WARPWORM, 2, {
RGB_GREEN,
0x26004B,
}
Expand Down
8 changes: 4 additions & 4 deletions VortexEngine/src/Patterns/Multi/BouncePattern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include "../../Log/Log.h"

// safety to prevent divide by 0
#define TOTAL_STEPS (((PAIR_COUNT * 2) - 2) ? ((PAIR_COUNT * 2) - 2) : 1)
#define TOTAL_STEPS (((LED_COUNT * 2) - 2) ? ((LED_COUNT * 2) - 2) : 1)
#define HALF_STEPS (TOTAL_STEPS / 2)

BouncePattern::BouncePattern(const PatternArgs &args) :
Expand Down Expand Up @@ -36,10 +36,10 @@ void BouncePattern::init()
void BouncePattern::blinkOn()
{
Leds::setAll(m_colorset.cur());
if (m_progress < PAIR_COUNT) {
Leds::setPair((Pair)m_progress, m_colorset.peekNext());
if (m_progress < LED_COUNT) {
Leds::setIndex((LedPos)m_progress, m_colorset.peekNext());
} else {
Leds::setPair((Pair)(TOTAL_STEPS - m_progress), m_colorset.peekNext());
Leds::setIndex((LedPos)(TOTAL_STEPS - m_progress), m_colorset.peekNext());
}
}

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;
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "ChaserPattern.h"

// This controls the ratio of chaser dots to LED_COUNT. Default 1 chaser per 7 LEDs. Range: 1-LED_COUNT.
#define CHASER_RATIO 7
#define CHASER_RATIO 5


// This pattern aims to be a demonstration of the sequencer.
Expand Down
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
24 changes: 16 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 / 4)

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,20 @@ 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;
}
if (m_stepCounter == 3) {
m_ledPositions = MAP_OPPOSITES_4;
}
if (m_stepCounter == 4) {
m_ledPositions = MAP_OPPOSITES_5;
}
// increment step counter
m_stepCounter = (m_stepCounter + 1) % THEATER_CHASE_STEPS;
Expand Down
5 changes: 3 additions & 2 deletions VortexEngine/src/Patterns/Multi/VortexPattern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ 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());
Leds::setIndex((LedPos)(m_progress), m_colorset.peekNext());
int offset = (m_progress != 0) ? m_progress : 10;
Leds::setIndex((LedPos)(LED_COUNT - (offset)), m_colorset.peekNext());
}

void VortexPattern::poststep()
Expand Down
26 changes: 6 additions & 20 deletions VortexEngine/src/Patterns/Multi/VortexWipePattern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,7 @@
#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
};
#define VORTEX_WIPE_STEPS (LED_COUNT/2)

VortexWipePattern::VortexWipePattern(const PatternArgs &args) :
BlinkStepPattern(args),
Expand All @@ -43,17 +31,15 @@ void VortexWipePattern::init()

void VortexWipePattern::blinkOn()
{
for (int index = 0; index < m_progress; ++index) {
Leds::setIndex(ledStepPositions[index], m_colorset.peekNext());
}
for (int index = m_progress; index < LED_COUNT; ++index) {
Leds::setIndex(ledStepPositions[index], m_colorset.cur());
}
Leds::setRange(LED_FIRST, (LedPos)m_progress, m_colorset.peekNext());
Leds::setRange((LedPos)(LED_COUNT/2), (LedPos)((LED_COUNT/2) + m_progress), m_colorset.peekNext());
Leds::setRange((LedPos)m_progress, (LedPos)((LED_COUNT/2) - 1), m_colorset.cur());
Leds::setRange((LedPos)((LED_COUNT / 2) + m_progress), (LedPos)(LED_COUNT - 1), m_colorset.cur());
}

void VortexWipePattern::poststep()
{
m_progress = (m_progress + 1) % LED_COUNT;
m_progress = (m_progress + 1) % VORTEX_WIPE_STEPS;
if (m_progress == 0) {
m_colorset.getNext();
}
Expand Down
3 changes: 0 additions & 3 deletions VortexEngine/src/Patterns/Multi/VortexWipePattern.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ class VortexWipePattern : public BlinkStepPattern
virtual void poststep() override;

private:
// path for leds to take, index this with m_step up to LED_COUNT steps
static const LedPos ledStepPositions[];

// how much the fill has progressed
uint8_t m_progress;
};
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
12 changes: 11 additions & 1 deletion VortexEngine/src/Patterns/Multi/ZigzagPattern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,17 @@ const LedPos ZigzagPattern::ledStepPositions[] = {
LED_5,
LED_7,
LED_9,

LED_11,
LED_13,
LED_15,
LED_17,
LED_19,

LED_18,
LED_16,
LED_14,
LED_12,
LED_10,
LED_8,
LED_6,
LED_4,
Expand Down

0 comments on commit 6a62435

Please sign in to comment.