Skip to content

Commit

Permalink
Substituted Materia for Vortex, needs renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
LivingSynthesis committed Nov 18, 2023
1 parent cfc76c2 commit c7c9f1d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 109 deletions.
103 changes: 17 additions & 86 deletions VortexEngine/src/Patterns/Multi/MateriaPattern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,11 @@
#include "../../Leds/Leds.h"
#include "../../Log/Log.h"

MateriaPattern::MateriaPattern(const PatternArgs &args) :
MultiLedPattern(args),
m_onDuration1(0),
m_offDuration1(0),
m_onDuration2(0),
m_offDuration2(0),
m_stepSpeed(0),
m_stepTimer(),
m_ledMap(0),
m_switch(false)
MateriaPattern::MateriaPattern(const PatternArgs& args) :
BlinkStepPattern(args),
m_progress(0)
{
m_patternID = PATTERN_MATERIA;
REGISTER_ARG(m_onDuration1);
REGISTER_ARG(m_offDuration1);
REGISTER_ARG(m_onDuration2);
REGISTER_ARG(m_offDuration2);
REGISTER_ARG(m_stepSpeed);
m_patternID = PATTERN_VORTEXWIPE;
setArgs(args);
}

Expand All @@ -32,79 +20,22 @@ MateriaPattern::~MateriaPattern()
// init the pattern to initial state
void MateriaPattern::init()
{
MultiLedPattern::init();

// start on index 1
m_colorset.setCurIndex(1);
// reset the blink timer entirely
m_blinkTimer1.reset();
// dops timing
m_blinkTimer1.addAlarm(m_onDuration1);
m_blinkTimer1.addAlarm(m_offDuration1);
// start the blink timer from the next frame
m_blinkTimer1.start();

// reset the blink timer entirely
m_blinkTimer2.reset();
// dops timing
m_blinkTimer2.addAlarm(m_onDuration2);
m_blinkTimer2.addAlarm(m_offDuration2);
// start the blink timer from the next frame
m_blinkTimer2.start();

// reset and add alarm
m_stepTimer.reset();
m_stepTimer.addAlarm(m_stepSpeed * 100);
m_stepTimer.start();

// map of the Thumb, Index, Ring, and Pinkie Tops
m_ledMap = MAP_LED(LED_9) | MAP_LED(LED_7) | MAP_LED(LED_3) | MAP_LED(LED_1);
BlinkStepPattern::init();
// reset progress
m_progress = 0;
// start colorset at index 0 so cur() works
m_colorset.setCurIndex(0);
}

//Set the middle top to solid color 0
Leds::setIndex(LED_5, m_colorset.get(0));
void MateriaPattern::blinkOn()
{
Leds::setRing((Ring)(RING_COUNT - m_progress), m_colorset.peekNext());
}

// pure virtual must override the play function
void MateriaPattern::play()
void MateriaPattern::poststep()
{
// get next color on stepTimer alarm, skip color 0
if (m_stepTimer.alarm() == 0) {
m_progress = (m_progress + 1) % RING_COUNT;
if (RING_COUNT - m_progress == RING_LAST) {
m_colorset.getNext();
if (m_colorset.curIndex() == 0) {
m_colorset.getNext();
}
}
switch (m_blinkTimer1.alarm()) {
case -1: // just break and still run post-step
break;
case 0: // turn on the leds for given mapping
m_switch = !m_switch;
// alternate between showing the current and next color
if (m_switch) {
// if this is the last color of the set, skip color 0 (color 0 is for Middle top only)
if (m_colorset.curIndex() != m_colorset.numColors() - 1) {
Leds::setAllEvens(m_colorset.peekNext());
} else {
Leds::setAllEvens(m_colorset.peek(2));
}
}
else {
Leds::setAllEvens(m_colorset.cur());
}
break;
case 1: // turn off the leds
Leds::clearAllEvens();
break;
}

switch (m_blinkTimer2.alarm()) {
case -1: // just break and still run post-step
break;
case 0: // turn on the leds for given mapping
Leds::setMap(m_ledMap, m_colorset.cur());
break;
case 1: // turn off the leds
Leds::clearMap(m_ledMap);
break;
}
}
}
31 changes: 9 additions & 22 deletions VortexEngine/src/Patterns/Multi/MateriaPattern.h
Original file line number Diff line number Diff line change
@@ -1,39 +1,26 @@
#ifndef MATERIA_PATTERN_H
#define MATERIA_PATTERN_H

#include "MultiLedPattern.h"
#include "BlinkStepPattern.h"

#include "../../Time/Timings.h"
#include "../../Time/Timer.h"
#include "../../Leds/LedTypes.h"

class MateriaPattern : public MultiLedPattern
class MateriaPattern : public BlinkStepPattern
{
public:
MateriaPattern(const PatternArgs &args);
MateriaPattern(const PatternArgs& args);
virtual ~MateriaPattern();

// init the pattern to initial state
virtual void init() override;

// pure virtual must override the play function
virtual void play() override;
protected:
virtual void blinkOn() override;
virtual void poststep() override;

private:
// blink durations
uint8_t m_onDuration1;
uint8_t m_offDuration1;
uint8_t m_onDuration2;
uint8_t m_offDuration2;
// the speed for the step timer
uint8_t m_stepSpeed;
// the step timer
Timer m_blinkTimer1;
Timer m_blinkTimer2;
Timer m_stepTimer;

LedMap m_ledMap;

bool m_switch;
// how much the fill has progressed
uint8_t m_progress;
};

#endif
2 changes: 1 addition & 1 deletion VortexEngine/src/Patterns/PatternBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ PatternArgs PatternBuilder::getDefaultArgs(PatternID id)
case PATTERN_BOUNCE: return PatternArgs(DOPS_ON_DURATION, DOPS_OFF_DURATION, 200, 10);
case PATTERN_SPLITSTROBIE: return PatternArgs(DOPS_ON_DURATION, DOPS_OFF_DURATION, 0, 16, 3, 10, PATTERN_DOPS, PATTERN_STROBIE);
case PATTERN_BACKSTROBE: return PatternArgs(DOPS_ON_DURATION, DOPS_OFF_DURATION, 0, HYPERSTROBE_ON_DURATION, HYPERSTROBE_OFF_DURATION, 10, PATTERN_DOPS, PATTERN_HYPERSTROBE);
case PATTERN_MATERIA: return PatternArgs(STROBE_ON_DURATION, STROBE_OFF_DURATION, 3, 35, 80);
case PATTERN_MATERIA: return PatternArgs(STROBE_ON_DURATION, STROBE_OFF_DURATION, 130);
case PATTERN_NONE: break;
default: break;
#else
Expand Down

0 comments on commit c7c9f1d

Please sign in to comment.