mirror of
https://github.com/maziggy/bambuddy.git
synced 2026-10-22 03:49:18 +02:00
Fix SpoolBuddy scale tare & calibration not being applied
The tare and calibrate buttons on the Settings page queued commands
but never executed them due to five broken links:
1. Daemon received tare command but never called scale.tare()
2. No endpoint to persist tare offset back to backend DB
3. Heartbeat never called scale.update_calibration()
4. Heartbeat response with stale values overwrote new tare to zero
5. set-factor used DB tare_offset (stale/zero), producing wrong
calibration factor — empty scale showed ~5000g
Fixed daemon to execute tare, persist result, and propagate
calibration. Calibration step now captures raw ADC at tare time
and sends it with step 2, making factor computation self-contained.
Replaced calibration weight input with compact touch numpad for
the RPi kiosk's 1024x600 touchscreen (no physical keyboard).
This commit is contained in:
@@ -342,11 +342,14 @@ async def set_calibration_factor(
|
||||
if not device:
|
||||
raise HTTPException(status_code=404, detail="Device not registered")
|
||||
|
||||
raw_delta = req.raw_adc - device.tare_offset
|
||||
tare = req.tare_raw_adc if req.tare_raw_adc is not None else device.tare_offset
|
||||
raw_delta = req.raw_adc - tare
|
||||
if raw_delta == 0:
|
||||
raise HTTPException(status_code=400, detail="Raw ADC value equals tare offset — place weight on scale")
|
||||
|
||||
device.calibration_factor = req.known_weight_grams / raw_delta
|
||||
if req.tare_raw_adc is not None:
|
||||
device.tare_offset = tare
|
||||
await db.commit()
|
||||
|
||||
logger.info(
|
||||
@@ -355,7 +358,7 @@ async def set_calibration_factor(
|
||||
device.calibration_factor,
|
||||
req.known_weight_grams,
|
||||
req.raw_adc,
|
||||
device.tare_offset,
|
||||
tare,
|
||||
)
|
||||
return CalibrationResponse(
|
||||
tare_offset=device.tare_offset,
|
||||
|
||||
Reference in New Issue
Block a user