extruder: Add an ACTIVATE_EXTRUDER command

Add support for an extended g-code command to change the currently
active extruder.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2019-11-24 19:43:50 -05:00
parent ab2d302b7e
commit c06618193d
3 changed files with 22 additions and 0 deletions

View File

@ -153,6 +153,9 @@ The following standard commands are supported:
- `SET_HEATER_TEMPERATURE HEATER=<heater_name> [TARGET=<target_temperature>]`:
Sets the target temperature for a heater. If a target temperature is
not supplied, the target is 0.
- `ACTIVATE_EXTRUDER EXTRUDER=<config_name>`: In a printer with
multiple extruders this command is used to change the active
extruder.
- `SET_PRESSURE_ADVANCE [EXTRUDER=<config_name>] [ADVANCE=<pressure_advance>]
[SMOOTH_TIME=<pressure_advance_smooth_time>]`: Set pressure advance
parameters. If EXTRUDER is not specified, it defaults to the active

View File

@ -17,6 +17,8 @@ class GCodeParser:
printer.register_event_handler("klippy:shutdown", self._handle_shutdown)
printer.register_event_handler("klippy:disconnect",
self._handle_disconnect)
printer.register_event_handler("extruder:activate_extruder",
self._handle_activate_extruder)
# Input handling
self.reactor = printer.get_reactor()
self.is_processing_data = False
@ -175,6 +177,10 @@ class GCodeParser:
self.fd_handle = self.reactor.register_fd(self.fd,
self._process_data)
self._respond_state("Ready")
def _handle_activate_extruder(self):
self.reset_last_position()
self.extrude_factor = 1.
self.base_position[3] = self.last_position[3]
def reset_last_position(self):
self.last_position = self.position_with_transform()
def _dump_debug(self):

View File

@ -73,6 +73,9 @@ class PrinterExtruder:
gcode.register_mux_command("SET_PRESSURE_ADVANCE", "EXTRUDER",
self.name, self.cmd_SET_PRESSURE_ADVANCE,
desc=self.cmd_SET_PRESSURE_ADVANCE_help)
gcode.register_mux_command("ACTIVATE_EXTRUDER", "EXTRUDER",
self.name, self.cmd_ACTIVATE_EXTRUDER,
desc=self.cmd_ACTIVATE_EXTRUDER_help)
def update_move_time(self, flush_time):
self.trapq_free_moves(self.trapq, flush_time)
def _set_pressure_advance(self, pressure_advance, smooth_time):
@ -168,6 +171,16 @@ class PrinterExtruder:
pressure_advance, smooth_time))
self.printer.set_rollover_info(self.name, "%s: %s" % (self.name, msg))
gcode.respond_info(msg, log=False)
cmd_ACTIVATE_EXTRUDER_help = "Change the active extruder"
def cmd_ACTIVATE_EXTRUDER(self, params):
gcode = self.printer.lookup_object('gcode')
toolhead = self.printer.lookup_object('toolhead')
if toolhead.get_extruder() is self:
gcode.respond_info("Extruder %s already active" % (self.name))
return
gcode.respond_info("Activating extruder %s" % (self.name))
toolhead.set_extruder(self, self.extrude_pos)
self.printer.send_event("extruder:activate_extruder")
# Dummy extruder class used when a printer has no extruder at all
class DummyExtruder: