From 9f0db64c4baa28ba333da66c058e0523c98f24b3 Mon Sep 17 00:00:00 2001 From: Shane Aronson Date: Thu, 19 Dec 2024 16:33:01 -0800 Subject: [PATCH] Adjusted menu buttons to be more consistent --- VortexEngine/src/Menus/MainMenu.cpp | 3 + VortexEngine/src/Menus/Menu.cpp | 2 +- .../src/Menus/MenuList/FactoryReset.cpp | 57 +++++++++++++------ .../src/Menus/MenuList/FactoryReset.h | 3 +- .../src/Menus/MenuList/GlobalBrightness.cpp | 17 +++++- .../src/Menus/MenuList/GlobalBrightness.h | 2 + .../src/Menus/MenuList/PatternSelect.cpp | 57 ++++++++++++++++++- .../src/Menus/MenuList/PatternSelect.h | 4 ++ 8 files changed, 124 insertions(+), 21 deletions(-) diff --git a/VortexEngine/src/Menus/MainMenu.cpp b/VortexEngine/src/Menus/MainMenu.cpp index cc4345c78e..138a2a0d14 100644 --- a/VortexEngine/src/Menus/MainMenu.cpp +++ b/VortexEngine/src/Menus/MainMenu.cpp @@ -36,6 +36,9 @@ bool MainMenu::run() if (g_pButtonM->onShortClick()) { select(); } + if (g_pButtonM->onLongClick()) { + select(); + } // press > if (g_pButtonR->onShortClick()) { pressRight(); diff --git a/VortexEngine/src/Menus/Menu.cpp b/VortexEngine/src/Menus/Menu.cpp index c82b6f1a40..9deb117cd6 100644 --- a/VortexEngine/src/Menus/Menu.cpp +++ b/VortexEngine/src/Menus/Menu.cpp @@ -122,7 +122,7 @@ Menu::MenuAction Menu::run() m_ledSelection = (m_ledSelection > 0) ? (m_ledSelection - 1) : (NUM_PERMUTATIONS - 1); } // on a long press of the button, lock in the target led - if (g_pButtonM->onLongClick()) { + if (g_pButtonM->onLongClick() || g_pButtonM->onShortClick()) { // if no target, set at least cur mask if (m_targetLeds == 0) { //if (m_targetLeds == MAP_LED_NONE) { diff --git a/VortexEngine/src/Menus/MenuList/FactoryReset.cpp b/VortexEngine/src/Menus/MenuList/FactoryReset.cpp index 6da188033d..5106462e02 100644 --- a/VortexEngine/src/Menus/MenuList/FactoryReset.cpp +++ b/VortexEngine/src/Menus/MenuList/FactoryReset.cpp @@ -57,11 +57,16 @@ Menu::MenuAction FactoryReset::run() return MENU_CONTINUE; } -void FactoryReset::onShortClickM() +void FactoryReset::onShortClickL() { m_curSelection = (uint8_t)!m_curSelection; } +void FactoryReset::onShortClickR() +{ + onShortClickL(); +} + void FactoryReset::onLongClickM() { if (m_curSelection == 0) { @@ -96,32 +101,50 @@ void FactoryReset::onLongClickM() void FactoryReset::showReset() { + // if we're on exit just set the rest to blank if (m_curSelection == 0) { Leds::clearAll(); Leds::blinkAll(350, 350, RGB_WHITE0); return; } - bool isPressed = g_pButtonM->isPressed(); - if (!isPressed) { - Leds::clearAll(); - Leds::blinkAll(50, 50, RGB_RED4); + // otherwise we're not on exit, if the button isn't pressed + if (!g_pButtonM->isPressed()) { + // just idle blink from clear to blank + Leds::clearRange(LED_FIRST, LED_LAST); + Leds::blinkRange(LED_FIRST, LED_LAST, 250, 150, RGB_RED0); return; } - // don't start the fill until the button has been held for a bit - uint32_t holdDur = g_pButtonM->holdDuration(); - if (holdDur < MS_TO_TICKS(100)) { + + // the button is pressed so show the reset countdown timer + + // the progress is how long the hold duration has been held + // relative to the factory reset threshold time + float progress = (float)g_pButtonM->holdDuration() / FACTORY_RESET_THRESHOLD_TICKS; + // prevents the countdown timer from showing unless button is held longer than 3% of the reset Threshold (this is for short clicks) + if (progress < 0.03) { return; } - uint16_t progress = ((holdDur * 100) / FACTORY_RESET_THRESHOLD_TICKS); - DEBUG_LOGF("progress: %d", progress); - if (progress >= 100) { - Leds::setAll(RGB_WHITE); + // the ledProgress is just an LED from pinky tip to index top based on progress + LedPos ledProgress = (LedPos)(progress * LED_LAST); + // max the led progress at index top (don't include thumb) + if (ledProgress > LED_LAST) { + // when we reach the end of the progress bar just blink white + Leds::blinkRange(LED_FIRST, LED_LAST, 80, 60, RGB_WHITE6); return; } - uint8_t offMs = 100; - uint8_t onMs = (progress > 60) ? 30 : 100; - uint8_t sat = (uint8_t)((progress * 5) >> 1); // Using bit shift for division by 2 - Leds::clearAll(); - Leds::blinkAll(offMs, onMs, HSVColor(0, 255 - sat, 180)); + + // the off/on ms blink faster based on the progress + uint32_t offMs = 150 - ((65 / LED_COUNT) * ledProgress); + uint32_t onMs = 200 - ((25 / LED_COUNT) * ledProgress); + // the 'endled' is the tip of the reset progress bar, since the progress + // bar starts full red and empties down to the pinky that means it is + // inverted from the 'ledProgress' which starts at 0 and grows + LedPos endLed = (LedPos)(LED_LAST - ledProgress); + // clear all the leds so that 'blinkRange' will blink from off to the designated color + Leds::clearRange(LED_FIRST, LED_LAST); + // blink to the calculated redish hue from pinky to the end led + Leds::blinkRange(LED_FIRST, endLed, offMs, onMs, HSVColor(0, 255 - (progress * 170), 180)); + // and blink the background the regular blank color + Leds::blinkRange((LedPos)(endLed + 1), LED_LAST, offMs, onMs, RGB_WHITE0); } diff --git a/VortexEngine/src/Menus/MenuList/FactoryReset.h b/VortexEngine/src/Menus/MenuList/FactoryReset.h index 5d1a0864a8..f4469a1af2 100644 --- a/VortexEngine/src/Menus/MenuList/FactoryReset.h +++ b/VortexEngine/src/Menus/MenuList/FactoryReset.h @@ -13,7 +13,8 @@ class FactoryReset : public Menu MenuAction run() override; // handlers for clicks - void onShortClickM() override; + void onShortClickL() override; + void onShortClickR() override; void onLongClickM() override; private: diff --git a/VortexEngine/src/Menus/MenuList/GlobalBrightness.cpp b/VortexEngine/src/Menus/MenuList/GlobalBrightness.cpp index 633b32fcff..3bcb9b8897 100644 --- a/VortexEngine/src/Menus/MenuList/GlobalBrightness.cpp +++ b/VortexEngine/src/Menus/MenuList/GlobalBrightness.cpp @@ -49,12 +49,27 @@ Menu::MenuAction GlobalBrightness::run() return MENU_CONTINUE; } -void GlobalBrightness::onShortClickM() +void GlobalBrightness::onShortClickR() { // include one extra option for the exit slot m_curSelection = (m_curSelection + 1) % (NUM_BRIGHTNESS_OPTIONS + 1); } +void GlobalBrightness::onShortClickL() +{ + // include one extra option for the exit slot + if (!m_curSelection) { + m_curSelection = NUM_BRIGHTNESS_OPTIONS; + } else { + m_curSelection = m_curSelection - 1; + } +} + +void GlobalBrightness::onShortClickM() +{ + onLongClickM(); +} + void GlobalBrightness::onLongClickM() { if (m_curSelection >= NUM_BRIGHTNESS_OPTIONS) { diff --git a/VortexEngine/src/Menus/MenuList/GlobalBrightness.h b/VortexEngine/src/Menus/MenuList/GlobalBrightness.h index ce14160184..875303fb9a 100644 --- a/VortexEngine/src/Menus/MenuList/GlobalBrightness.h +++ b/VortexEngine/src/Menus/MenuList/GlobalBrightness.h @@ -13,6 +13,8 @@ class GlobalBrightness : public Menu MenuAction run() override; // handlers for clicks + void onShortClickL() override; + void onShortClickR() override; void onShortClickM() override; void onLongClickM() override; diff --git a/VortexEngine/src/Menus/MenuList/PatternSelect.cpp b/VortexEngine/src/Menus/MenuList/PatternSelect.cpp index 6af4a8e831..81ae047bdd 100644 --- a/VortexEngine/src/Menus/MenuList/PatternSelect.cpp +++ b/VortexEngine/src/Menus/MenuList/PatternSelect.cpp @@ -52,11 +52,21 @@ void PatternSelect::onLedSelected() m_srcLed = ledmapGetFirstLed(m_targetLeds); } -void PatternSelect::onShortClickM() +void PatternSelect::onShortClickR() { nextPattern(); } +void PatternSelect::onShortClickL() +{ + previousPattern(); +} + +void PatternSelect::onShortClickM() +{ + onLongClickM(); +} + void PatternSelect::nextPatternID() { // increment to next pattern @@ -101,6 +111,51 @@ void PatternSelect::nextPattern() DEBUG_LOGF("Iterated to pattern id %d", m_newPatternID); } +void PatternSelect::previousPatternID() +{ + // increment to next pattern + PatternID endList = PATTERN_SINGLE_LAST; + PatternID beginList = PATTERN_SINGLE_FIRST; +#if VORTEX_SLIM == 0 + // 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 (m_newPatternID > beginList) { + m_newPatternID = (PatternID)(m_newPatternID - 1); + } else { + m_newPatternID = endList; + } +} + +void PatternSelect::previousPattern() +{ + if (m_started) { + previousPatternID(); + } else { + m_started = true; + // 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(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.clearPattern(LED_MULTI); + } + m_previewMode.init(); + DEBUG_LOGF("Iterated to pattern id %d", m_newPatternID); +} + void PatternSelect::onLongClickM() { bool needsSave = false; diff --git a/VortexEngine/src/Menus/MenuList/PatternSelect.h b/VortexEngine/src/Menus/MenuList/PatternSelect.h index 29a61ef3dc..7690dc6e32 100644 --- a/VortexEngine/src/Menus/MenuList/PatternSelect.h +++ b/VortexEngine/src/Menus/MenuList/PatternSelect.h @@ -19,12 +19,16 @@ class PatternSelect : public Menu void onLedSelected() override; // handlers for clicks + void onShortClickL() override; + void onShortClickR() override; void onShortClickM() override; void onLongClickM() override; private: void nextPatternID(); void nextPattern(); + void previousPatternID(); + void previousPattern(); // the patternid of the current demo PatternID m_newPatternID;