Repository navigation
add Touch Grid 2D effect (perimeter touch-chase + interior fire) - #6
Conversation
New 2D effect for the AMPWorks square grids (matrix 8x8, touch-box 5x5): - Outer ring (perimeter) is touch-reactive. Each touch spawns a colored dot that chases clockwise around the ring. Local touches (this device's MPR121) spawn bright dots; remote touches (other devices, via the sensor-sync bus) spawn dimmer dots. Chasers carry a short fading tail (length from c3). - Interior square runs a Fire2012-style fire (heat buffer + HeatColor ramp), rising toward the top row; spark rate from Intensity, cooling from c2. Generalizes to any W x H >= 3 matrix: perimeter = 2W+2H-4 cells, interior = (W-2)x(H-2). Guarded on SEGMENT.is2D(); no-op on 1D segments. Local input via UsermodMPR121 edge-detect, remote via UsermodSensorSync::popRemoteEvent, both behind #ifdef. Descriptor: "Touch Grid@Speed,Fire,Hz,Cool,Tail;;!;2". Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
The fire still runs at its baseline rate when silent (or with no AudioReactive usermod), but now reacts to sound: - Volume/bass (volumeSmth + fftResult[0]) raises the spark rate, so the flame gets livelier and taller as the music gets louder. - Beat onsets (samplePeak) punch the whole flame base with extra heat, giving a beat-matched flicker pulse that ripples up through the fire. Pulls audio via UsermodManager::getUMData(USERMOD_ID_AUDIOREACTIVE), falling back to simulateSound() so the sound-sim works. Descriptor flagged "2v" (2D + volume-reactive) so the UI groups it under audio effects. Perimeter chasers remain touch-driven. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Hardware feedback: the interior fire saturated to white (hiding the audio response), and the perimeter chase ran too fast. - Fire: rebuilt for short columns. Per-cell cooling is stronger and the rise is lossy (scale8 ~80%), so heat fades to red/black up the column instead of every cell pegging at max. Base sparks now SET toward a target (random 150..210) rather than qadd, removing the runaway that whitened the flame. - Audio: spark-rate boost softened; beats now SET the base toward a capped target (<=255) for a visible flash instead of dumping unbounded heat across the row. - Chasers: speed mapping lowered (0.04..0.44 ring/frame, was 0.15..1.0). Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
aphelps-claude-bot
left a comment
There was a problem hiding this comment.
Post-PR self-review — Touch Grid 2D effect
Reviewed the full diff plus the referenced helpers, the MPR121 / SensorSync / AudioReactive APIs, Segment::allocateData, and the SEGMENT field widths. Two genuine correctness/behavior bugs, both simple one-liners; the rest is clean. Effect-tuning items are left alone per owner sign-off.
Must-fix
1. tgRingXY off-by-one on the left edge — one perimeter cell never lit, corner drawn twice (all geometries incl. 5×5 and 8×8).
The left-edge branch computes:
else { x = 0; y = H - 1 - (r - top - right - bottom); }For the first left-edge index (r = top+right+bottom) this yields y = H-1, i.e. the bottom-left corner — which the bottom run already emitted. Verified by enumerating the ring for W×H ∈ {3×3, 5×5, 8×8, 4×6, 3×8}:
(0, H-1)(bottom-left corner) is emitted twice(0, 1)(the cell directly above the bottom-left corner) is never emitted → permanently dark
Not an out-of-bounds access (all indices stay in-range, so no crash), but a visible ring defect on every square: chasers "teleport" over the dark cell and double-brighten the corner. Fix is one character — the left run should walk the interior of the left edge, y = H-2 .. 1:
else { x = 0; y = H - 2 - (r - top - right - bottom); }With H-2, enumeration gives exact border coverage, in-bounds, zero duplicates, for all tested geometries.
2. Tail slider (custom3) is dead — tails never render.
SEGMENT.custom3 is a 5-bit field (0–31) (FX.h:366), but the code feeds it to map8(), which expects a full 0–255 input:
uint8_t tail = map8(SEGMENT.custom3, 0, 5);map8(v,0,5) = scale8(v,5) = (v*5)>>8, which is 0 for every v ≤ 31. So tail is always 0 and the tail-drawing loop (for t in 1..tail) never executes regardless of the slider. The descriptor default c3=120 is also silently truncated to 24 by the 5-bit field (and would still map to 0). Fix: scale the 5-bit value up before mapping, e.g. map8(SEGMENT.custom3 << 3, 0, 5), or compute directly tail = (SEGMENT.custom3 * 5 + 15) / 31;.
(Note: speed, intensity, custom1, custom2 are full 8-bit fields, so their map8 calls are correct — only custom3 has the reduced range.)
Verified clean (no action needed)
- Flexible-array-member allocation is correct.
sizeof(GridFireData)includes the struct up to and including trailing padding beforeheat[]; sinceheat[]isuint8_t(alignment 1) it begins exactly at that offset, sosizeof(GridFireData) + heatBytesneither double-counts nor misaligns. Thecall==0memset(d, 0, sizeof(GridFireData)+heatBytes)zeroes the whole buffer including heat, so no uninitialized state on first frame. - Interior heat index math is safe for W×H ≥ 3. Indices
y*iW+xstay withiniW*iH = heatBytes(5×5→3×3=9 bytes, 8×8→6×6=36 bytes, 3×3→1×1=1 byte), and the interior draw offsets by(1+x, 1+y), landing strictly inside the border. TheiW>0 && iH>0guard is redundant given theW<3||H<3early return but harmless. - Chaser pos/speed math cannot go out of bounds:
pos ∈ [0, perim), and every ring lookup in the draw loop is wrapped with((v % perim) + perim) % perim. A remoteev.channel ≥ nch(e.g. proximity electrode 12+) can seedpos == perimat spawn, but the wrap masks it — purely cosmetic, no OOB. Oldest-slot eviction when all 16 chasers are busy is correct. #ifdefguards compile in all combinations.MPR121::MAX_SENSORSand the MPR121/SensorSync symbols are referenced only inside#ifdef USERMOD_MPR121(SensorSync nested inside, behindUSERMOD_SENSOR_SYNC). The audio block and the rest of the effect use only WLED core symbols, so the effect still builds and runs (fire + audio, no touch) with both usermods off.- AudioReactive
u_dataaccess is correct: indices [0]=volumeSmth(float*), [2]=fftResult(uint8_t*), [3]=samplePeakmatchaudio_reactive.h:1138–1144.samplePeakis a 1-bytebool, so reading it asuint8_tis fine.fftResultnull-checked before[0].simulateSound(SEGMENT.soundSim)fallback matches core usage;2vdescriptor flag +si=0default is consistent.
Subjective / tuning (non-blocking, per owner)
Cooling/spark/rise constants, chase speed range (0.04–0.44), remote-dim brightness (90), and the 1200-frame chaser lifetime are visual-feel choices to refine later.
Reviewed by aphelps-claude-bot.
Two correctness bugs found in self-review of PR #6: - tgRingXY left edge started at y=H-1, double-drawing the bottom-left corner and leaving (0,1) permanently dark on every square. Corrected to H-2 so the left run covers y=1..H-2 exactly (verified dup-free + in-bounds for 3x3..8x8). - The Tail control read SEGMENT.custom3 (a 5-bit field, 0..31) through map8() (expects 0..255), so tail was always 0 and chaser tails never rendered. Use map(custom3, 0, 31, 0, 5); fix the descriptor default (c3=120 -> c3=24, since 120 wrapped to 24 in the 5-bit field anyway). Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Addressed both self-review findings in |
New 2D effect for the AMPWorks square LED grids (8×8 matrix, 5×5 touch-box).
clockwise around the ring. Local touches (this device's MPR121) → bright dots; remote
touches (other devices, via the sensor-sync bus) → dimmer dots. Short fading tail per chaser.
columns so it holds a black→red→orange→yellow gradient rather than saturating to white.
the fire still runs at baseline when silent. Descriptor flag
2v.Generalizes to any W×H ≥ 3 matrix. Guarded on
SEGMENT.is2D()(no-op on 1D segments). Localinput via
UsermodMPR121edge-detect, remote viaUsermodSensorSync::popRemoteEvent, both behind#ifdef. Registered inAMPWorks::setup().Test plan
pio run -e ampworksbuilds clean on current main (rebased onto main after the HSPI/setup PRs landed)..27/64-LED and 5×5.4/25-LED); Touch Grid renders, touch sync works across devices.Notes
Merging as-is per owner sign-off; further visual refinement (fire feel / chase speed / audio
strength) will come in a follow-up. Devices must be configured as 2D matrices for the effect to
render.
Co-Authored-By: Claude Opus 4.8 (1M context) [email protected]