From 448cb47cb7316810867eaa941c0c7d888e040675 Mon Sep 17 00:00:00 2001 From: Unreal-Dan <72595612+Unreal-Dan@users.noreply.github.com> Date: Thu, 28 Dec 2023 18:18:16 -0800 Subject: [PATCH] led selection fixes (#177) --- VortexEngine/src/Menus/Menu.cpp | 4 +++- VortexEngine/src/Menus/Menu.h | 4 ++++ VortexEngine/src/Menus/MenuList/ColorSelect.cpp | 8 ++++++++ VortexEngine/src/Menus/MenuList/ColorSelect.h | 6 +++++- 4 files changed, 20 insertions(+), 2 deletions(-) diff --git a/VortexEngine/src/Menus/Menu.cpp b/VortexEngine/src/Menus/Menu.cpp index cd7da1f83b..7540c486b5 100644 --- a/VortexEngine/src/Menus/Menu.cpp +++ b/VortexEngine/src/Menus/Menu.cpp @@ -71,7 +71,9 @@ Menu::MenuAction Menu::run() // every time the button is clicked, change the target led if (g_pButton->onShortClick()) { - nextBulbSelection(); + do { + nextBulbSelection(); + } while (!isValidLedSelection(m_targetLeds)); } // on a long press of the button, lock in the target led if (g_pButton->onLongClick()) { diff --git a/VortexEngine/src/Menus/Menu.h b/VortexEngine/src/Menus/Menu.h index b68b4748d8..67d49e929b 100644 --- a/VortexEngine/src/Menus/Menu.h +++ b/VortexEngine/src/Menus/Menu.h @@ -44,6 +44,10 @@ class Menu // iterate to next bulb selection void nextBulbSelection(); + // 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; } + // the mode copied from the current mode used to preview changes Mode m_previewMode; // the color of this menu diff --git a/VortexEngine/src/Menus/MenuList/ColorSelect.cpp b/VortexEngine/src/Menus/MenuList/ColorSelect.cpp index c1caf53cab..58296089eb 100644 --- a/VortexEngine/src/Menus/MenuList/ColorSelect.cpp +++ b/VortexEngine/src/Menus/MenuList/ColorSelect.cpp @@ -260,3 +260,11 @@ void ColorSelect::showFullSet(uint8_t offMs, uint8_t onMs) Leds::setAll(m_colorset.get((now / offOnMs) % numCols)); } } + +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(); +} diff --git a/VortexEngine/src/Menus/MenuList/ColorSelect.h b/VortexEngine/src/Menus/MenuList/ColorSelect.h index 970c9b2b13..6bda0fd1c3 100644 --- a/VortexEngine/src/Menus/MenuList/ColorSelect.h +++ b/VortexEngine/src/Menus/MenuList/ColorSelect.h @@ -22,7 +22,11 @@ class ColorSelect : public Menu void onLongClick() override; private: - enum ColorSelectState + // 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 { STATE_INIT, STATE_PICK_SLOT,