Conversation
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.
on() drove the DAC to full scale, so every switch-on flashed at maximum brightness before the caller set the requested level. Remember the last level that was set and restore that instead.
hardware.json and config.json are written while controllers read them, and a partially written file leaves the instrument unbootable. Write to a temporary file in the same directory, fsync it and rename over the target, so a reader sees either the old file or the new one. Also fixes a typo that passed `forrce` instead of `force` when removing calibration.json, which made /api/reset throw if the file did not exist.
The calibration an operator performs did not survive a reboot, so it had to be redone on every start. Calibration is stored in calibration.json, which initConfigFiles never overwrites, rather than hardware.json, which a hardware version switch rewrites from defaults. The backend exposes calibration/save and calibration/read, and publishes the stored values on a retained status/calibration. White balance is applied without operator action: the gains are mirrored into hardware.json, which the camera already reads at startup, and published as a live settings command for a running camera. The hardware controllers are unchanged. They keep driving hardware over the MQTT API they already expose, and hold no calibration state of their own.
babo989
force-pushed
the
fix/575-persist-led-wb
branch
from
September 16, 2026 15:11
604e74a to
0b7f756
Compare
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.