feat(spoolbuddy): scale auto-calibration and manual recalibrate button - #3071
Closed
khaosdoctor wants to merge 2 commits into
Closed
feat(spoolbuddy): scale auto-calibration and manual recalibrate button#3071khaosdoctor wants to merge 2 commits into
khaosdoctor wants to merge 2 commits into
Conversation
…drift Auto-zero uses NAU7802 system offset calibration (mode=2) when scale is empty and stable for 10s. Periodic internal cal (mode=0) every 6h.
New "Recalibrate Scale" button in the scale tab runs calibrate_zero + recalibrate_afe directly from the UI, reusing the existing diagnostic queue/poll infrastructure.
There was a problem hiding this comment.
🟡 Changes recommended
The new recalibration diagnostic currently relies on private ScaleReader internals and reports potentially misleading success/messaging, and there are unprofessional/unclear comment markers that should be cleaned up.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
Adds scale drift-mitigation and user-triggered calibration flows for SpoolBuddy by introducing auto-zero detection, periodic NAU7802 AFE recalibration, and a new “recalibrate” diagnostic surfaced in the UI and API.
Changes:
- Implemented auto-zero detection and zero-point calibration logic in the scale reader, plus periodic AFE recalibration.
- Added a new
recalibratediagnostic command handler in the daemon and wired it through backend validation + frontend client/modal UI. - Added test coverage for auto-zero detection,
calibrate_zero(), and AFE recalibration behavior.
File summaries
| File | Description |
|---|---|
| spoolbuddy/daemon/scale_reader.py | Adds auto-zero state machine, calibrate_zero(), and periodic recalibrate_afe() support. |
| spoolbuddy/daemon/main.py | Runs auto-zero + periodic recal in the scale poll loop and adds run_recalibrate_diag handler. |
| spoolbuddy/tests/test_scale_reader.py | New unit tests covering auto-zero detection, zero calibration, and AFE recalibration. |
| backend/app/api/routes/spoolbuddy.py | Allows recalibrate as a diagnostic type for queue/result endpoints. |
| frontend/src/api/client.ts | Extends diagnostics type unions to include recalibrate. |
| frontend/src/components/SpoolBuddySettings.tsx | Adds “Recalibrate Scale” button and opens diagnostic modal. |
| frontend/src/components/spoolbuddy/DiagnosticModal.tsx | Adds recalibrate type and title handling. |
Review details
Suppressed comments (2)
spoolbuddy/daemon/main.py:354
calibrate_zero()returns a tare offset even when it falls back to software adjustment after a hardware calibration failure, so reporting "System offset cal: OK" here can be misleading. Also, theelsebranch (skipped (not pending)) is effectively unreachable because_auto_zero_pendingis set immediately before callingcalibrate_zero(). Consider using neutral wording that reflects the fallback behavior and removing the dead branch.
lines.append(f" System offset cal: OK (new tare={new_tare})")
else:
lines.append(" System offset cal: skipped (not pending)")
spoolbuddy/daemon/main.py:372
- The diagnostic
successflag only reflects the internal offset calibration result (afe_ok) and ignores the outcome of the zero calibration step, so the UI may show overall success even if step [2] fails/throws. Track a separatezero_ok(even if justnew_tare is not None) and combine them for the final success/exit_code.
success = afe_ok
- Files reviewed: 7/7 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+346
to
+347
| scale._auto_zero_pending = True | ||
| scale._pending_zero_avg = 0.0 |
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.
Description
Adds automatic calibration for the NAU7802 + load cell scale to correct thermal and mechanical drift, plus a manual recalibration button in the SpoolBuddy settings UI.
Related Issue
N/A
Documentation
Pick one:
Type of Change
Changes Made
Files changed
spoolbuddy/daemon/scale_reader.py— auto-zero detection loop,calibrate_zero(),recalibrate_afe()methodsspoolbuddy/daemon/main.py—run_recalibrate_diagcommand handlerspoolbuddy/tests/test_scale_reader.py— new test file (176 lines)backend/app/api/routes/spoolbuddy.py— added "recalibrate" to diagnostic validationfrontend/src/api/client.ts— extended diagnostic type unionsfrontend/src/components/SpoolBuddySettings.tsx— recalibrate button + modalfrontend/src/components/spoolbuddy/DiagnosticModal.tsx— recalibrate type + titleTesting
Checklist
Additional Notes
All 90 daemon tests pass. The auto-zero only triggers when the scale is genuinely empty and stable, with a 60s cooldown to avoid rapid re-calibration loops. The periodic internal recal (mode=0) is safe with a spool on the scale since it only recalibrates the ADC's internal analog front-end.