fix(controller): persist LED intensity and white balance calibration - #1013
Open
babo989 wants to merge 2 commits into
Open
fix(controller): persist LED intensity and white balance calibration#1013babo989 wants to merge 2 commits into
babo989 wants to merge 2 commits into
Conversation
LED intensity had no home in any config file, so it lived only in the DAC register: init() zeroed it on every start and on() jumped to DAC_MAX. White balance was written to Node-RED context while the camera reads red_gain and blue_gain from hardware.json at startup, so the two stores never agreed. Both now persist to hardware.json on an explicit save and are restored at startup. hardware.json writes are made atomic, since this adds two more writer processes to a file that bricks the instrument if half-written. Fixes fairscope/PlanktoScope3#575
sonnyp
reviewed
Aug 12, 2026
sonnyp
left a comment
Collaborator
There was a problem hiding this comment.
The hardware controllers (light, bubbler, etc) are designed only to control hardware.
They should not be involved in "business logic". Ideally there are no changes to controller/light to solve this issue.
I see several things to take into consideration:
- We want calibration to work without a browser
- We want calibration to happen automatically
- The code duplication problem you described
- The quality of the current implementation
- We have to consider https://github.com/fairscope/PlanktoScope3/issues/327 for later
I think we should discuss this but my thoughts for now:
Calibration should be implemented in the backend, not in the browser. Probably as a new MQTT service.
Dashboard would automatically run calibration before starting an acquisition. Possibly when loading preview too. TBD
Since calibration would happen automatically, I'm not even sure we have anything to save at all.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
We need to decide on a permanent fix, issue is now solved but fragile.
Consolidate the three duplicated auto-calibration implementations in the dashboard
The LED/white-balance auto-calibration sequence (
runInit→runSaturationLoop→runLightnessLoop) exists as three independent copies, all on enabled tabs:db1ef284071e60a179bccc0355eb5d8797634d7d17fefdebThey have already drifted: the Acquisition copy uses
cal_status/cal_stepwhere the others usestatus/step. There are also two older wizard tabs, "Calibration - Lightness" (c9a6d6f19ff18dda) and "Calibration - Saturation Level" (10c29a65226c0da4), which are enabled but unused.This duplication is the structural reason calibration bugs keep reopening. #473 reopened four times because each fix landed on one node while its siblings kept the old behaviour, and it was closed only once the same change was made in every copy. #575 had the same shape — persisting on success had to be written three times, and any future change to calibration behaviour will too. Each round the fix looks complete, then reappears as "it works sometimes, depending on which screen you calibrate from."
Two things worth doing, in order:
Worth checking for other duplicated logic in the flows at the same time; these two issues suggest it may not be limited to calibration.