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

Shane/gloves/polish #225

Merged
merged 41 commits into from
May 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
30335cb
Fixed colorset applies to Led Selection only
LivingSynthesis Apr 18, 2024
7bc8b12
Colorselect fixed target blink
LivingSynthesis Apr 19, 2024
829575f
Hue1 select was being skipped
LivingSynthesis Apr 19, 2024
74b30e4
Fixed patten select affects only target leds
LivingSynthesis Apr 19, 2024
63b225c
added serial fixes
Unreal-Dan Apr 25, 2024
1df6910
more adjustments
Unreal-Dan Apr 25, 2024
6eda2d7
minor adjustments
Unreal-Dan Apr 25, 2024
d87bb73
fixed test 11, looks like bad recording
Unreal-Dan Apr 25, 2024
9e3d2cf
fixed led map confusion
Unreal-Dan Apr 25, 2024
0c08df0
recorded test 17 seems to just be bad recording
Unreal-Dan Apr 25, 2024
f821184
removed adv menu tests
Unreal-Dan Apr 25, 2024
bd22c64
renamed front bulb to multi led
Unreal-Dan Apr 25, 2024
6bde7fc
renamed both bulbs tests to all bulbs
Unreal-Dan Apr 25, 2024
c9c2314
renamed top bulbs to all tips
Unreal-Dan Apr 25, 2024
cdbc4f8
new tests for gloves, fixed up test list script
Unreal-Dan Apr 25, 2024
be0024a
fixes for tests and auto cycle
Unreal-Dan Apr 26, 2024
d04bc53
more fixes
Unreal-Dan Apr 26, 2024
2da7736
fix for makefile to run trinket mod
Unreal-Dan Apr 26, 2024
90b1a5c
restored makefile
Unreal-Dan Apr 26, 2024
33420a3
minor fix
Unreal-Dan Apr 26, 2024
768bc44
Changed delete to be consistent with other devices
LivingSynthesis Apr 26, 2024
f43054f
Changed Factory reset visual to match Duo
LivingSynthesis Apr 26, 2024
1528efc
fixes for pat select and bad breath
Unreal-Dan Apr 26, 2024
82124f0
Merge branch 'shane/gloves/polish' of https://github.com/Unreal-Dan/V…
Unreal-Dan Apr 26, 2024
290b179
breath finger
Unreal-Dan Apr 26, 2024
2d602c0
fixed menu tests
Unreal-Dan Apr 26, 2024
045486e
removed unused var
Unreal-Dan Apr 26, 2024
44cf964
don't need these vars
Unreal-Dan Apr 26, 2024
0fc813f
Merge branch 'gloves' into shane/gloves/polish
Unreal-Dan Apr 26, 2024
cb59422
minor fix
Unreal-Dan Apr 26, 2024
fe697fa
Merge branch 'gloves' into shane/gloves/polish
Unreal-Dan Apr 26, 2024
dbb9138
fixed bounce pattern
LivingSynthesis Apr 26, 2024
dd93e90
Merge branch 'gloves' into shane/gloves/polish
Unreal-Dan Apr 26, 2024
dc36d0e
Merge branch 'shane/gloves/polish' of https://github.com/Unreal-Dan/V…
Unreal-Dan Apr 26, 2024
32696d3
recorded tests
Unreal-Dan Apr 26, 2024
c65b90f
Merge branch 'gloves' into shane/gloves/polish
Unreal-Dan Apr 26, 2024
c5bdba0
added split randomizer
LivingSynthesis Apr 27, 2024
3ad0d5e
attempted fix of pattern select
Unreal-Dan Apr 30, 2024
81ed8f8
dont need this line
Unreal-Dan Apr 30, 2024
b538bf8
Merge branch 'gloves' into shane/gloves/polish
Unreal-Dan May 1, 2024
783d4f8
recorded tests
Unreal-Dan May 1, 2024
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
4 changes: 2 additions & 2 deletions VortexEngine/src/Leds/LedTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ typedef Pair Finger;

#define ledToFinger(led) ledToPair(led)

#define setFinger(map, finger) setPair(map, finger)
#define checkFinger(map, finger) checkPair(map, finger)
#define ledmapSetFinger(map, finger) ledmapSetPair(map, finger)
#define ledmapCheckFinger(map, finger) ledmapCheckPair(map, finger)

