PA calibration reads Spoolman first; guard resets a sensor left in PA mode

- LANE_CALIBRATE_PA: when a calibration will run, assign the lane's spool
  again (SET_SPOOL_ID) so AFC reads the Spoolman temperature now; AFC
  only reads it at spool assignment and Klipper start (TPU calibrated at
  210C after Spoolman was set to 230C). The calibration moved to
  _LANE_CALIBRATE_PA_RUN, rendered after the refresh.
- bdp_guard: an emergency stop during PA_CALIBRATE leaves the sensor in
  PA mode (FIRMWARE_RESTART does not reset it). When arming, read the
  mode register and switch the sensor back to probe mode with a fresh
  baseline before watching it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
mangavalkandClaude Opus 5.5 committed 2026-10-19 16:04:40 +02:00
1 parent d49e65c0bb
commit 93ae8795b8
3 files changed
+54 -3

No files matched your search

+29
View File
@@ -40,6 +40,9 @@
import logging
REG_MODE = 48 # status_clk: 7 = PA mode, 2 = probe (endstop) mode
REG_RESET_PROBE = 52 # set_normal: write 1 = take the current reading as zero
MODE_PA = 7
REG_EXT = 54 # extension marker 0xBD + version
REG_DELTA = 64 # chk_delta, int16 little-endian
EXT_MAGIC = 0xBD
@@ -134,6 +137,31 @@ class BDPGuard:
return False
return len(data) == 2 and data[0] == EXT_MAGIC and data[1] >= 1
def _ensure_probe_mode(self, gcmd):
# An emergency stop during PA_CALIBRATE leaves the sensor in PA mode
# (FIRMWARE_RESTART does not reset it); bdpressure.py only switches
# it back at the next homing move, after the guard is armed. In PA
# mode the delta means nothing and could trip the guard. Register 48
# is the mode: 7 = PA, 2 = probe.
if getattr(self.sensor, 'last_state', 0):
return # a calibration runs, leave the sensor alone
try:
mode = bytearray(self.i2c.i2c_read([REG_MODE], 1)['response'])
if len(mode) != 1 or mode[0] != MODE_PA:
return
self.sensor.set_probe_mode()
# new samples at the probe sample rate, then a fresh baseline
self.reactor.pause(self.reactor.monotonic() + 0.5)
self.i2c.i2c_write([REG_RESET_PROBE, 1])
self.reactor.pause(self.reactor.monotonic() + 0.3)
except Exception:
logging.exception("bdp_guard: switching the sensor to probe mode failed")
return
msg = ("BDP_GUARD: bd_pressure was still in PA mode (stopped "
"calibration?), switched to probe mode")
logging.info(msg)
gcmd.respond_info(msg)
def _stop_timer(self):
if self.timer is not None:
self.reactor.unregister_timer(self.timer)
@@ -200,6 +228,7 @@ class BDPGuard:
gcmd.respond_info("BDP_GUARD_ARM: bd_pressure load-check "
"extension not found, guard not armed")
return
self._ensure_probe_mode(gcmd)
self.phase_mode = mode
self._reset_phase(phase)
self.armed_until = self.reactor.monotonic() + self.timeout