From 793013916ae702b715029f8f41fc631adea72a6d Mon Sep 17 00:00:00 2001 From: Zeanon Date: Sat, 14 Oct 2023 22:11:09 +0200 Subject: [PATCH] . --- docs/Status_Reference.md | 2 ++ klippy/extras/filament_motion_sensor.py | 5 +++++ klippy/extras/filament_switch_sensor.py | 17 +++++++++++------ 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/docs/Status_Reference.md b/docs/Status_Reference.md index d47b5987b505..f75524eb413e 100644 --- a/docs/Status_Reference.md +++ b/docs/Status_Reference.md @@ -150,6 +150,7 @@ objects: - `enabled`: Returns True if the switch sensor is currently enabled. - `filament_detected`: Returns True if the sensor is in a triggered state. +- `runout_distance`: Returns the runout_distance ## filament_motion_sensor @@ -159,6 +160,7 @@ objects: - `enabled`: Returns True if the motion sensor is currently enabled. - `filament_detected`: Returns True if the sensor is in a triggered state. +- `detection_length`: Returns the detection_length ## firmware_retraction diff --git a/klippy/extras/filament_motion_sensor.py b/klippy/extras/filament_motion_sensor.py index 7928c767175c..0a83682e6923 100644 --- a/klippy/extras/filament_motion_sensor.py +++ b/klippy/extras/filament_motion_sensor.py @@ -78,6 +78,11 @@ def get_sensor_status(self): % (self.runout_helper.name, 'enabled' if self.runout_helper.sensor_enabled > 0 else 'disabled', self.detection_length)) + def sensor_get_status(self, eventtime): + return { + "filament_detected": bool(self.runout_helper.filament_present), + "enabled": bool(self.runout_helper.sensor_enabled), + "detection_length": float(self.detection_length)} def set_filament_sensor(self, gcmd): enable = gcmd.get_int('ENABLE', None, minval=0, maxval=1) reset = gcmd.get_int('RESET', None, minval=0, maxval=1) diff --git a/klippy/extras/filament_switch_sensor.py b/klippy/extras/filament_switch_sensor.py index 8094f48e3e31..37bcf98f3d2f 100644 --- a/klippy/extras/filament_switch_sensor.py +++ b/klippy/extras/filament_switch_sensor.py @@ -26,9 +26,6 @@ def __init__(self, config, defined_sensor, runout_distance=0): if self.runout_pause or config.get('runout_gcode', None) is not None: self.runout_gcode = gcode_macro.load_template( config, 'runout_gcode', '') - if config.get('immediate_runout_gcode', None) is not None: - self.immediate_runout_gcode = gcode_macro.load_template( - config, 'immediate_runout_gcode', '') if config.get('insert_gcode', None) is not None: self.insert_gcode = gcode_macro.load_template( config, 'insert_gcode') @@ -130,9 +127,7 @@ def note_filament_present(self, is_filament_present, force=False): (self.name, eventtime)) self.reactor.register_callback(self._runout_event_handler) def get_status(self, eventtime): - return { - "filament_detected": bool(self.filament_present), - "enabled": bool(self.sensor_enabled)} + return self.defined_sensor.sensor_get_status(eventtime) cmd_QUERY_FILAMENT_SENSOR_help = "Query the status of the Filament Sensor" def cmd_QUERY_FILAMENT_SENSOR(self, gcmd): msg = "Filament Sensor %s: filament %s" %\ @@ -147,6 +142,7 @@ def cmd_SET_FILAMENT_SENSOR(self, gcmd): class SwitchSensor: def __init__(self, config): self.printer = config.get_printer() + gcode_macro = self.printer.load_object(config, 'gcode_macro') buttons = self.printer.load_object(config, 'buttons') switch_pin = config.get('switch_pin') runout_distance = config.getfloat('runout_distance', 0., minval=0.) @@ -154,6 +150,10 @@ def __init__(self, config): self.reactor = self.printer.get_reactor() self.estimated_print_time = None self.runout_helper = RunoutHelper(config, self, runout_distance) + if config.get('immediate_runout_gcode', None) is not None: + self.runout_helper.immediate_runout_gcode = ( + gcode_macro.load_template(config, 'immediate_runout_gcode', '') + ) self.get_status = self.runout_helper.get_status self.printer.register_event_handler('klippy:ready', self._handle_ready) @@ -174,6 +174,11 @@ def get_sensor_status(self): % (self.runout_helper.name, 'enabled' if self.runout_helper.sensor_enabled else 'disabled', self.runout_helper.runout_distance)) + def sensor_get_status(self, eventtime): + return { + "filament_detected": bool(self.runout_helper.filament_present), + "enabled": bool(self.runout_helper.sensor_enabled), + "runout_distance": float(self.runout_helper.runout_distance)} def set_filament_sensor(self, gcmd): enable = gcmd.get_int('ENABLE', None, minval=0, maxval=1) reset = gcmd.get_int('RESET', None, minval=0, maxval=1)