// check if an led is even or odd
#define isEven(pos) ((pos % 2) == 0)
Expand Down
15 changes: 15 additions & 0 deletions VortexEngine/src/Leds/Leds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@ void Leds::setPairs(Pair first, Pair last, RGBColor col)
setRange(pairEven(first), pairOdd(last), col);
}

void Leds::setFinger(Finger finger, RGBColor col)
{
setRange(fingerTip(finger), fingerTop(finger), col);
}

void Leds::setRangeEvens(Pair first, Pair last, RGBColor col)
{
for (Pair pos = first; pos <= last; pos++) {
Expand Down Expand Up @@ -236,6 +241,11 @@ void Leds::blinkRangeOffset(LedPos first, LedPos last, uint32_t time, uint16_t o
}
}

void Leds::blinkFingerOffset(Finger target, uint32_t time, uint16_t offMs, uint16_t onMs, RGBColor col)
{
blinkRangeOffset(fingerTip(target), fingerTop(target), time, offMs, onMs, col);
}

void Leds::blinkIndex(LedPos target, uint16_t offMs, uint16_t onMs, RGBColor col)
{
if ((Time::getCurtime() % MS_TO_TICKS(offMs + onMs)) < MS_TO_TICKS(onMs)) {
Expand Down Expand Up @@ -292,6 +302,11 @@ void Leds::breatheRange(LedPos first, LedPos last, uint8_t hue, uint32_t varianc
setRange(first, last, HSVColor((uint8_t)(hue + ((sin(variance * 0.0174533) + 1) * magnitude)), sat, val));
}

void Leds::breatheFinger(Finger finger, uint8_t hue, uint32_t variance, uint32_t magnitude, uint8_t sat, uint8_t val)
{
breatheRange(fingerTip(finger), fingerTop(finger), hue, variance, magnitude, sat, val);
}

void Leds::breatheIndexSat(LedPos target, uint8_t hue, uint32_t variance, uint32_t magnitude, uint8_t sat, uint8_t val)
{
setIndex(target, HSVColor(hue, 255 - (uint8_t)(sat + 128 + ((sin(variance * 0.0174533) + 1) * magnitude)), val));
Expand Down
9 changes: 9 additions & 0 deletions VortexEngine/src/Leds/Leds.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,16 @@ class Leds
static void setPair(Pair pair, RGBColor col);
static void setPairs(Pair first, Pair last, RGBColor col);

// set a single finger to a color
static void setFinger(Finger finger, RGBColor col);

// Turn off both LEDs on a pair, these are appropriate for use in internal pattern logic
static void clearPair(Pair pair) { setPair(pair, RGB_OFF); }
static void clearPairs(Pair first, Pair last) { setPairs(first, last, RGB_OFF); }

// clear the led on a single finger
static void clearFinger(Finger finger) { setFinger(finger, RGB_OFF); }

// Controll pair evens
static void setRangeEvens(Pair first, Pair last, RGBColor);
static void setAllEvens(RGBColor col);
Expand Down Expand Up @@ -78,6 +84,7 @@ class Leds
// is unpredictable whether they will blink on or off first
static void blinkIndexOffset(LedPos target, uint32_t time, uint16_t offMs = 250, uint16_t onMs = 500, RGBColor col = RGB_OFF);
static void blinkRangeOffset(LedPos first, LedPos last, uint32_t time, uint16_t offMs = 250, uint16_t onMs = 500, RGBColor col = RGB_OFF);
static void blinkFingerOffset(Finger target, uint32_t time, uint16_t offMs = 250, uint16_t onMs = 500, RGBColor col = RGB_OFF);
static void blinkIndex(LedPos target, uint16_t offMs = 250, uint16_t onMs = 500, RGBColor col = RGB_OFF);
static void blinkRange(LedPos first, LedPos last, uint16_t offMs = 250, uint16_t onMs = 500, RGBColor col = RGB_OFF);
static void blinkMap(LedMap targets, uint16_t offMs = 250, uint16_t onMs = 500, RGBColor col = RGB_OFF);
Expand All @@ -92,6 +99,8 @@ class Leds
uint32_t magnitude = 15, uint8_t sat = 255, uint8_t val = 210);
static void breatheRange(LedPos first, LedPos last, uint8_t hue, uint32_t variance,
uint32_t magnitude = 15, uint8_t sat = 255, uint8_t val = 210);
static void breatheFinger(Finger finger, uint8_t hue, uint32_t variance,
uint32_t magnitude = 15, uint8_t sat = 255, uint8_t val = 210);
static void breatheIndexSat(LedPos target, uint8_t hue, uint32_t variance,
uint32_t magnitude = 15, uint8_t sat = 255, uint8_t val = 210);
static void breatheIndexVal(LedPos target, uint8_t hue, uint32_t variance,
Expand Down
6 changes: 3 additions & 3 deletions VortexEngine/src/Menus/Menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ Menu::MenuAction Menu::run()
}
// on a long press of the button, lock in the target led
if (g_pButton->onLongClick()) {
m_targetLeds = ledPermutations[m_ledSelection];
m_ledSelected = true;
// call led selected callback
onLedSelected();
Expand Down Expand Up @@ -199,9 +200,8 @@ void Menu::blinkSelection(uint32_t offMs, uint32_t onMs)
blinkCol = RGB_WHITE0;
}
// blink the target finger to the target color
Leds::blinkIndexOffset(fingerTip(m_curSelection),
g_pButton->isPressed() ? g_pButton->holdDuration() : Time::getCurtime(),
offMs, onMs, blinkCol);
uint32_t blinkDur = g_pButton->isPressed() ? g_pButton->holdDuration() : Time::getCurtime();
Leds::blinkFingerOffset(m_curSelection, blinkDur, offMs, onMs, blinkCol);
break;
}
}
6 changes: 2 additions & 4 deletions VortexEngine/src/Menus/MenuList/ColorSelect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ ColorSelect::ColorSelect(const RGBColor &col, bool advanced) :
m_state(STATE_PICK_SLOT),
m_curPage(0),
m_slot(0),
m_quadrant(0),
m_newColor()
{
// NOTE! Specifically using hsv_to_rgb_rainbow instead of generic because
Expand Down Expand Up @@ -168,7 +167,7 @@ void ColorSelect::onLongClick()
// if we need to save, then actually update the colorset
if (needsSave) {
// save the colorset
cur->setColorset(m_colorset);
cur->setColorsetMap(m_targetLeds, m_colorset);
cur->init();
}
// leave menu and save if we made changes
Expand Down Expand Up @@ -203,7 +202,6 @@ void ColorSelect::onLongClick()
m_curPage = m_slot / PAGE_SIZE;
return;
}
m_state = STATE_PICK_HUE1;
// the page is only used for slot selection so reset current page
// for next time they use the color select
m_curPage = 0;
Expand Down Expand Up @@ -302,7 +300,7 @@ void ColorSelect::blinkSelection(uint32_t offMs, uint32_t onMs)
// if we're pressing down on a slot then glow the tip white/red
if ((g_pButton->holdDuration() % (DELETE_CYCLE_TICKS * 2)) > DELETE_CYCLE_TICKS) {
// breath red instead of white blink
Leds::breatheIndex(fingerTip(m_curSelection), 0, g_pButton->holdDuration());
Leds::breatheFinger(m_curSelection, 0, g_pButton->holdDuration());
return;
}
}
Expand Down
3 changes: 0 additions & 3 deletions VortexEngine/src/Menus/MenuList/ColorSelect.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,6 @@ class ColorSelect : public Menu
// the target color slot to change
uint32_t m_slot;

