Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Started fixing patterns and buttons #273

Merged
merged 6 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions VortexEngine/src/Leds/LedTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,13 @@ inline LedPos ledmapGetNextLed(LedMap map, LedPos pos)
#define MAP_LINE_4 (MAP_LED(LED_3) | MAP_LED(LED_13) | MAP_LED(LED_18) | MAP_LED(LED_8))
#define MAP_LINE_5 (MAP_LED(LED_4) | MAP_LED(LED_14) | MAP_LED(LED_19) | MAP_LED(LED_9))

//Chromadeck bitmap
#define MAP_OPPOSITES_1 (MAP_LED(LED_0) | MAP_LED(LED_5) | MAP_LED(LED_10) | MAP_LED(LED_15))
#define MAP_OPPOSITES_2 (MAP_LED(LED_1) | MAP_LED(LED_6) | MAP_LED(LED_11) | MAP_LED(LED_16))
#define MAP_OPPOSITES_3 (MAP_LED(LED_2) | MAP_LED(LED_7) | MAP_LED(LED_12) | MAP_LED(LED_17))
#define MAP_OPPOSITES_4 (MAP_LED(LED_3) | MAP_LED(LED_8) | MAP_LED(LED_13) | MAP_LED(LED_18))
#define MAP_OPPOSITES_5 (MAP_LED(LED_4) | MAP_LED(LED_9) | MAP_LED(LED_14) | MAP_LED(LED_19))

// set a single led
inline void ledmapSetLed(LedMap &map, LedPos pos)
{
Expand Down
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
59 changes: 57 additions & 2 deletions 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 All @@ -72,7 +82,7 @@ void PatternSelect::nextPatternID()
beginList = PATTERN_MULTI_FIRST;
}
#endif
m_newPatternID = (PatternID)((m_newPatternID + 1) % endList);
m_newPatternID = (PatternID)((m_newPatternID + 1) % (endList + 1));
if (m_newPatternID > endList || m_newPatternID < beginList) {
m_newPatternID = beginList;
}
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
21 changes: 21 additions & 0 deletions VortexEngine/src/Modes/DefaultModes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,27 @@ const default_mode_entry default_modes[MAX_MODES] = {
RGB_GREEN,
RGB_BLUE
}
},
{
PATTERN_STROBE, 2, {
RGB_RED,
RGB_GREEN,
}
},
{
PATTERN_DRIP, 4, {
RGB_RED,
RGB_GREEN,
RGB_BLUE,
RGB_YELLOW
}
},
{
PATTERN_DASHCYCLE, 3, {
RGB_RED,
RGB_GREEN,
RGB_BLUE
}
}
};

Expand Down
8 changes: 4 additions & 4 deletions VortexEngine/src/Patterns/Multi/BouncePattern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include "../../Log/Log.h"

// safety to prevent divide by 0
#define TOTAL_STEPS (((PAIR_COUNT * 2) - 2) ? ((PAIR_COUNT * 2) - 2) : 1)
#define TOTAL_STEPS (((LED_COUNT * 2) - 2) ? ((LED_COUNT * 2) - 2) : 1)
#define HALF_STEPS (TOTAL_STEPS / 2)

BouncePattern::BouncePattern(const PatternArgs &args) :
Expand Down Expand Up @@ -36,10 +36,10 @@ void BouncePattern::init()
void BouncePattern::blinkOn()
{
Leds::setAll(m_colorset.cur());
if (m_progress < PAIR_COUNT) {
Leds::setPair((Pair)m_progress, m_colorset.peekNext());
if (m_progress < LED_COUNT) {
Leds::setIndex((LedPos)m_progress, m_colorset.peekNext());
} else {
Leds::setPair((Pair)(TOTAL_STEPS - m_progress), m_colorset.peekNext());
Leds::setIndex((LedPos)(TOTAL_STEPS - m_progress), m_colorset.peekNext());
}
}

Expand Down
6 changes: 3 additions & 3 deletions VortexEngine/src/Patterns/Multi/FillPattern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ void FillPattern::init()

void FillPattern::blinkOn()
{
Leds::setPairs(PAIR_FIRST, (Pair)m_progress, m_colorset.peekNext());
Leds::setPairs((Pair)m_progress, PAIR_COUNT, m_colorset.cur());
Leds::setRange(LED_FIRST, (LedPos)m_progress, m_colorset.peekNext());
Leds::setRange((LedPos)m_progress, LED_LAST, m_colorset.cur());
}

void FillPattern::poststep()
{
m_progress = (m_progress + 1) % PAIR_COUNT;
m_progress = (m_progress + 1) % LED_COUNT;
if (m_progress == 0) {
m_colorset.getNext();
}
Expand Down
16 changes: 12 additions & 4 deletions VortexEngine/src/Patterns/Multi/HueShiftPattern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,17 @@ void HueShiftPattern::play()
m_cur.hue += sign;
}
HSVColor showColor = HSVColor(m_cur.hue, 255, 255);
// set the target led with the current HSV color
for (LedPos pos = LED_FIRST; pos < LED_COUNT; ++pos) {
Leds::setIndex(pos, hsv_to_rgb_generic(showColor));
showColor.hue = (showColor.hue + 5) % 256;

// variable amount to shift, more LEDs should have smaller shifts
uint8_t shiftAmount = 108 / LED_COUNT;
// if you increment color with each led index there's a sharp contrast between the first and last led
// instead this creates a perfectly looped gradient between the first and last led which is better
for (LedPos pos = LED_FIRST; pos < (LED_COUNT / 2) + 1; ++pos) {
if (((LED_COUNT / 2) + pos) != LED_COUNT) {
// set the target led with the current HSV color
Leds::setIndex((LedPos)((LED_COUNT / 2) + pos), hsv_to_rgb_generic(showColor));
}
Leds::setIndex((LedPos)((LED_COUNT / 2) - pos), hsv_to_rgb_generic(showColor));
showColor.hue = (showColor.hue + shiftAmount) % 256;
}
}
Loading
Loading