Skip to content

Commit

Permalink
led selection fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Unreal-Dan committed Dec 29, 2023
1 parent 3dadc2a commit a78cf4d
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 9 deletions.
12 changes: 6 additions & 6 deletions VortexEngine/src/Menus/Menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,14 @@ Menu::MenuAction Menu::run()

// every time a button is clicked, change the led selection
if (g_pButton->onShortClick()) {
m_ledSelection = (m_ledSelection + 1) % NUM_PERMUTATIONS;
do {
m_ledSelection = (m_ledSelection + 1) % NUM_PERMUTATIONS;
} while (!isValidLedSelection(ledPermutations[m_ledSelection]));
}
if (g_pButton2->onShortClick()) {
if (m_ledSelection > 0) {
m_ledSelection--;
} else {
m_ledSelection = NUM_PERMUTATIONS - 1;
}
do {
m_ledSelection = (m_ledSelection > 0) ? (m_ledSelection - 1) : (NUM_PERMUTATIONS - 1);
} while (!isValidLedSelection(ledPermutations[m_ledSelection]));
}
// on a long press of the button, lock in the target led
if (g_pButton->onLongClick()) {
Expand Down
6 changes: 3 additions & 3 deletions VortexEngine/src/Menus/Menu.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ class Menu
void showBulbSelection();
void showExit();

// iterate to next bulb selection
void nextBulbSelection();
void prevBulbSelection();
// an overridable api that allows derived menus to decide which led selections
// should be available before they have actually opened
virtual bool isValidLedSelection(LedMap selection) const { return true; }

// blink the selected finger
virtual void blinkSelection(uint32_t offMs = 250, uint32_t onMs = 500);
Expand Down
8 changes: 8 additions & 0 deletions VortexEngine/src/Menus/MenuList/ColorSelect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -405,3 +405,11 @@ void ColorSelect::blinkSelection(uint32_t offMs, uint32_t onMs)
// otherwise run the default blink logic
Menu::blinkSelection(offMs, onMs);
}

bool ColorSelect::isValidLedSelection(LedMap selection) const
{
// if we have a multi-led pattern then we can only select LED_MULTI otherwise
// if we don't have a multi-led pattern then we can't select multi
bool selectedMulti = (selection == MAP_LED(LED_MULTI));
return selectedMulti == m_previewMode.isMultiLed();
}
3 changes: 3 additions & 0 deletions VortexEngine/src/Menus/MenuList/ColorSelect.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ class ColorSelect : public Menu
// overridden blink logic for the colorselect menu (Controls how m_curSelection blinks)
void blinkSelection(uint32_t offMs = 350, uint32_t onMs = 500) override;

// override the led selection api to choose which led maps can be selected
bool isValidLedSelection(LedMap selection) const override;

// private enumeration for internal state of color selection
enum ColorSelectState : uint32_t
{
Expand Down

0 comments on commit a78cf4d

Please sign in to comment.