// the chosen quadrant
uint32_t m_quadrant;

// the new color to set
HSVColor m_newColor;
};
Expand Down
6 changes: 2 additions & 4 deletions VortexEngine/src/Menus/MenuList/FactoryReset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ void FactoryReset::showReset()
if (!g_pButton->isPressed()) {
// just idle blink from clear to blank
Leds::clearRange(LED_FIRST, INDEX_TOP);
Leds::blinkRange(LED_FIRST, INDEX_TOP, 250, 150, RGB_WHITE0);
Leds::blinkRange(LED_FIRST, INDEX_TOP, 250, 150, RGB_RED0);
return;
}

Expand All @@ -145,16 +145,14 @@ void FactoryReset::showReset()
// the off/on ms blink faster based on the progress
uint32_t offMs = 150 - (12 * ledProgress);
uint32_t onMs = 200 - (10 * ledProgress);
// the hue gets more red starting at 20 going in steps of 4 to min 0
int8_t hue = (ledProgress < 6) ? 20 - (4 * ledProgress) : 0;
// 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)(INDEX_TOP - ledProgress);
// clear all the leds so that 'blinkRange' will blink from off to the designated color
Leds::clearRange(LED_FIRST, INDEX_TOP);
// blink to the calculated redish hue from pinky to the end led
Leds::blinkRange(LED_FIRST, endLed, offMs, onMs, HSVColor(hue, 255, 180));
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), INDEX_TOP, offMs, onMs, RGB_WHITE0);
}
Expand Down
86 changes: 66 additions & 20 deletions VortexEngine/src/Menus/MenuList/PatternSelect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ bool PatternSelect::init()
return false;
}
m_state = STATE_PICK_LIST;
m_newPatternID = PATTERN_FIRST;
DEBUG_LOG("Entered pattern select");
return true;
}
Expand Down Expand Up @@ -60,6 +59,7 @@ Menu::MenuAction PatternSelect::run()

