extruder: Move M104/M140 commands from gcode.py to extruder.py

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2019-12-16 20:08:00 -05:00
parent 9654816abf
commit f4c4de1a24
2 changed files with 31 additions and 33 deletions

View File

@ -399,27 +399,6 @@ class GCodeParser:
print_time = self.toolhead.get_last_move_time() print_time = self.toolhead.get_last_move_time()
self.respond(self._get_temp(eventtime)) self.respond(self._get_temp(eventtime))
eventtime = self.reactor.pause(eventtime + 1.) eventtime = self.reactor.pause(eventtime + 1.)
def _set_temp(self, params, wait=False):
temp = self.get_float('S', params, 0.)
heater = None
if 'T' in params:
index = self.get_int('T', params, minval=0)
section = 'extruder'
if index:
section = 'extruder%d' % (index,)
extruder = self.printer.lookup_object(section, None)
if extruder is not None:
heater = extruder.get_heater()
else:
heater = self.toolhead.get_extruder().get_heater()
if heater is None:
if temp > 0.:
self.respond_error("Heater not configured")
return
print_time = self.toolhead.get_last_move_time()
heater.set_temp(print_time, temp)
if wait and temp:
self.wait_for_temperature(heater)
# G-Code special command handlers # G-Code special command handlers
def cmd_default(self, params): def cmd_default(self, params):
if not self.is_printer_ready: if not self.is_printer_ready:
@ -435,7 +414,7 @@ class GCodeParser:
if handler is not None: if handler is not None:
handler(params) handler(params)
return return
elif cmd == 'M140' and not self.get_float('S', params, 0.): elif cmd in ['M140', 'M104'] and not self.get_float('S', params, 0.):
# Don't warn about requests to turn off heaters when not present # Don't warn about requests to turn off heaters when not present
return return
elif cmd == 'M107' or (cmd == 'M106' and ( elif cmd == 'M107' or (cmd == 'M106' and (
@ -457,8 +436,7 @@ class GCodeParser:
'G1', 'G4', 'G28', 'M400', 'G1', 'G4', 'G28', 'M400',
'G20', 'M82', 'M83', 'G90', 'G91', 'G92', 'M114', 'M220', 'M221', 'G20', 'M82', 'M83', 'G90', 'G91', 'G92', 'M114', 'M220', 'M221',
'SET_GCODE_OFFSET', 'SAVE_GCODE_STATE', 'RESTORE_GCODE_STATE', 'SET_GCODE_OFFSET', 'SAVE_GCODE_STATE', 'RESTORE_GCODE_STATE',
'M105', 'M104', 'M109', 'M105', 'M112', 'M115', 'IGNORE', 'GET_POSITION',
'M112', 'M115', 'IGNORE', 'GET_POSITION',
'RESTART', 'FIRMWARE_RESTART', 'ECHO', 'STATUS', 'HELP'] 'RESTART', 'FIRMWARE_RESTART', 'ECHO', 'STATUS', 'HELP']
# G-Code movement commands # G-Code movement commands
cmd_G1_aliases = ['G0'] cmd_G1_aliases = ['G0']
@ -613,7 +591,7 @@ class GCodeParser:
speed = self.get_float('MOVE_SPEED', params, self.speed, above=0.) speed = self.get_float('MOVE_SPEED', params, self.speed, above=0.)
self.last_position[:3] = state['last_position'][:3] self.last_position[:3] = state['last_position'][:3]
self.move_with_transform(self.last_position, speed) self.move_with_transform(self.last_position, speed)
# G-Code temperature commands # G-Code miscellaneous commands
cmd_M105_when_not_ready = True cmd_M105_when_not_ready = True
def cmd_M105(self, params): def cmd_M105(self, params):
# Get Extruder Temperature # Get Extruder Temperature
@ -622,13 +600,6 @@ class GCodeParser:
self.ack(msg) self.ack(msg)
else: else:
self.respond(msg) self.respond(msg)
def cmd_M104(self, params):
# Set Extruder Temperature
self._set_temp(params)
def cmd_M109(self, params):
# Set Extruder Temperature and Wait
self._set_temp(params, wait=True)
# G-Code miscellaneous commands
cmd_M112_when_not_ready = True cmd_M112_when_not_ready = True
def cmd_M112(self, params): def cmd_M112(self, params):
# Emergency Stop # Emergency Stop

View File

@ -62,6 +62,8 @@ class PrinterExtruder:
gcode = self.printer.lookup_object('gcode') gcode = self.printer.lookup_object('gcode')
if self.name == 'extruder': if self.name == 'extruder':
toolhead.set_extruder(self, self.extrude_pos) toolhead.set_extruder(self, self.extrude_pos)
gcode.register_command("M104", self.cmd_M104)
gcode.register_command("M109", self.cmd_M109)
gcode.register_mux_command("SET_PRESSURE_ADVANCE", "EXTRUDER", None, gcode.register_mux_command("SET_PRESSURE_ADVANCE", "EXTRUDER", None,
self.cmd_default_SET_PRESSURE_ADVANCE, self.cmd_default_SET_PRESSURE_ADVANCE,
desc=self.cmd_SET_PRESSURE_ADVANCE_help) desc=self.cmd_SET_PRESSURE_ADVANCE_help)
@ -87,7 +89,7 @@ class PrinterExtruder:
self.pressure_advance = pressure_advance self.pressure_advance = pressure_advance
self.pressure_advance_smooth_time = smooth_time self.pressure_advance_smooth_time = smooth_time
def get_status(self, eventtime): def get_status(self, eventtime):
return dict(self.get_heater().get_status(eventtime), return dict(self.heater.get_status(eventtime),
pressure_advance=self.pressure_advance, pressure_advance=self.pressure_advance,
smooth_time=self.pressure_advance_smooth_time) smooth_time=self.pressure_advance_smooth_time)
def get_name(self): def get_name(self):
@ -143,6 +145,31 @@ class PrinterExtruder:
1., pressure_advance, 0., 1., pressure_advance, 0.,
start_v, cruise_v, accel) start_v, cruise_v, accel)
self.extrude_pos = move.end_pos[3] self.extrude_pos = move.end_pos[3]
def cmd_M104(self, params, wait=False):
# Set Extruder Temperature
toolhead = self.printer.lookup_object('toolhead')
gcode = self.printer.lookup_object('gcode')
temp = gcode.get_float('S', params, 0.)
if 'T' in params:
index = gcode.get_int('T', params, minval=0)
section = 'extruder'
if index:
section = 'extruder%d' % (index,)
extruder = self.printer.lookup_object(section, None)
if extruder is None:
if temp <= 0.:
return
raise gcode.error("Extruder not configured")
else:
extruder = toolhead.get_extruder()
print_time = toolhead.get_last_move_time()
heater = extruder.get_heater()
heater.set_temp(print_time, temp)
if wait and temp:
gcode.wait_for_temperature(heater)
def cmd_M109(self, params):
# Set Extruder Temperature and Wait
self.cmd_M104(params, 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, params):
extruder = self.printer.lookup_object('toolhead').get_extruder() extruder = self.printer.lookup_object('toolhead').get_extruder()