Skip to content

Commit 32bc474

Browse files
committed
spots effect bugfix, take 2
next try: make sure that the strip is filled, and all gaps are equal
1 parent 7f88976 commit 32bc474

1 file changed

Lines changed: 6 additions & 11 deletions

File tree

wled00/FX.cpp

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3015,20 +3015,15 @@ uint16_t spots_base(uint16_t threshold)
30153015
if (SEGLEN <= 1) return mode_oops();
30163016
if (!SEGMENT.check2) SEGMENT.fill(SEGCOLOR(1));
30173017

3018-
// constants for fixed point scaling
3019-
constexpr uint8_t ZONELEN_FP_SHIFT = 3;
3020-
constexpr uint32_t ZONELEN_FP_SCALE = 1U << ZONELEN_FP_SHIFT;
3021-
3022-
unsigned maxZones = max(1, SEGLEN >> 2); // prevents "0 zones"
3023-
unsigned zones = 1U + ((uint32_t(SEGMENT.intensity) * maxZones) >> 8);
3024-
unsigned zoneLen = uint32_t(SEGLEN) / zones;
3025-
unsigned zoneLen8 = (uint32_t(SEGLEN) * ZONELEN_FP_SCALE) / zones; // zoneLength * 8 (fixed‑point) -> avoids gaps at right/left sides
3026-
unsigned offset = (uint32_t(SEGLEN) - ((zones * zoneLen8) >> ZONELEN_FP_SHIFT)) >> 1;
3018+
unsigned maxZones = max(1, SEGLEN / 4); // prevents "0 zones"
3019+
int zones = 1U + ((uint32_t(SEGMENT.intensity) * maxZones + 127) >> 8); // with rounding
3020+
unsigned zoneLen = (uint32_t(SEGLEN) + zones-1) / zones; // round up (ceil)
3021+
int offset = ((int)SEGLEN - (zones * zoneLen)) / 2; // center the zones on the segment (can not use bit shift on negative number)
30273022

30283023
for (unsigned z = 0; z < zones; z++)
30293024
{
3030-
unsigned pos = offset + ((z * zoneLen8) >> ZONELEN_FP_SHIFT);
3031-
for (unsigned i = 0; i < zoneLen; i++)
3025+
int pos = offset + (z * zoneLen);
3026+
for (int i = 0; i < zoneLen; i++)
30323027
{
30333028
unsigned wave = triwave16((i * 0xFFFF) / zoneLen);
30343029
if (wave > threshold) {

0 commit comments

Comments
 (0)