fan: Allow heater_fan to work with heater_bed

Fix order of init error preventing heater_fan from being used with
heater_bed.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2017-09-06 14:51:47 -04:00
parent 477b3941a6
commit 7d17002b33
3 changed files with 12 additions and 14 deletions

View File

@ -252,11 +252,10 @@ def get_printer_extruders(printer):
return out return out
def get_printer_heater(printer, name): def get_printer_heater(printer, name):
if name == 'heater_bed': if name == 'heater_bed' and name in printer.objects:
return printer.objects.get(name) return printer.objects[name]
if name == 'extruder': if name == 'extruder':
name = 'extruder0' name = 'extruder0'
extruder = printer.objects.get(name) if name.startswith('extruder') and name in printer.objects:
if extruder is None: return printer.objects[name].get_heater()
return None raise printer.config_error("Unknown heater '%s'" % (name,))
return extruder.get_heater()

View File

@ -41,8 +41,6 @@ class PrinterHeaterFan:
self.fan = PrinterFan(printer, config) self.fan = PrinterFan(printer, config)
heater = config.get("heater", "extruder0") heater = config.get("heater", "extruder0")
self.heater = extruder.get_printer_heater(printer, heater) self.heater = extruder.get_printer_heater(printer, heater)
if self.heater is None:
raise config.error("Unknown heater '%s'" % (heater,))
self.heater_temp = config.getfloat("heater_temp", 50.0) self.heater_temp = config.getfloat("heater_temp", 50.0)
printer.reactor.register_timer(self.callback, printer.reactor.NOW) printer.reactor.register_timer(self.callback, printer.reactor.NOW)
def callback(self, eventtime): def callback(self, eventtime):

View File

@ -6,7 +6,7 @@
# 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.
import sys, optparse, ConfigParser, logging, time, threading import sys, optparse, ConfigParser, logging, time, threading
import util, reactor, queuelogger, msgproto, gcode import util, reactor, queuelogger, msgproto, gcode
import pins, mcu, chipmisc, toolhead, extruder, fan, heater import pins, mcu, chipmisc, toolhead, extruder, heater, fan
message_ready = "Printer is ready" message_ready = "Printer is ready"
@ -123,6 +123,7 @@ class ConfigLogger():
self.lines.append(data.strip()) self.lines.append(data.strip())
class Printer: class Printer:
config_error = ConfigParser.Error
def __init__(self, input_fd, bglogger, start_args): def __init__(self, input_fd, bglogger, start_args):
self.bglogger = bglogger self.bglogger = bglogger
self.start_args = start_args self.start_args = start_args
@ -166,13 +167,13 @@ class Printer:
config_file = self.start_args['config_file'] config_file = self.start_args['config_file']
res = self.fileconfig.read(config_file) res = self.fileconfig.read(config_file)
if not res: if not res:
raise ConfigParser.Error("Unable to open config file %s" % ( raise self.config_error("Unable to open config file %s" % (
config_file,)) config_file,))
if self.bglogger is not None: if self.bglogger is not None:
ConfigLogger(self.fileconfig, self.bglogger) ConfigLogger(self.fileconfig, self.bglogger)
# Create printer components # Create printer components
config = ConfigWrapper(self, 'printer') config = ConfigWrapper(self, 'printer')
for m in [pins, mcu, chipmisc, toolhead, extruder, fan, heater]: for m in [pins, mcu, chipmisc, toolhead, extruder, heater, fan]:
m.add_printer_objects(self, config) m.add_printer_objects(self, config)
self.mcu = self.objects['mcu'] self.mcu = self.objects['mcu']
# Validate that there are no undefined parameters in the config file # Validate that there are no undefined parameters in the config file
@ -180,12 +181,12 @@ class Printer:
for section in self.fileconfig.sections(): for section in self.fileconfig.sections():
section = section.lower() section = section.lower()
if section not in valid_sections: if section not in valid_sections:
raise ConfigParser.Error("Unknown config file section '%s'" % ( raise self.config_error("Unknown config file section '%s'" % (
section,)) section,))
for option in self.fileconfig.options(section): for option in self.fileconfig.options(section):
option = option.lower() option = option.lower()
if (section, option) not in self.all_config_options: if (section, option) not in self.all_config_options:
raise ConfigParser.Error( raise self.config_error(
"Unknown option '%s' in section '%s'" % ( "Unknown option '%s' in section '%s'" % (
option, section)) option, section))
def _connect(self, eventtime): def _connect(self, eventtime):
@ -196,7 +197,7 @@ class Printer:
self.mcu.connect() self.mcu.connect()
self.gcode.set_printer_ready(True) self.gcode.set_printer_ready(True)
self.state_message = message_ready self.state_message = message_ready
except (ConfigParser.Error, pins.error) as e: except (self.config_error, pins.error) as e:
logging.exception("Config error") logging.exception("Config error")
self.state_message = "%s%s" % (str(e), message_restart) self.state_message = "%s%s" % (str(e), message_restart)
self.reactor.update_timer(self.stats_timer, self.reactor.NEVER) self.reactor.update_timer(self.stats_timer, self.reactor.NEVER)