Skip to content

Commit 1bac251

Browse files
committed
Daniel/duo/blend improvement (#74)
* blend improvements
1 parent e5b7090 commit 1bac251

File tree

5 files changed

+45
-41
lines changed

5 files changed

+45
-41
lines changed

VortexEngine/src/Modes/DefaultModes.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ const default_mode_entry default_modes[] = {
3636
0x00001C
3737
}
3838
},
39+
3940
{
4041
PATTERN_ZIGZAG, 6, {
4142
RGB_OFF,

VortexEngine/src/Patterns/PatternBuilder.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,12 @@ PatternArgs PatternBuilder::getDefaultArgs(PatternID id)
153153
case PATTERN_TRACER: return PatternArgs(ULTRADOPS_ON_DURATION, 0, 0, 20, 1);
154154
case PATTERN_RIBBON: return PatternArgs(RIBBON_DURATION);
155155
case PATTERN_MINIRIBBON: return PatternArgs(1);
156-
case PATTERN_BLEND: return PatternArgs(DOPS_ON_DURATION, DOPS_OFF_DURATION, 0, 0, 0, 0, 1);
156+
case PATTERN_BLEND: return PatternArgs(BLEND_ON_DURATION, BLEND_OFF_DURATION, 0, 0, 0, 2, 1);
157157
case PATTERN_BLENDSTROBE: return PatternArgs(STROBE_ON_DURATION, STROBE_OFF_DURATION, 0, 0, 0, 0, 1);
158-
case PATTERN_COMPLEMENTARY_BLEND: return PatternArgs(2, 13, 0, 0, 0, 0, 2);
158+
case PATTERN_BLENDSTROBEGAP: return PatternArgs(STROBE_ON_DURATION, STROBE_OFF_DURATION, 75, 0, 0, 9, 1);
159+
case PATTERN_COMPLEMENTARY_BLEND: return PatternArgs(BLEND_ON_DURATION, BLEND_OFF_DURATION, 0, 0, 0, 2, 2);
159160
case PATTERN_COMPLEMENTARY_BLENDSTROBE: return PatternArgs(STROBE_ON_DURATION, STROBE_OFF_DURATION, 0, 0, 0, 0, 2);
161+
case PATTERN_COMPLEMENTARY_BLENDSTROBEGAP: return PatternArgs(STROBE_ON_DURATION, STROBE_OFF_DURATION, 75, 0, 0, 9, 2);
160162
case PATTERN_SOLID: return PatternArgs(250);
161163

162164
// =====================
@@ -241,8 +243,10 @@ Pattern *PatternBuilder::generate(PatternID id, const PatternArgs *userArgs)
241243
case PATTERN_MINIRIBBON: return new BasicPattern(args);
242244
case PATTERN_BLEND:
243245
case PATTERN_BLENDSTROBE:
246+
case PATTERN_BLENDSTROBEGAP:
244247
case PATTERN_COMPLEMENTARY_BLEND:
245-
case PATTERN_COMPLEMENTARY_BLENDSTROBE: return new BlendPattern(args);
248+
case PATTERN_COMPLEMENTARY_BLENDSTROBE:
249+
case PATTERN_COMPLEMENTARY_BLENDSTROBEGAP: return new BlendPattern(args);
246250
case PATTERN_SOLID: return new SolidPattern(args);
247251

248252
// =====================

VortexEngine/src/Patterns/Patterns.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,10 @@ enum PatternID : int8_t
4949
PATTERN_MINIRIBBON,
5050
PATTERN_BLEND,
5151
PATTERN_BLENDSTROBE,
52+
PATTERN_BLENDSTROBEGAP,
5253
PATTERN_COMPLEMENTARY_BLEND,
5354
PATTERN_COMPLEMENTARY_BLENDSTROBE,
55+
PATTERN_COMPLEMENTARY_BLENDSTROBEGAP,
5456
PATTERN_SOLID,
5557

5658
// ADD NEW SINGLE LED PATTERNS HERE

VortexEngine/src/Patterns/Single/BlendPattern.cpp

Lines changed: 31 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,37 @@ void BlendPattern::init()
3535

3636
void BlendPattern::onBlinkOn()
3737
{
38+
// if the current hue has reached the next hue
39+
if (m_cur == m_next) {
40+
// get the next color
41+
m_next = m_colorset.getNext();
42+
}
43+
// only transition the blend once every 4 ticks, this will make sure the blend doesn't go
44+
// to fast and it allows the blendspeed parameter to speed it up to preference
45+
if ((Time::getCurtime() % 4) == 0) {
46+
// transition each value of the current hsv to the next hsv, the 'hue' has a
47+
// special handling where 255 is beside 0 (circular transition)
48+
transitionValue(m_cur.hue, m_next.hue, true);
49+
transitionValue(m_cur.sat, m_next.sat, false);
50+
transitionValue(m_cur.val, m_next.val, false);
51+
}
52+
// make a copy of the current color being rendered so that it can be
53+
// flipped to an inverse color if the flips are enabled
54+
HSVColor hsvCol = m_cur;
55+
// flip the hue if there is any flips
3856
if (m_flip) {
39-
// do a flip as bender would say
40-
doFlip();
41-
} else {
42-
// if there is no flips then just do a normal blink
43-
doBlink();
57+
// note: no division by zero because m_numFlips cannot be 0 if m_flip is non-zero
58+
hsvCol.hue += (m_flip * (255 / m_numFlips));
4459
}
45-
// now if there is a flip amount set
46-
if (m_numFlips > 0) {
47-
// then increase the flip counter and modulate it
48-
m_flip = (m_flip + 1) % m_numFlips;
60+
// convert the HSV to RGB with the generic function because
61+
// this will generate a different appearance from using the
62+
// default hsv_to_rgb_rainbow()
63+
Leds::setIndex(m_ledPos, hsv_to_rgb_generic(hsvCol));
64+
// increase the flip counter and modulate it, this actually takes less space
65+
// on avr than using a modulo of numflips, because you must check for nonzero
66+
m_flip++;
67+
if (m_flip >= m_numFlips) {
68+
m_flip = 0;
4969
}
5070
}
5171

@@ -87,33 +107,6 @@ void BlendPattern::transitionValue(uint8_t &current, const uint8_t next, bool hu
87107
if (hue) {
88108
// wrap around the hue automatically, this handles for example if step is -1
89109
// and it subtracts past 0 to -1, then adding 256 will result in 255
90-
current = (current + 256) % 256;
91-
}
92-
}
93-
94-
void BlendPattern::doBlink()
95-
{
96-
// if the current hue has reached the next hue
97-
if (m_cur == m_next) {
98-
// get the next color
99-
m_next = m_colorset.getNext();
110+
current += 256;
100111
}
101-
// transition each value of the current hsv to the next hsv, the 'hue' has a
102-
// special handling where 255 is beside 0 (circular transition)
103-
transitionValue(m_cur.hue, m_next.hue, true);
104-
transitionValue(m_cur.sat, m_next.sat, false);
105-
transitionValue(m_cur.val, m_next.val, false);
106-
// set the target led with the current HSV color
107-
Leds::setIndex(m_ledPos, hsv_to_rgb_generic(m_cur));
108-
}
109-
110-
void BlendPattern::doFlip()
111-
{
112-
uint32_t hueOffset = m_flip * (255 / m_numFlips);
113-
// generate an inverse hue based on the current hue position
114-
HSVColor hsvCol((m_cur.hue + hueOffset) % 256, m_cur.sat, m_cur.val);
115-
// convert the HSV to RGB with the generic function because
116-
// this will generate a different appearance from using the
117-
// default hsv_to_rgb_rainbow()
118-
Leds::setIndex(m_ledPos, hsv_to_rgb_generic(hsvCol));
119-
}
112+
}

VortexEngine/src/Time/Timings.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@
5555
#define SIGNAL_ON_DURATION 10
5656
#define SIGNAL_OFF_DURATION 296
5757

58+
// A blink speed good for blends
59+
#define BLEND_ON_DURATION 2
60+
#define BLEND_OFF_DURATION 13
61+
5862
// Ribbon
5963
#define RIBBON_DURATION 6
6064

0 commit comments

Comments
 (0)