Skip to content

Commit

Permalink
Adjusted menu buttons to be more consistent
Browse files Browse the repository at this point in the history
  • Loading branch information
LivingSynthesis committed Dec 20, 2024
1 parent 6724ea4 commit 9f0db64
Show file tree
Hide file tree
Showing 8 changed files with 124 additions and 21 deletions.
3 changes: 3 additions & 0 deletions VortexEngine/src/Menus/MainMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ bool MainMenu::run()
if (g_pButtonM->onShortClick()) {
select();
}
if (g_pButtonM->onLongClick()) {
select();
}
// press >
if (g_pButtonR->onShortClick()) {
pressRight();
Expand Down
2 changes: 1 addition & 1 deletion VortexEngine/src/Menus/Menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
57 changes: 40 additions & 17 deletions VortexEngine/src/Menus/MenuList/FactoryReset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
}

3 changes: 2 additions & 1 deletion VortexEngine/src/Menus/MenuList/FactoryReset.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
17 changes: 16 additions & 1 deletion VortexEngine/src/Menus/MenuList/GlobalBrightness.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 2 additions & 0 deletions VortexEngine/src/Menus/MenuList/GlobalBrightness.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
57 changes: 56 additions & 1 deletion VortexEngine/src/Menus/MenuList/PatternSelect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions VortexEngine/src/Menus/MenuList/PatternSelect.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 9f0db64

Please sign in to comment.