filament_switch_sensor: add SET_FILAMENT_SENSOR gcode
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
parent
856b22b387
commit
d4d8bf795b
|
@ -442,6 +442,9 @@ section is enabled.
|
||||||
- `QUERY_FILAMENT_SENSOR SENSOR=<sensor_name>`: Queries the current status of
|
- `QUERY_FILAMENT_SENSOR SENSOR=<sensor_name>`: Queries the current status of
|
||||||
the filament sensor. The data displayed on the terminal will depend on the
|
the filament sensor. The data displayed on the terminal will depend on the
|
||||||
sensor type defined in the confguration.
|
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
|
## Firmware Retraction
|
||||||
|
|
||||||
|
|
|
@ -75,6 +75,10 @@ class BaseSensor(object):
|
||||||
def cmd_QUERY_FILAMENT_SENSOR(self, params):
|
def cmd_QUERY_FILAMENT_SENSOR(self, params):
|
||||||
raise NotImplementedError(
|
raise NotImplementedError(
|
||||||
"Sensor must implement cmd_QUERY_FILAMENT_SENSOR")
|
"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):
|
class SwitchSensor(BaseSensor):
|
||||||
def __init__(self, config):
|
def __init__(self, config):
|
||||||
|
@ -85,12 +89,17 @@ class SwitchSensor(BaseSensor):
|
||||||
self.buttons.register_buttons([switch_pin], self._button_handler)
|
self.buttons.register_buttons([switch_pin], self._button_handler)
|
||||||
self.event_delay = config.getfloat('event_delay', 3., above=0.)
|
self.event_delay = config.getfloat('event_delay', 3., above=0.)
|
||||||
self.start_time = self.reactor.NEVER
|
self.start_time = self.reactor.NEVER
|
||||||
|
self.sensor_enabled = True
|
||||||
self.last_button_state = False
|
self.last_button_state = False
|
||||||
self.last_cb_event_time = 0.
|
self.last_cb_event_time = 0.
|
||||||
self.gcode.register_mux_command(
|
self.gcode.register_mux_command(
|
||||||
"QUERY_FILAMENT_SENSOR", "SENSOR", self.name,
|
"QUERY_FILAMENT_SENSOR", "SENSOR", self.name,
|
||||||
self.cmd_QUERY_FILAMENT_SENSOR,
|
self.cmd_QUERY_FILAMENT_SENSOR,
|
||||||
desc=self.cmd_QUERY_FILAMENT_SENSOR_help)
|
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)
|
self.printer.register_event_handler("klippy:ready", self._handle_ready)
|
||||||
def _handle_ready(self):
|
def _handle_ready(self):
|
||||||
self.start_time = self.reactor.monotonic() + 2.
|
self.start_time = self.reactor.monotonic() + 2.
|
||||||
|
@ -100,14 +109,14 @@ class SwitchSensor(BaseSensor):
|
||||||
return
|
return
|
||||||
if state:
|
if state:
|
||||||
# button pushed, check if insert callback should happen
|
# 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):
|
(eventtime - self.last_cb_event_time) > self.event_delay):
|
||||||
self.last_cb_event_time = eventtime
|
self.last_cb_event_time = eventtime
|
||||||
logging.info(
|
logging.info(
|
||||||
"switch_sensor: insert event detected, Time %.2f",
|
"switch_sensor: insert event detected, Time %.2f",
|
||||||
eventtime)
|
eventtime)
|
||||||
self.reactor.register_callback(self._insert_event_handler)
|
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):
|
(eventtime - self.last_cb_event_time) > self.event_delay):
|
||||||
# Filament runout detected
|
# Filament runout detected
|
||||||
self.last_cb_event_time = eventtime
|
self.last_cb_event_time = eventtime
|
||||||
|
@ -121,6 +130,8 @@ class SwitchSensor(BaseSensor):
|
||||||
else:
|
else:
|
||||||
msg = "Switch Sensor: filament not detected"
|
msg = "Switch Sensor: filament not detected"
|
||||||
self.gcode.respond_info(msg)
|
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):
|
def load_config_prefix(config):
|
||||||
return SwitchSensor(config)
|
return SwitchSensor(config)
|
||||||
|
|
Loading…
Reference in New Issue