void PatternSelect::showListSelection()
{
Leds::clearAll();
for (Finger f = FINGER_PINKIE; f <= FINGER_INDEX; ++f) {
// hue split into 4 quadrants of 90
Leds::breatheIndex(fingerTop(f), f * (255/4), (uint32_t)Time::getCurtime() / 3, 10, 255, 255);
Expand All @@ -77,8 +77,18 @@ void PatternSelect::showPatternSelection()

void PatternSelect::onLedSelected()
{
m_previewMode.setPatternMap(m_targetLeds, PATTERN_FIRST);
m_previewMode.init();
// need to ready up the preview mode for picking patterns, this can look different based on
// which pattern was already on this mode, and which leds they decided to pick
// for example if they had a multi-led pattern and they are targetting some grouping of singles now
// then we need to convert the multi into singles, maybe in the future we can allow singles to overlay
if (m_previewMode.isMultiLed() && m_targetLeds != MAP_LED_ALL && m_targetLeds != MAP_LED(LED_MULTI)) {
Colorset curSet = m_previewMode.getColorset();
m_previewMode.setPattern(PATTERN_FIRST, LED_ALL_SINGLE, nullptr, &curSet);
// todo: clear multi a better way, automatically when setting singles?
m_previewMode.clearPattern(LED_MULTI);
m_previewMode.init();
DEBUG_LOG("Converted existing multi-led pattern to singles for given led selection");
}
}

void PatternSelect::onShortClick()
Expand All @@ -94,43 +104,79 @@ void PatternSelect::onShortClick()
}
}

