filament_switch_sensor: add SET_FILAMENT_SENSOR gcode

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
Arksine 2019-07-03 19:12:44 -04:00 committed by KevinOConnor
parent 856b22b387
commit d4d8bf795b
2 changed files with 16 additions and 2 deletions

View File

@ -442,6 +442,9 @@ section is enabled.
- `QUERY_FILAMENT_SENSOR SENSOR=<sensor_name>`: 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=<sensor_name> 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

View File

@ -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)