Reject PA calibrations with no result or bad sensor data

bdpressure.py leaves the extruder at the last PA_CALIBRATE test value
(0.098) when it finds no result, and _PA_AFTER_CALIBRATE saved that as
the calibrated PA (lane1 after an AFC pause, lane5 after the sensor went
silent). A run is now rejected, with nothing cached or written to
Spoolman, when the PA is still at the end of the scan, the printer
paused during the test, or bd_pressure gave too few or too few different
readings. The previous valid PA (or fallback_pa) is applied instead.

bdpressure_check reports pa_points and pa_distinct from the bdpressure
module's last PA_CALIBRATE data for this.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
mangavalkandClaude Opus 5.5 committed 2026-10-12 21:10:06 +02:00
1 parent 82f9486160
commit 25891640b8
3 files changed
+60 -3

No files matched your search

+16 -1
View File
@@ -19,6 +19,11 @@
#
# Status (printer.bdpressure_check), updated by the commands above:
# available, running, peak, above_ms, longest_ms, delta
# pa_points, pa_distinct - readings the [bdpressure] module collected in
# its last PA_CALIBRATE, and how many of them differ (read
# from that module, not from the sensor). A sensor that
# stops answering gives few points; one that hangs repeats
# the same reading. LANE_CALIBRATE_PA rejects such runs.
REG_EXT = 54 # first byte of the extension
REG_CTRL = 56
@@ -31,6 +36,7 @@ class BDPressureCheck:
self.printer = config.get_printer()
self.sensor_name = 'bdpressure ' + config.get('sensor', 'bd_pa')
self.i2c = None
self.sensor = None
self.status = {'available': False, 'running': False, 'peak': 0,
'above_ms': 0, 'longest_ms': 0, 'delta': 0}
self.printer.register_event_handler('klippy:connect',
@@ -45,6 +51,7 @@ class BDPressureCheck:
def _handle_connect(self):
sensor = self.printer.lookup_object(self.sensor_name)
self.sensor = sensor
self.i2c = getattr(sensor, 'i2c', None)
def _read(self):
@@ -100,7 +107,15 @@ class BDPressureCheck:
self._respond(gcmd, "BDP_CHECK_QUERY")
def get_status(self, eventtime):
return dict(self.status)
status = dict(self.status)
# [val, res, lk, rk, Hk, Ha] per reading, see bdpressure.py
try:
data = list(getattr(self.sensor, 'PA_data', None) or [])
status['pa_points'] = len(data)
status['pa_distinct'] = len(set(tuple(d[1:]) for d in data))
except Exception:
status['pa_points'] = status['pa_distinct'] = -1
return status
def load_config(config):