diff --git a/docs/G-Codes.md b/docs/G-Codes.md index 4b4d7a8b..f38c1a28 100644 --- a/docs/G-Codes.md +++ b/docs/G-Codes.md @@ -442,6 +442,9 @@ section is enabled. - `QUERY_FILAMENT_SENSOR SENSOR=`: Queries the current status of the filament sensor. The data displayed on the terminal will depend on the sensor type defined in the confguration. + - `SET_FILAMENT_SENSOR SENSOR= ENABLE=[0|1]`: Sets the + filament sensor on/off. If ENABLE is set to 0, the filament sensor will + be disabled, if set to 1 it is enabled. ## Firmware Retraction diff --git a/klippy/extras/filament_switch_sensor.py b/klippy/extras/filament_switch_sensor.py index 20df5959..a5b189df 100644 --- a/klippy/extras/filament_switch_sensor.py +++ b/klippy/extras/filament_switch_sensor.py @@ -75,6 +75,10 @@ class BaseSensor(object): def cmd_QUERY_FILAMENT_SENSOR(self, params): raise NotImplementedError( "Sensor must implement cmd_QUERY_FILAMENT_SENSOR") + cmd_SET_FILAMENT_SENSOR_help = "Sets the filament sensor on/off" + def cmd_SET_FILAMENT_SENSOR(self, params): + raise NotImplementedError( + "Sensor must implement cmd_SET_FILAMENT_SENSOR") class SwitchSensor(BaseSensor): def __init__(self, config): @@ -85,12 +89,17 @@ class SwitchSensor(BaseSensor): self.buttons.register_buttons([switch_pin], self._button_handler) self.event_delay = config.getfloat('event_delay', 3., above=0.) self.start_time = self.reactor.NEVER + self.sensor_enabled = True self.last_button_state = False self.last_cb_event_time = 0. self.gcode.register_mux_command( "QUERY_FILAMENT_SENSOR", "SENSOR", self.name, self.cmd_QUERY_FILAMENT_SENSOR, desc=self.cmd_QUERY_FILAMENT_SENSOR_help) + self.gcode.register_mux_command( + "SET_FILAMENT_SENSOR", "SENSOR", self.name, + self.cmd_SET_FILAMENT_SENSOR, + desc=self.cmd_SET_FILAMENT_SENSOR_help) self.printer.register_event_handler("klippy:ready", self._handle_ready) def _handle_ready(self): self.start_time = self.reactor.monotonic() + 2. @@ -100,14 +109,14 @@ class SwitchSensor(BaseSensor): return if state: # button pushed, check if insert callback should happen - if (self.insert_enabled and + if (self.insert_enabled and self.sensor_enabled and (eventtime - self.last_cb_event_time) > self.event_delay): self.last_cb_event_time = eventtime logging.info( "switch_sensor: insert event detected, Time %.2f", eventtime) self.reactor.register_callback(self._insert_event_handler) - elif (self.runout_enabled and + elif (self.runout_enabled and self.sensor_enabled and (eventtime - self.last_cb_event_time) > self.event_delay): # Filament runout detected self.last_cb_event_time = eventtime @@ -121,6 +130,8 @@ class SwitchSensor(BaseSensor): else: msg = "Switch Sensor: filament not detected" self.gcode.respond_info(msg) + def cmd_SET_FILAMENT_SENSOR(self, params): + self.sensor_enabled = self.gcode.get_int("ENABLE", params, 1) def load_config_prefix(config): return SwitchSensor(config)