heater_bed: Move M140/M190 commands from gcode.py to heater_bed.py

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2019-12-16 19:35:49 -05:00
parent 0e2d1a190e
commit 9654816abf
2 changed files with 32 additions and 14 deletions

View File

@ -1,9 +1,32 @@
# Support for a heated bed # Support for a heated bed
# #
# Copyright (C) 2018 Kevin O'Connor <kevin@koconnor.net> # Copyright (C) 2018-2019 Kevin O'Connor <kevin@koconnor.net>
# #
# This file may be distributed under the terms of the GNU GPLv3 license. # This file may be distributed under the terms of the GNU GPLv3 license.
class PrinterHeaterBed:
def __init__(self, config):
self.printer = config.get_printer()
pheater = self.printer.lookup_object('heater')
self.heater = pheater.setup_heater(config, 'B')
self.get_status = self.heater.get_status
self.stats = self.heater.stats
# Register commands
gcode = self.printer.lookup_object('gcode')
gcode.register_command("M140", self.cmd_M140)
gcode.register_command("M190", self.cmd_M190)
def cmd_M140(self, params, wait=False):
# Set Bed Temperature
gcode = self.printer.lookup_object('gcode')
temp = gcode.get_float('S', params, 0.)
toolhead = self.printer.lookup_object('toolhead')
print_time = toolhead.get_last_move_time()
self.heater.set_temp(print_time, temp)
if wait and temp:
gcode.wait_for_temperature(self.heater)
def cmd_M190(self, params):
# Set Bed Temperature and Wait
self.cmd_M140(params, wait=True)
def load_config(config): def load_config(config):
pheater = config.get_printer().lookup_object('heater') return PrinterHeaterBed(config)
return pheater.setup_heater(config, 'B')

View File

@ -399,12 +399,10 @@ 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, is_bed=False, wait=False): def _set_temp(self, params, wait=False):
temp = self.get_float('S', params, 0.) temp = self.get_float('S', params, 0.)
heater = None heater = None
if is_bed: if 'T' in params:
heater = self.printer.lookup_object('heater_bed', None)
elif 'T' in params:
index = self.get_int('T', params, minval=0) index = self.get_int('T', params, minval=0)
section = 'extruder' section = 'extruder'
if index: if index:
@ -437,6 +435,9 @@ 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.):
# Don't warn about requests to turn off heaters when not present
return
elif cmd == 'M107' or (cmd == 'M106' and ( elif cmd == 'M107' or (cmd == 'M106' and (
not self.get_float('S', params, 1.) or self.is_fileinput)): not self.get_float('S', params, 1.) or self.is_fileinput)):
# Don't warn about requests to turn off fan when fan not present # Don't warn about requests to turn off fan when fan not present
@ -456,7 +457,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', 'M140', 'M190', 'M105', 'M104', 'M109',
'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
@ -627,12 +628,6 @@ class GCodeParser:
def cmd_M109(self, params): def cmd_M109(self, params):
# Set Extruder Temperature and Wait # Set Extruder Temperature and Wait
self._set_temp(params, wait=True) self._set_temp(params, wait=True)
def cmd_M140(self, params):
# Set Bed Temperature
self._set_temp(params, is_bed=True)
def cmd_M190(self, params):
# Set Bed Temperature and Wait
self._set_temp(params, is_bed=True, wait=True)
# G-Code miscellaneous commands # 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):