Skip to content

Commit

Permalink
Fixes for buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
Unreal-Dan committed Nov 3, 2023
1 parent 3a06828 commit cf8e27b
Show file tree
Hide file tree
Showing 11 changed files with 40 additions and 34 deletions.
8 changes: 6 additions & 2 deletions VortexEngine/src/Buttons/Button.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 0 additions & 2 deletions VortexEngine/src/Buttons/Buttons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@

// Button Left
Button *g_pButtonL = nullptr;

// Button Mid
Button *g_pButtonM = nullptr;

// Button Right
Button *g_pButtonR = nullptr;

Expand Down
8 changes: 6 additions & 2 deletions VortexEngine/src/Buttons/Buttons.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 3 additions & 3 deletions VortexEngine/src/Menus/Menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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;
}
Expand Down
6 changes: 3 additions & 3 deletions VortexEngine/src/Menus/MenuList/ColorSelect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions VortexEngine/src/Menus/MenuList/FactoryReset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion VortexEngine/src/Menus/MenuList/PatternSelect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion VortexEngine/src/Menus/MenuList/Randomizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 12 additions & 12 deletions VortexEngine/src/Menus/Menus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
Expand All @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion VortexEngine/src/Modes/Modes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions VortexEngine/src/VortexEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit cf8e27b

Please sign in to comment.