From 456f71ec722406b14fd9666b59078c19f110bdfb Mon Sep 17 00:00:00 2001 From: Unreal-Dan <72595612+Unreal-Dan@users.noreply.github.com> Date: Tue, 5 Dec 2023 22:00:03 -0800 Subject: [PATCH] Fixed sequencer and some multi led fixes (#144) --- VortexEngine/src/Leds/LedTypes.h | 3 +++ VortexEngine/src/Menus/MenuList/ColorSelect.cpp | 1 + .../Multi/Sequencer/SequencedPattern.cpp | 17 ++++++++++++++--- .../Patterns/Multi/Sequencer/SequencedPattern.h | 2 ++ 4 files changed, 20 insertions(+), 3 deletions(-) diff --git a/VortexEngine/src/Leds/LedTypes.h b/VortexEngine/src/Leds/LedTypes.h index 117e726f0a..48b8cb7a86 100644 --- a/VortexEngine/src/Leds/LedTypes.h +++ b/VortexEngine/src/Leds/LedTypes.h @@ -108,6 +108,9 @@ typedef uint64_t LedMap; // convert a map to the first Led position in the map inline LedPos mapGetFirstLed(LedMap map) { + if (map == MAP_LED(LED_MULTI)) { + return LED_MULTI; + } LedPos pos = LED_FIRST; while (map && pos < LED_COUNT) { if (map & 1) { diff --git a/VortexEngine/src/Menus/MenuList/ColorSelect.cpp b/VortexEngine/src/Menus/MenuList/ColorSelect.cpp index ba8c76504c..c1caf53cab 100644 --- a/VortexEngine/src/Menus/MenuList/ColorSelect.cpp +++ b/VortexEngine/src/Menus/MenuList/ColorSelect.cpp @@ -45,6 +45,7 @@ bool ColorSelect::init() return false; } if (cur->isMultiLed()) { + m_targetLeds = MAP_LED(LED_MULTI); m_ledSelected = true; } m_state = STATE_INIT; diff --git a/VortexEngine/src/Patterns/Multi/Sequencer/SequencedPattern.cpp b/VortexEngine/src/Patterns/Multi/Sequencer/SequencedPattern.cpp index b4bd86f151..d65e64bc7f 100644 --- a/VortexEngine/src/Patterns/Multi/Sequencer/SequencedPattern.cpp +++ b/VortexEngine/src/Patterns/Multi/Sequencer/SequencedPattern.cpp @@ -47,16 +47,27 @@ void SequencedPattern::init() m_timer.start(); - // TODO: Play first sequence step in init? + // Play first sequence step in init, if there is one + if (m_sequence.numSteps() > 0) { + playSequenceStep(m_sequence[0]); + } } // pure virtual must the play function void SequencedPattern::play() { - if (m_timer.alarm() != -1 && !m_timer.onStart()) { + if (m_timer.alarm() != -1) { m_curSequence = (m_curSequence + 1) % m_sequence.numSteps(); } - const SequenceStep &step = m_sequence[m_curSequence]; + // only index the sequence if the current sequence index is valid + if (m_curSequence < m_sequence.numSteps()) { + // play the sequence step + playSequenceStep(m_sequence[m_curSequence]); + } +} + +void SequencedPattern::playSequenceStep(const SequenceStep &step) +{ for (LedPos pos = LED_FIRST; pos < LED_COUNT; ++pos) { // the current initialized pattern for this LED SingleLedPattern *curPat = m_ledPatterns[pos]; diff --git a/VortexEngine/src/Patterns/Multi/Sequencer/SequencedPattern.h b/VortexEngine/src/Patterns/Multi/Sequencer/SequencedPattern.h index a73d6130fe..d1f6786ce3 100644 --- a/VortexEngine/src/Patterns/Multi/Sequencer/SequencedPattern.h +++ b/VortexEngine/src/Patterns/Multi/Sequencer/SequencedPattern.h @@ -32,6 +32,8 @@ class SequencedPattern : public CompoundPattern void bindSequence(const Sequence &sequence); protected: + void playSequenceStep(const SequenceStep &step); + // static data Sequence m_sequence;