Skip to content

Commit

Permalink
Allow switching the extruder_stepper controlled by a belay
Browse files Browse the repository at this point in the history
  • Loading branch information
rsghosh committed Jan 27, 2024
1 parent 56fcf1f commit c911f65
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
28 changes: 22 additions & 6 deletions Klipper_Stuff/klippy_module/belay.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ def __init__(self, config):
self.gcode.register_mux_command("BELAY_SET_MULTIPLIER",
"BELAY", self.name, self.cmd_BELAY_SET_MULTIPLIER,
desc=self.cmd_BELAY_SET_MULTIPLIER_help)

# register extruder_stepper-only commands
if self.type == 'extruder_stepper':
self.gcode.register_mux_command("BELAY_SET_STEPPER",
"BELAY", self.name, self.cmd_BELAY_SET_STEPPER,
desc=self.cmd_BELAY_SET_STEPPER_help)

def handle_connect(self):
self.toolhead = self.printer.lookup_object('toolhead')
Expand All @@ -78,12 +84,15 @@ def handle_connect(self):
self.enable_conditions.append(trad_rack.is_fil_driver_synced)
self.disable_conditions.append(trad_rack.is_fil_driver_synced)
elif self.type == 'extruder_stepper':
printer_extruder_stepper = self.printer.lookup_object(
'extruder_stepper {}'.format(self.extruder_stepper_name))
stepper = printer_extruder_stepper.extruder_stepper.stepper
base_rotation_dist = stepper.get_rotation_distance()[0]
self.set_multiplier = lambda m : stepper.set_rotation_distance(
base_rotation_dist / m)
self._set_extruder_stepper(self.extruder_stepper_name)

def _set_extruder_stepper(self, extruder_stepper_name):
printer_extruder_stepper = self.printer.lookup_object(
'extruder_stepper {}'.format(extruder_stepper_name))
stepper = printer_extruder_stepper.extruder_stepper.stepper
base_rotation_dist = stepper.get_rotation_distance()[0]
self.set_multiplier = lambda m : stepper.set_rotation_distance(
base_rotation_dist / m)

def handle_ready(self):
if self.enable_initial:
Expand Down Expand Up @@ -160,6 +169,13 @@ def cmd_BELAY_SET_MULTIPLIER(self, gcmd):
minval=1.)
self.multiplier_low = gcmd.get_float('LOW', self.multiplier_low,
minval=0., maxval=1.)

cmd_BELAY_SET_STEPPER_help = ("Select the extruder_stepper object to be "
"controlled by the Belay")
def cmd_BELAY_SET_STEPPER(self, gcmd):
self.handle_disable()
self._set_extruder_stepper(gcmd.get('STEPPER'))
self.handle_enable()

def get_status(self, eventtime):
return {
Expand Down
9 changes: 9 additions & 0 deletions docs/klipper/G-Codes.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,12 @@ multiplier_low for the belay specified by `BELAY`, overriding their
values from the corresponding
[belay config section](Config_Reference.md#belay). Values set by this
command will not persist across restarts.

### BELAY_SET_STEPPER
`BELAY_SET_STEPPER BELAY=<config_name> STEPPER=<extruder_stepper_name>`: Selects
the extruder_stepper whose multiplier will be controlled by the belay specified
by `BELAY`. The multiplier for the previous stepper will be reset back
to 1 before switching to the new stepper. Stepper selections made by this
command will not persist across restarts. This command is only available if
extruder_type is set to 'extruder_stepper' in the corresponding
[belay config section](Config_Reference.md#belay).

0 comments on commit c911f65

Please sign in to comment.