feat: ESP-NOW link, beat sync and control messages in the C++ driver
- espnow_link, ctrl_msg and beat_sync: the reliable link, envelopes and beat-synced timing. - ctrl_msg: accept an envelope with the trailing save byte. - patterns_frame() and espnow_link_poll() split out of their tasks, so the WebAssembly simulator can drive one frame and one link pass from a timer. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
94e300f6ad
commit
24dd5ffb15
30 files changed
+2159
-158
No files matched your search
+65
-16
@@ -268,8 +268,7 @@ bool fx_chase(fx_t &f, st_t &s)
|
||||
(void)nc;
|
||||
int on_len = nz(f.pr->n[1], 3);
|
||||
int off_len = nz(f.pr->n[2], 2);
|
||||
int step = abs(sgn(f, nz(f.pr->n[3], 1)));
|
||||
if (step < 1) step = 1;
|
||||
int step = f.pr->n[3] == 0 ? 1 : f.pr->n[3]; // negative steps walk the other way
|
||||
int period = on_len + off_len;
|
||||
if (first_call(s)) {
|
||||
s.last = f.now;
|
||||
@@ -284,7 +283,7 @@ bool fx_chase(fx_t &f, st_t &s)
|
||||
int m = pmod(i + s.phase, period);
|
||||
putl(f, i, m < on_len ? col : bgc);
|
||||
}
|
||||
s.phase = pmod(s.phase + sgn(f, step), period);
|
||||
s.phase = pmod(s.phase + step, period);
|
||||
return !f.pr->autorun;
|
||||
}
|
||||
|
||||
@@ -296,10 +295,9 @@ bool fx_chase(fx_t &f, st_t &s)
|
||||
rgb color1 = ab(nc > 1 ? c[1] : c[0], b);
|
||||
int n1 = nz(f.pr->n[1], 1);
|
||||
int n2 = nz(f.pr->n[2], 1);
|
||||
// Always move forward: a negative n3/n4 would otherwise make the dot bounce back.
|
||||
// sgn() still applies the preset's reverse flag.
|
||||
int n3 = sgn(f, abs(f.pr->n[3]));
|
||||
int n4 = sgn(f, abs(f.pr->n[4]));
|
||||
// Steps may be negative: a negative n3/n4 walks the dot the other way. 0 (unset) means 1.
|
||||
int n3 = f.pr->n[3] == 0 ? 1 : f.pr->n[3];
|
||||
int n4 = f.pr->n[4] == 0 ? 1 : f.pr->n[4];
|
||||
int seg = n1 + n2;
|
||||
int max_pos = nled + seg;
|
||||
auto position = [&](int sc) {
|
||||
@@ -313,7 +311,7 @@ bool fx_chase(fx_t &f, st_t &s)
|
||||
};
|
||||
if (!f.pr->autorun) {
|
||||
chase_draw(f, position(s.sc), n1, n2, n3, n4, color0, color1);
|
||||
s.sc = (s.sc + 1) % 2;
|
||||
s.sc = (s.sc + 1) % (2 * max_pos); // the dot walks the whole cycle; even modulus keeps the parity
|
||||
return true;
|
||||
}
|
||||
uint32_t dur_ms = f.pr->delay < 10 ? 10 : f.pr->delay;
|
||||
@@ -322,7 +320,7 @@ bool fx_chase(fx_t &f, st_t &s)
|
||||
}
|
||||
if ((int32_t)(f.now - s.last) >= (int32_t)dur_ms) {
|
||||
chase_draw(f, position(s.sc), n1, n2, n3, n4, color0, color1);
|
||||
s.sc = (s.sc + 1) % 2;
|
||||
s.sc = (s.sc + 1) % (2 * max_pos); // the dot walks the whole cycle; even modulus keeps the parity
|
||||
s.last += dur_ms;
|
||||
}
|
||||
return false;
|
||||
@@ -495,6 +493,24 @@ bool fx_colour_cycle(fx_t &f, st_t &s)
|
||||
return false;
|
||||
}
|
||||
|
||||
// Rainbow: the spectrum wheel scrolling at n1 steps per frame (the controller's "rainbow" pattern)
|
||||
bool fx_rainbow(fx_t &f, st_t &s)
|
||||
{
|
||||
int step_amount = nz(f.pr->n[1], 1);
|
||||
if (!f.pr->autorun) {
|
||||
rainbow_render(f, s.phase);
|
||||
s.phase = pmod(s.phase + sgn(f, step_amount), 256);
|
||||
return true;
|
||||
}
|
||||
uint32_t d = f.pr->delay < 1 ? 1 : f.pr->delay;
|
||||
if (!due(f.now, s.last, d)) {
|
||||
return false;
|
||||
}
|
||||
rainbow_render(f, s.phase);
|
||||
s.phase = pmod(s.phase + sgn(f, step_amount), 256);
|
||||
return false;
|
||||
}
|
||||
|
||||
// ---- flicker -----------------------------------------------------------------------------------
|
||||
|
||||
bool fx_flicker(fx_t &f, st_t &s)
|
||||
@@ -787,6 +803,41 @@ bool fx_pulse(fx_t &f, st_t &s)
|
||||
|
||||
// ---- transition --------------------------------------------------------------------------------
|
||||
|
||||
// Wipe: the next colour sweeps in from the first LED to the last over `delay` ms, then becomes the
|
||||
// current colour and the one after it starts wiping in.
|
||||
bool fx_wipe(fx_t &f, st_t &s)
|
||||
{
|
||||
rgb c[PATTERN_MAX_COLOURS];
|
||||
int nc = get_colours(f, &WHITE, 1, c);
|
||||
int b = f.pr->brightness;
|
||||
if (nc == 1) {
|
||||
fill(f, ab(c[0], b));
|
||||
return false;
|
||||
}
|
||||
if (first_call(s)) {
|
||||
s.aux = f.now;
|
||||
}
|
||||
int duration = f.pr->delay < 10 ? 10 : (int)f.pr->delay;
|
||||
int elapsed = (int)(f.now - s.aux);
|
||||
if (elapsed >= duration) {
|
||||
if (!f.pr->autorun) {
|
||||
fill(f, ab(c[(s.ci + 1) % nc], b));
|
||||
return true;
|
||||
}
|
||||
s.ci = (s.ci + 1) % nc;
|
||||
s.aux = f.now;
|
||||
elapsed = 0;
|
||||
}
|
||||
rgb cur = c[s.ci % nc];
|
||||
rgb nxt = c[(s.ci + 1) % nc];
|
||||
int front = (elapsed * f.n) / duration; // LEDs already showing the next colour
|
||||
for (int i = 0; i < f.n; i++) {
|
||||
putl(f, i, ab(i < front ? nxt : cur, b));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Transition: the whole bar shows one colour, which fades from each colour to the next over `delay` ms.
|
||||
bool fx_transition(fx_t &f, st_t &s)
|
||||
{
|
||||
rgb c[PATTERN_MAX_COLOURS];
|
||||
@@ -808,14 +859,12 @@ bool fx_transition(fx_t &f, st_t &s)
|
||||
}
|
||||
s.ci = (s.ci + 1) % nc;
|
||||
s.aux = f.now;
|
||||
return false;
|
||||
elapsed = 0;
|
||||
}
|
||||
rgb c1 = c[s.ci % nc];
|
||||
rgb c2 = c[(s.ci + 1) % nc];
|
||||
float factor = (float)elapsed / duration;
|
||||
rgb m = { (int)(c1.r + (c2.r - c1.r) * factor), (int)(c1.g + (c2.g - c1.g) * factor),
|
||||
(int)(c1.b + (c2.b - c1.b) * factor) };
|
||||
fill(f, ab(m, b));
|
||||
rgb cur = c[s.ci % nc];
|
||||
rgb nxt = c[(s.ci + 1) % nc];
|
||||
int k = (elapsed * 255) / duration; // 0 = all current colour, 255 = all next colour
|
||||
fill(f, ab(mix(cur, nxt, k), b));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user