extruder: Use new GCodeCommand wrappers

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2020-04-24 21:20:18 -04:00
parent 6869611147
commit 9b6010dc7b
1 changed files with 28 additions and 32 deletions

View File

@ -148,12 +148,11 @@ class PrinterExtruder:
move.start_pos[3], 0., 0., move.start_pos[3], 0., 0.,
1., pressure_advance, 0., 1., pressure_advance, 0.,
start_v, cruise_v, accel) start_v, cruise_v, accel)
def cmd_M104(self, params, wait=False): def cmd_M104(self, gcmd, wait=False):
# Set Extruder Temperature # Set Extruder Temperature
gcode = self.printer.lookup_object('gcode') temp = gcmd.get_float('S', 0.)
temp = gcode.get_float('S', params, 0.) index = gcmd.get_int('T', None, minval=0)
if 'T' in params: if index is not None:
index = gcode.get_int('T', params, minval=0)
section = 'extruder' section = 'extruder'
if index: if index:
section = 'extruder%d' % (index,) section = 'extruder%d' % (index,)
@ -161,55 +160,52 @@ class PrinterExtruder:
if extruder is None: if extruder is None:
if temp <= 0.: if temp <= 0.:
return return
raise gcode.error("Extruder not configured") raise gcmd.error("Extruder not configured")
else: else:
extruder = self.printer.lookup_object('toolhead').get_extruder() extruder = self.printer.lookup_object('toolhead').get_extruder()
heater = extruder.get_heater() heater = extruder.get_heater()
heater.set_temp(temp) heater.set_temp(temp)
if wait and temp: if wait and temp:
self.printer.lookup_object('heaters').wait_for_temperature(heater) self.printer.lookup_object('heaters').wait_for_temperature(heater)
def cmd_M109(self, params): def cmd_M109(self, gcmd):
# Set Extruder Temperature and Wait # Set Extruder Temperature and Wait
self.cmd_M104(params, wait=True) self.cmd_M104(gcmd, wait=True)
cmd_SET_PRESSURE_ADVANCE_help = "Set pressure advance parameters" cmd_SET_PRESSURE_ADVANCE_help = "Set pressure advance parameters"
def cmd_default_SET_PRESSURE_ADVANCE(self, params): def cmd_default_SET_PRESSURE_ADVANCE(self, gcmd):
extruder = self.printer.lookup_object('toolhead').get_extruder() extruder = self.printer.lookup_object('toolhead').get_extruder()
extruder.cmd_SET_PRESSURE_ADVANCE(params) extruder.cmd_SET_PRESSURE_ADVANCE(gcmd)
def cmd_SET_PRESSURE_ADVANCE(self, params): def cmd_SET_PRESSURE_ADVANCE(self, gcmd):
gcode = self.printer.lookup_object('gcode') pressure_advance = gcmd.get_float('ADVANCE', self.pressure_advance,
pressure_advance = gcode.get_float( minval=0.)
'ADVANCE', params, self.pressure_advance, minval=0.) smooth_time = gcmd.get_float('SMOOTH_TIME',
smooth_time = gcode.get_float( self.pressure_advance_smooth_time,
'SMOOTH_TIME', params, minval=0., maxval=.200)
self.pressure_advance_smooth_time, minval=0., maxval=.200)
self._set_pressure_advance(pressure_advance, smooth_time) self._set_pressure_advance(pressure_advance, smooth_time)
msg = ("pressure_advance: %.6f\n" msg = ("pressure_advance: %.6f\n"
"pressure_advance_smooth_time: %.6f" % ( "pressure_advance_smooth_time: %.6f"
pressure_advance, smooth_time)) % (pressure_advance, smooth_time))
self.printer.set_rollover_info(self.name, "%s: %s" % (self.name, msg)) self.printer.set_rollover_info(self.name, "%s: %s" % (self.name, msg))
gcode.respond_info(msg, log=False) gcmd.respond_info(msg, log=False)
cmd_SET_E_STEP_DISTANCE_help = "Set extruder step distance" cmd_SET_E_STEP_DISTANCE_help = "Set extruder step distance"
def cmd_SET_E_STEP_DISTANCE(self, params): def cmd_SET_E_STEP_DISTANCE(self, gcmd):
gcode = self.printer.lookup_object('gcode')
toolhead = self.printer.lookup_object('toolhead') toolhead = self.printer.lookup_object('toolhead')
if 'DISTANCE' not in params: dist = gcmd.get_float('DISTANCE', None, above=0.)
if dist is None:
step_dist = self.stepper.get_step_dist() step_dist = self.stepper.get_step_dist()
gcode.respond_info("Extruder '%s' step distance is %0.6f" gcmd.respond_info("Extruder '%s' step distance is %0.6f"
% (self.name, step_dist)) % (self.name, step_dist))
return return
dist = gcode.get_float('DISTANCE', params, above=0.)
toolhead.flush_step_generation() toolhead.flush_step_generation()
self.stepper.set_step_dist(dist) self.stepper.set_step_dist(dist)
gcode.respond_info("Extruder '%s' step distance set to %0.6f" gcmd.respond_info("Extruder '%s' step distance set to %0.6f"
% (self.name, dist)) % (self.name, dist))
cmd_ACTIVATE_EXTRUDER_help = "Change the active extruder" cmd_ACTIVATE_EXTRUDER_help = "Change the active extruder"
def cmd_ACTIVATE_EXTRUDER(self, params): def cmd_ACTIVATE_EXTRUDER(self, gcmd):
gcode = self.printer.lookup_object('gcode')
toolhead = self.printer.lookup_object('toolhead') toolhead = self.printer.lookup_object('toolhead')
if toolhead.get_extruder() is self: if toolhead.get_extruder() is self:
gcode.respond_info("Extruder %s already active" % (self.name)) gcmd.respond_info("Extruder %s already active" % (self.name,))
return return
gcode.respond_info("Activating extruder %s" % (self.name)) gcmd.respond_info("Activating extruder %s" % (self.name,))
toolhead.flush_step_generation() toolhead.flush_step_generation()
toolhead.set_extruder(self, self.stepper.get_commanded_position()) toolhead.set_extruder(self, self.stepper.get_commanded_position())
self.printer.send_event("extruder:activate_extruder") self.printer.send_event("extruder:activate_extruder")