From cf8e27b6ffc22198ccf7cff10511e6769067799e Mon Sep 17 00:00:00 2001 From: Dan Date: Fri, 3 Nov 2023 03:56:37 -0700 Subject: [PATCH] Fixes for buttons --- VortexEngine/src/Buttons/Button.h | 8 +++++-- VortexEngine/src/Buttons/Buttons.cpp | 2 -- VortexEngine/src/Buttons/Buttons.h | 8 +++++-- VortexEngine/src/Menus/Menu.cpp | 6 ++--- .../src/Menus/MenuList/ColorSelect.cpp | 6 ++--- .../src/Menus/MenuList/FactoryReset.cpp | 6 ++--- .../src/Menus/MenuList/PatternSelect.cpp | 2 +- .../src/Menus/MenuList/Randomizer.cpp | 2 +- VortexEngine/src/Menus/Menus.cpp | 24 +++++++++---------- VortexEngine/src/Modes/Modes.cpp | 2 +- VortexEngine/src/VortexEngine.cpp | 8 +++---- 11 files changed, 40 insertions(+), 34 deletions(-) diff --git a/VortexEngine/src/Buttons/Button.h b/VortexEngine/src/Buttons/Button.h index 16b6248d78..94a0a571b1 100644 --- a/VortexEngine/src/Buttons/Button.h +++ b/VortexEngine/src/Buttons/Button.h @@ -97,7 +97,11 @@ class Button #endif }; -// See Button.cpp for info about this -extern Button *g_pButton; +// Button Left +extern Button *g_pButtonL; +// Button Mid +extern Button *g_pButtonM; +// Button Right +extern Button *g_pButtonR; #endif diff --git a/VortexEngine/src/Buttons/Buttons.cpp b/VortexEngine/src/Buttons/Buttons.cpp index b4a38ee326..1be643a564 100644 --- a/VortexEngine/src/Buttons/Buttons.cpp +++ b/VortexEngine/src/Buttons/Buttons.cpp @@ -16,10 +16,8 @@ // Button Left Button *g_pButtonL = nullptr; - // Button Mid Button *g_pButtonM = nullptr; - // Button Right Button *g_pButtonR = nullptr; diff --git a/VortexEngine/src/Buttons/Buttons.h b/VortexEngine/src/Buttons/Buttons.h index 8af5e74fb0..fb9167fd1b 100644 --- a/VortexEngine/src/Buttons/Buttons.h +++ b/VortexEngine/src/Buttons/Buttons.h @@ -27,7 +27,11 @@ class Buttons static Button m_buttons[NUM_BUTTONS]; }; -// best way I think -extern Button *g_pButton; +// Button Left +extern Button *g_pButtonL; +// Button Mid +extern Button *g_pButtonM; +// Button Right +extern Button *g_pButtonR; #endif diff --git a/VortexEngine/src/Menus/Menu.cpp b/VortexEngine/src/Menus/Menu.cpp index 3684051905..c28163e092 100644 --- a/VortexEngine/src/Menus/Menu.cpp +++ b/VortexEngine/src/Menus/Menu.cpp @@ -69,11 +69,11 @@ Menu::MenuAction Menu::run() // class's onShortClick and onLongClick functions so // every time the button is clicked, change the target led - if (g_pButton->onShortClick()) { + if (g_pButtonM->onShortClick()) { nextBulbSelection(); } // on a long press of the button, lock in the target led - if (g_pButton->onLongClick()) { + if (g_pButtonM->onLongClick()) { m_ledSelected = true; // call led selected callback onLedSelected(); @@ -105,7 +105,7 @@ void Menu::showBulbSelection() void Menu::showExit() { - if (g_pButton->isPressed() && g_pButton->holdDuration() > SHORT_CLICK_THRESHOLD_TICKS) { + if (g_pButtonM->isPressed() && g_pButtonM->holdDuration() > SHORT_CLICK_THRESHOLD_TICKS) { Leds::setAll(RGB_RED); return; } diff --git a/VortexEngine/src/Menus/MenuList/ColorSelect.cpp b/VortexEngine/src/Menus/MenuList/ColorSelect.cpp index ba8c76504c..62239dc41f 100644 --- a/VortexEngine/src/Menus/MenuList/ColorSelect.cpp +++ b/VortexEngine/src/Menus/MenuList/ColorSelect.cpp @@ -122,7 +122,7 @@ void ColorSelect::onLongClick() } // reuse these variables lots uint8_t numColors = m_colorset.numColors(); - uint32_t holdDur = g_pButton->holdDuration(); + uint32_t holdDur = g_pButtonM->holdDuration(); switch (m_state) { case STATE_INIT: // nothing @@ -180,9 +180,9 @@ void ColorSelect::onLongClick() void ColorSelect::showSlotSelection() { uint8_t exitIndex = m_colorset.numColors(); - uint32_t holdDur = g_pButton->holdDuration(); + uint32_t holdDur = g_pButtonM->holdDuration(); bool withinNumColors = m_curSelection < exitIndex; - bool holdDurationCheck = g_pButton->isPressed() && holdDur >= DELETE_THRESHOLD_TICKS; + bool holdDurationCheck = g_pButtonM->isPressed() && holdDur >= DELETE_THRESHOLD_TICKS; bool holdDurationModCheck = (holdDur % (DELETE_CYCLE_TICKS * 2)) > DELETE_CYCLE_TICKS; const RGBColor &col = m_colorset[m_curSelection]; if (withinNumColors && holdDurationCheck && holdDurationModCheck) { diff --git a/VortexEngine/src/Menus/MenuList/FactoryReset.cpp b/VortexEngine/src/Menus/MenuList/FactoryReset.cpp index 287af81739..afe8f1f508 100644 --- a/VortexEngine/src/Menus/MenuList/FactoryReset.cpp +++ b/VortexEngine/src/Menus/MenuList/FactoryReset.cpp @@ -70,7 +70,7 @@ void FactoryReset::onLongClick() return; } // if the button hasn't been held long enough just return - if (g_pButton->holdDuration() <= (FACTORY_RESET_THRESHOLD_TICKS + MS_TO_TICKS(10))) { + if (g_pButtonM->holdDuration() <= (FACTORY_RESET_THRESHOLD_TICKS + MS_TO_TICKS(10))) { return; } // the button was held down long enough so actually perform the factory reset @@ -101,14 +101,14 @@ void FactoryReset::showReset() Leds::blinkAll(350, 350, RGB_WHITE0); return; } - bool isPressed = g_pButton->isPressed(); + bool isPressed = g_pButtonM->isPressed(); if (!isPressed) { Leds::clearAll(); Leds::blinkAll(50, 50, RGB_RED4); return; } // don't start the fill until the button has been held for a bit - uint32_t holdDur = g_pButton->holdDuration(); + uint32_t holdDur = g_pButtonM->holdDuration(); if (holdDur < MS_TO_TICKS(100)) { return; } diff --git a/VortexEngine/src/Menus/MenuList/PatternSelect.cpp b/VortexEngine/src/Menus/MenuList/PatternSelect.cpp index a86be8a50e..79b4bc4616 100644 --- a/VortexEngine/src/Menus/MenuList/PatternSelect.cpp +++ b/VortexEngine/src/Menus/MenuList/PatternSelect.cpp @@ -56,7 +56,7 @@ void PatternSelect::onShortClick() { if (m_advanced) { // double click = skip 10 - bool doSkip = g_pButton->onConsecutivePresses(2); + bool doSkip = g_pButtonM->onConsecutivePresses(2); MAP_FOREACH_LED(m_targetLeds) { uint8_t &arg = m_previewMode.getPattern(pos)->argRef(m_argIndex); if (doSkip) { diff --git a/VortexEngine/src/Menus/MenuList/Randomizer.cpp b/VortexEngine/src/Menus/MenuList/Randomizer.cpp index d741d3eb71..dd0be1702f 100644 --- a/VortexEngine/src/Menus/MenuList/Randomizer.cpp +++ b/VortexEngine/src/Menus/MenuList/Randomizer.cpp @@ -84,7 +84,7 @@ Menu::MenuAction Randomizer::run() m_previewMode.init(); } // if the user fast-clicks 3 times then toggle automode - if (g_pButton->onRelease() && g_pButton->onConsecutivePresses(AUTO_CYCLE_RANDOMIZER_CLICKS)) { + if (g_pButtonM->onRelease() && g_pButtonM->onConsecutivePresses(AUTO_CYCLE_RANDOMIZER_CLICKS)) { // toggle the auto cycle flag m_autoCycle = !m_autoCycle; // display a quick flash of either green or red to indicate whether auto mode is on or not diff --git a/VortexEngine/src/Menus/Menus.cpp b/VortexEngine/src/Menus/Menus.cpp index 2e6312faca..d0af5d3110 100644 --- a/VortexEngine/src/Menus/Menus.cpp +++ b/VortexEngine/src/Menus/Menus.cpp @@ -102,7 +102,7 @@ bool Menus::run() bool Menus::runMenuSelection() { - if (g_pButton->onShortClick()) { + if (g_pButtonM->onShortClick()) { // otherwise increment selection and wrap around at num menus m_selection = (m_selection + 1) % NUM_MENUS; DEBUG_LOGF("Cyling to ring menu %u", m_selection); @@ -122,10 +122,10 @@ bool Menus::runMenuSelection() // if the button was long pressed then select this menu, but we // need to check the presstime to ensure we don't catch the initial // release after opening the ringmenu - if (g_pButton->pressTime() >= m_openTime) { + if (g_pButtonM->pressTime() >= m_openTime) { // whether to open advanced menus or not - bool openAdv = (g_pButton->holdDuration() > ADV_MENU_DURATION_TICKS) && advMenus; - if (g_pButton->onLongClick()) { + bool openAdv = (g_pButtonM->holdDuration() > ADV_MENU_DURATION_TICKS) && advMenus; + if (g_pButtonM->onLongClick()) { // ringmenu is open so select the menu DEBUG_LOGF("Selected ringmenu %s", menuList[m_selection].menuName); // open the menu we have selected @@ -137,7 +137,7 @@ bool Menus::runMenuSelection() return true; } // if holding down to select the menu option - if (g_pButton->isPressed() && openAdv) { + if (g_pButtonM->isPressed() && openAdv) { // make it strobe aw yiss offtime = HYPERSTROBE_OFF_DURATION; ontime = HYPERSTROBE_ON_DURATION; @@ -154,7 +154,7 @@ bool Menus::runMenuSelection() } } // check if the advanced menus have been enabled - if (g_pButton->onConsecutivePresses(ADVANCED_MENU_CLICKS)) { + if (g_pButtonM->onConsecutivePresses(ADVANCED_MENU_CLICKS)) { // toggle the advanced menu Modes::setAdvancedMenus(!advMenus); // display a pink or red depending on whether the menu was enabled @@ -183,10 +183,10 @@ bool Menus::runCurMenu() return false; case Menu::MENU_CONTINUE: // if Menu continue run the click handlers for the menu - if (g_pButton->onShortClick()) { + if (g_pButtonM->onShortClick()) { m_pCurMenu->onShortClick(); } - if (g_pButton->onLongClick()) { + if (g_pButtonM->onLongClick()) { m_pCurMenu->onLongClick(); } break; @@ -247,16 +247,16 @@ void Menus::showSelection(RGBColor colval) { // blink the tip led white for 150ms when the short // click threshold has been surpassed - if (g_pButton->isPressed() && - g_pButton->holdDuration() > SHORT_CLICK_THRESHOLD_TICKS && - g_pButton->holdDuration() < (SHORT_CLICK_THRESHOLD_TICKS + MS_TO_TICKS(250))) { + if (g_pButtonM->isPressed() && + g_pButtonM->holdDuration() > SHORT_CLICK_THRESHOLD_TICKS && + g_pButtonM->holdDuration() < (SHORT_CLICK_THRESHOLD_TICKS + MS_TO_TICKS(250))) { Leds::setAll(colval); } } bool Menus::checkOpen() { - return m_menuState != MENU_STATE_NOT_OPEN && g_pButton->releaseTime() > m_openTime; + return m_menuState != MENU_STATE_NOT_OPEN && g_pButtonM->releaseTime() > m_openTime; } bool Menus::checkInMenu() diff --git a/VortexEngine/src/Modes/Modes.cpp b/VortexEngine/src/Modes/Modes.cpp index 48f69077a0..b5bdcdb8e5 100644 --- a/VortexEngine/src/Modes/Modes.cpp +++ b/VortexEngine/src/Modes/Modes.cpp @@ -68,7 +68,7 @@ void Modes::play() return; } // shortclick cycles to the next mode - if (g_pButton->onShortClick()) { + if (g_pButtonM->onShortClick()) { nextModeSkipEmpty(); } // play the current mode diff --git a/VortexEngine/src/VortexEngine.cpp b/VortexEngine/src/VortexEngine.cpp index 7467018604..dbd602d2f2 100644 --- a/VortexEngine/src/VortexEngine.cpp +++ b/VortexEngine/src/VortexEngine.cpp @@ -115,12 +115,12 @@ void VortexEngine::tick() // update the buttons to check for wake Buttons::update(); // several fast clicks will unlock the device - if (Modes::locked() && g_pButton->onConsecutivePresses(DEVICE_LOCK_CLICKS - 1)) { + if (Modes::locked() && g_pButtonM->onConsecutivePresses(DEVICE_LOCK_CLICKS - 1)) { // turn off the lock flag and save it to disk Modes::setLocked(false); } // check for any kind of press to wakeup - if (g_pButton->check() || g_pButton->onRelease() || !Vortex::sleepEnabled()) { + if (g_pButtonM->check() || g_pButtonM->onRelease() || !Vortex::sleepEnabled()) { wakeup(); } return; @@ -160,14 +160,14 @@ void VortexEngine::runMainLogic() } // check if we should enter the menu - if (g_pButton->isPressed() && g_pButton->holdDuration() > MENU_TRIGGER_THRESHOLD_TICKS) { + if (g_pButtonM->isPressed() && g_pButtonM->holdDuration() > MENU_TRIGGER_THRESHOLD_TICKS) { DEBUG_LOG("Entering Menu Selection..."); Menus::openMenuSelection(); return; } // toggle auto cycle mode with many clicks at main modes - if (g_pButton->onConsecutivePresses(AUTO_CYCLE_MODES_CLICKS)) { + if (g_pButtonM->onConsecutivePresses(AUTO_CYCLE_MODES_CLICKS)) { m_autoCycle = !m_autoCycle; Leds::holdAll(m_autoCycle ? RGB_GREEN : RGB_RED); }