Skip to content

fix(dither): name the enable threshold, so the test reads it rather than a copy (#4042) - #4294

Merged
zackees merged 1 commit into
masterfrom
fix/4042-name-the-dither-enable-threshold
Sep 10, 2026
Merged

zackees merged 1 commit into
masterfrom
fix/4042-name-the-dither-enable-threshold

Conversation

@zackees

@zackees zackees commented Sep 10, 2026 •

Copy link
Copy Markdown
Member

The case that was supposed to catch a change could not

tests/pixel_controller.cpp records the cadence gap #4156 R8 asked to have written down. The dither cycle length is derived:

MAX_LIKELY_UPDATE_RATE_HZ     400
MIN_ACCEPTABLE_DITHER_RATE_HZ  50
UPDATES_PER_FULL_DITHER_CYCLE  400 / 50 = 8

Eight frames is the number that makes a 400 Hz refresh complete a cycle at 50 Hz. But what enables dithering is a refresh of 100 — at which an eight-frame cycle completes at 12.5 Hz, a quarter of that floor and near the peak of human flicker sensitivity.

The case says it "fails if either number moves so that whoever moves it writes down why". It did not. show() and showColor() each carried a bare if (mNFPS < 100), and the case carried its own:

// The threshold `show()` actually applies, repeated here because it is a
// literal there rather than a named constant.
const int kDitherEnableFps = 100;

So changing the threshold moved the behaviour and failed nothing. That is the same defect #4279 fixed elsewhere: a test that reads a copy is not reading the thing it names.

What changed

FL_DITHER_ENABLE_MIN_REFRESH_HZ exists once, both call sites use it, and the case reads it.

Verified rather than assumed: setting the constant to 200 now fails three assertions, including the 12.5 Hz cadence pin. Before this change that mutation passed silently.

Behaviour is unchanged — the value is still 100. The gap is a decision and not a cleanup: raising it to MAX_LIKELY_UPDATE_RATE_HZ, the refresh that would actually reach the floor, would disable dithering for most sketches. What changes is that the arithmetic now lives at the definition rather than only in a doc and a test comment, and the constant cannot drift away from the case that prices it.

Placement

In FastLED.h rather than beside the cycle constants in pixel_controller.h, because those sit inside #if !defined(NO_DITHERING) || (NO_DITHERING != 1) while the setDither(0) calls this gates do not — putting it there would break a NO_DITHERING=1 build.

Renamed from FASTLED_- to FL_-prefixed after MacroPrefixChecker flagged it; the repo requires the prefix for new macros.

303/303 unit, 84/84 examples, bash lint clean.

Why this matters beyond tidiness

P8 (#4042) still owes a flicker budget, and the doc's own note is that it is "worth having before any pipeline dither is built, because that one modulates harder". This does not set the budget. It makes the number that the budget will have to move a named thing with the consequence attached, instead of a literal in two places that nothing was watching.

🤖 Generated with Claude Code

https://claude.ai/code/session_01MLhWkMfzLjrnLTDMBE6Fj9

Summary by CodeRabbit

  • New Features

    • Added the public FL_DITHER_ENABLE_MIN_REFRESH_HZ setting to identify the minimum refresh rate at which dithering remains enabled.
    • Added documentation explaining the dithering threshold and its relationship to full dithering cycles.
  • Bug Fixes

    • Ensured dithering behavior consistently uses the documented refresh-rate threshold.
  • Tests

    • Updated dither cadence coverage to validate against the shipped threshold setting.

…han a copy

`tests/pixel_controller.cpp` records the cadence gap #4156 R8 asked to have
written down: the dither cycle length is derived as
`MAX_LIKELY_UPDATE_RATE_HZ / MIN_ACCEPTABLE_DITHER_RATE_HZ` = 400 / 50 = 8,
but what enables dithering is a refresh of 100, at which an eight-frame
cycle completes at 12.5 Hz -- a quarter of that floor, near the peak of
human flicker sensitivity.

The case said it "fails if either number moves so that whoever moves it
writes down why". It did not. `show()` and `showColor()` each carried a bare
`if (mNFPS < 100)`, and the case carried its own `const int
kDitherEnableFps = 100` because there was no constant to read -- so changing
the threshold moved the behaviour and failed nothing. Same defect as #4279:
a test that reads a copy is not reading the thing it names.

`FL_DITHER_ENABLE_MIN_REFRESH_HZ` now exists once, both call sites use it,
and the case reads it. Verified rather than assumed: setting it to 200 fails
three assertions, including the 12.5 Hz cadence pin. Before this it passed.

Behaviour is unchanged -- the value is still 100. The gap is a decision, not
a cleanup: raising it to `MAX_LIKELY_UPDATE_RATE_HZ`, which is the refresh
that would actually reach the floor, would disable dithering for most
sketches. What changes is that the arithmetic now lives at the definition
rather than only in a doc and a test comment, and the constant cannot drift
away from the case that prices it.

In `FastLED.h` rather than beside the cycle constants because those sit
inside `#if !defined(NO_DITHERING)`, while the `setDither(0)` calls this
gates do not.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01MLhWkMfzLjrnLTDMBE6Fj9
@coderabbitai

coderabbitai Bot commented Sep 10, 2026 •

Copy link
Copy Markdown

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: acc81d2c-c776-4cf5-b84f-1759a20eadd0

📥 Commits

Reviewing files that changed from the base of the PR and between 7bb824b and e7114af.

📒 Files selected for processing (3)
  • src/FastLED.cpp.hpp
  • src/FastLED.h
  • tests/pixel_controller.cpp

Included review availability: Your plan provides up to 8 included reviews per hour; 1 remains after this review.


📝 Walkthrough

Walkthrough

The PR adds FL_DITHER_ENABLE_MIN_REFRESH_HZ with value 100. The show() and showColor() paths use it to disable dithering below the threshold. The pixel controller test also uses and validates the macro.

Changes

Dither threshold

Layer / File(s) Summary
Define and apply the dither threshold
src/FastLED.h, src/FastLED.cpp.hpp, tests/pixel_controller.cpp
Adds the documented FL_DITHER_ENABLE_MIN_REFRESH_HZ macro. Both display paths use the macro instead of a literal. The test references the macro and asserts its value is 100.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Merge Risk: ⚪ Minimal · up to e7114

The change centralizes the existing 100 Hz dithering threshold for both display paths and its cadence test without changing behavior. It is mergeable with no current user-impacting risk identified.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 3 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: naming the dither enable threshold and updating the test to use the shared constant instead of a duplicate value.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/4042-name-the-dither-enable-threshold

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@zackees
zackees merged commit 6004920 into master Sep 10, 2026
27 checks passed
@fastled-project-sync fastled-project-sync Bot moved this from Triage to Done in FastLED Tracker Sep 10, 2026
@zackees
zackees deleted the fix/4042-name-the-dither-enable-threshold branch November 5, 2026 05:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant