Repository navigation
fix(dither): name the enable threshold, so the test reads it rather than a copy (#4042) - #4294
Conversation
…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
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (3)
Included review availability: Your plan provides up to 8 included reviews per hour; 1 remains after this review. 📝 WalkthroughWalkthroughThe PR adds ChangesDither threshold
Estimated code review effort: 1 (Trivial) | ~5 minutes Merge Risk: ⚪ Minimal · up to 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)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
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. Comment |
The case that was supposed to catch a change could not
tests/pixel_controller.cpprecords the cadence gap #4156 R8 asked to have written down. The dither cycle length is derived: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()andshowColor()each carried a bareif (mNFPS < 100), and the case carried its own: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_HZexists 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.hrather than beside the cycle constants inpixel_controller.h, because those sit inside#if !defined(NO_DITHERING) || (NO_DITHERING != 1)while thesetDither(0)calls this gates do not — putting it there would break aNO_DITHERING=1build.Renamed from
FASTLED_- toFL_-prefixed afterMacroPrefixCheckerflagged it; the repo requires the prefix for new macros.303/303 unit, 84/84 examples,
bash lintclean.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
FL_DITHER_ENABLE_MIN_REFRESH_HZsetting to identify the minimum refresh rate at which dithering remains enabled.Bug Fixes
Tests