void PatternSelect::nextPattern()
void PatternSelect::nextPatternID()
{
// increment to next pattern
m_newPatternID = (PatternID)((m_newPatternID + 1) % PATTERN_COUNT);
if (!m_started) {
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
m_newPatternID = (PatternID)((m_newPatternID + 1) % endList);
if (m_newPatternID > endList || m_newPatternID < beginList) {
m_newPatternID = beginList;
}
}

void PatternSelect::nextPattern()
{
if (m_started) {
nextPatternID();
} else {
m_started = true;
m_newPatternID = PATTERN_FIRST;
// 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);
}
// change the pattern of demo mode
m_previewMode.setPattern(m_newPatternID);
m_previewMode.init();
DEBUG_LOGF("Demoing Pattern %u", m_newPatternID);
DEBUG_LOGF("Iterated to pattern id %d", m_newPatternID);
}

void PatternSelect::onLongClick()
{
bool needsSave = false;
Mode *cur = Modes::curMode();
switch (m_state) {
case STATE_PICK_LIST:
if (m_curSelection == FINGER_THUMB) {
leaveMenu();
return;
}
// if targeted multi then start at multis and only iterate multis
if ((m_targetLeds == MAP_LED(LED_MULTI))) {
// the selected multi only iterate multis
m_newPatternID = (PatternID)(PATTERN_MULTI_FIRST + (m_curSelection * (PATTERN_MULTI_COUNT / 4)));
} else if ((m_targetLeds != MAP_LED_ALL)) {
// they selected some singles, only iterate single led patterns
m_newPatternID = (PatternID)(PATTERN_SINGLE_FIRST + (m_curSelection * (PATTERN_SINGLE_COUNT / 4)));
} else {
// otherwise they selected all divide the entire list
m_newPatternID = (PatternID)(PATTERN_FIRST + (m_curSelection * (PATTERN_COUNT / 4)));
}
m_state = STATE_PICK_PATTERN;
// start the new pattern ID selection based on the chosen list
m_newPatternID = (PatternID)(PATTERN_FIRST + (m_curSelection * (PATTERN_COUNT / 4)));
m_previewMode.setPattern(m_newPatternID);
m_previewMode.init();
DEBUG_LOGF("Started picking pattern at %u", m_newPatternID);
break;
case STATE_PICK_PATTERN:
// need to save the new pattern if it's different from current
needsSave = (cur->getPatternID() != m_newPatternID);
// store the new pattern in the mode
cur->setPattern(m_newPatternID);
cur->init();
needsSave = !Modes::curMode()->equals(&m_previewMode);
if (needsSave) {
// update the current mode with the new pattern
Modes::updateCurMode(&m_previewMode);
}
DEBUG_LOGF("Saving pattern %u", m_newPatternID);
// go back to beginning for next time
m_state = STATE_PICK_LIST;
Expand Down
4 changes: 1 addition & 3 deletions VortexEngine/src/Menus/MenuList/PatternSelect.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class PatternSelect : public Menu
private:
void showListSelection();
void showPatternSelection();
void nextPatternID();
void nextPattern();

void showExit() override;
Expand All @@ -41,9 +42,6 @@ class PatternSelect : public Menu
// the current state of the pattern selection menu
PatternSelectState m_state;

// an internal mode used for demoing patterns
Mode m_demoMode;

// the patternid of the current demo
PatternID m_newPatternID;

Expand Down
55 changes: 54 additions & 1 deletion VortexEngine/src/Menus/MenuList/Randomizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,20 @@
#include "../../Leds/Leds.h"
#include "../../Log/Log.h"

static LedMap maps[] = {
MAP_PAIR_EVENS,
MAP_PAIR_ODDS,
MAP_ODD_FINGERS,
MAP_EVEN_FINGERS,
MAP_FINGER(FINGER_THUMB),
MAP_FINGER(FINGER_INDEX),
MAP_FINGER(FINGER_MIDDLE),
MAP_FINGER(FINGER_RING),
MAP_FINGER(FINGER_PINKIE)
};

#define NUM_MAPS (sizeof(maps) / sizeof(maps[0]))

Randomizer::Randomizer(const RGBColor &col, bool advanced) :
Menu(col, advanced),
m_lastRandomization(0),
Expand Down Expand Up @@ -172,7 +186,12 @@ void Randomizer::showRandomizationSelect()

#if VORTEX_SLIM == 0
bool Randomizer::reRollMulti()
{
{
// 50% chance to roll a 'split multi' which is a random mapping of singles half
// being one pattern/color and the other half being another pattern/color
if (m_multiRandCtx.next8() > 128) {
return splitMultiRandomize();
}
if (m_flags & RANDOMIZE_PATTERN) {
// TODO: Roll custom multi pattern?
//if (m_advanced) {
Expand All @@ -199,6 +218,40 @@ PatternID Randomizer::rollMultiLedPatternID(Random &ctx)
{
return (PatternID)ctx.next8(PATTERN_MULTI_FIRST, PATTERN_MULTI_LAST);
}

bool Randomizer::splitMultiRandomize()
{
// clear any existing patterns just in case a multi is set
m_previewMode.clearPattern();
// generate random bitmap of which leds to set
LedMap randomMap = maps[m_multiRandCtx.next8(0, (NUM_MAPS - 1))];
// roll all of one side of the map one way
if (!rollSinglesLedMap(m_multiRandCtx, randomMap)) {
ERROR_LOG("Failed to roll first half of split multi map");
return false;
}
// roll the flipped map with new singles
if (!rollSinglesLedMap(m_multiRandCtx, MAP_INVERSE(randomMap))) {
ERROR_LOG("Failed to roll first half of split multi map");
return false;
}
return true;
}

bool Randomizer::rollSinglesLedMap(Random& ctx, LedMap map)
{
// apply pattern2 and colorset2 to the inverse bitmap
PatternID pat = rollSingleLedPatternID(ctx);
Colorset set = rollColorset(ctx);
MAP_FOREACH_LED(map) {
// apply the pattern and colorset
if (!m_previewMode.setPattern(pat, pos, nullptr, &set)) {
ERROR_LOG("Failed to apply pattern or colorset");
return false;
}
}
return true;
}
#endif

bool Randomizer::reRollSingles()
Expand Down
Loading