Skip to content

Commit

Permalink
Merge branch 'master' into spark
Browse files Browse the repository at this point in the history
  • Loading branch information
Unreal-Dan committed Nov 27, 2024
2 parents 82bd81c + 0ff2406 commit cc681bb
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 15 deletions.
57 changes: 42 additions & 15 deletions VortexEngine/src/Menus/MenuList/PatternSelect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,34 +94,56 @@ void PatternSelect::onShortClick()
}
return;
}
PatternID newID = (PatternID)(m_previewMode.getPatternID(m_srcLed) + 1);
PatternID maxID = PATTERN_SINGLE_LAST;
nextPattern();
}

void PatternSelect::nextPatternID()
{
// increment to next pattern
PatternID endList = PATTERN_SINGLE_LAST;
PatternID beginList = PATTERN_SINGLE_FIRST;
#if VORTEX_SLIM == 0
if (m_targetLeds == MAP_LED_ALL || m_targetLeds == MAP_LED(LED_MULTI)) {
maxID = PATTERN_MULTI_LAST;
// if targeted multi led or all singles, iterate through multis
if ((m_targetLeds == MAP_LED_ALL) || (m_targetLeds == MAP_LED(LED_MULTI))) {
endList = PATTERN_MULTI_LAST;
}
// if targeted multi then start at multis and only iterate multis
if ((m_targetLeds == MAP_LED(LED_MULTI))) {
beginList = PATTERN_MULTI_FIRST;
}
#endif
if (newID > maxID) {
newID = maxID;
m_newPatternID = (PatternID)((m_newPatternID + 1) % endList);
if (m_newPatternID > endList || m_newPatternID < beginList) {
m_newPatternID = beginList;
}
if (!m_started) {
}

void PatternSelect::nextPattern()
{
if (m_started) {
nextPatternID();
} else {
m_started = true;
newID = PATTERN_FIRST;
// Do not modify m_newPatternID Here! It has been set in the long click handler
// to be the start of the list we want to iterate
}
// set the new pattern id
if (isMultiLedPatternID(newID)) {
m_previewMode.setPattern(newID);
if (isMultiLedPatternID(m_newPatternID)) {
m_previewMode.setPattern(m_newPatternID);
} else {
// if the user selected multi then just put singles on all leds
LedMap setLeds = (m_targetLeds == MAP_LED(LED_MULTI)) ? LED_ALL : m_targetLeds;
m_previewMode.setPatternMap(setLeds, m_newPatternID);
// TODO: clear multi a better way
m_previewMode.setPatternMap(m_targetLeds, newID);
m_previewMode.clearPattern(LED_MULTI);
}
m_previewMode.init();
DEBUG_LOGF("Iterated to pattern id %d", newID);
DEBUG_LOGF("Iterated to pattern id %d", m_newPatternID);
}

void PatternSelect::onLongClick()
{
bool needsSave = false;
if (m_advanced) {
m_argIndex++;
if (m_argIndex < m_previewMode.getPattern(m_srcLed)->getNumArgs()) {
Expand All @@ -130,7 +152,12 @@ void PatternSelect::onLongClick()
}
Leds::holdAll(m_menuColor);
}
// store the mode as current mode
Modes::updateCurMode(&m_previewMode);
leaveMenu(true);
needsSave = !Modes::curMode()->equals(&m_previewMode);
if (needsSave) {
// update the current mode with the new pattern
Modes::updateCurMode(&m_previewMode);
}
DEBUG_LOGF("Saving pattern %u", m_newPatternID);
// done in the pattern select menu
leaveMenu(needsSave);
}
6 changes: 6 additions & 0 deletions VortexEngine/src/Menus/MenuList/PatternSelect.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ class PatternSelect : public Menu
void onLongClick() override;

private:
void nextPatternID();
void nextPattern();

// the patternid of the current demo
PatternID m_newPatternID;

// helpful member
LedPos m_srcLed;

Expand Down

0 comments on commit cc681bb

Please sign in to comment.