Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

led selection fixes #176

Merged
merged 1 commit into from
Dec 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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