2020-02-12 16:08:30 +01:00
|
|
|
# Heater handling on homing moves
|
|
|
|
#
|
|
|
|
# Copyright (C) 2016-2018 Kevin O'Connor <kevin@koconnor.net>
|
|
|
|
#
|
|
|
|
# This file may be distributed under the terms of the GNU GPLv3 license.
|
|
|
|
|
|
|
|
import logging
|
|
|
|
|
|
|
|
class HomingHeaters:
|
|
|
|
def __init__(self, config):
|
|
|
|
self.printer = config.get_printer()
|
|
|
|
self.printer.register_event_handler("klippy:connect",
|
|
|
|
self.handle_connect)
|
2020-02-12 19:03:42 +01:00
|
|
|
self.printer.register_event_handler("homing:homing_move_begin",
|
2020-02-12 16:08:30 +01:00
|
|
|
self.handle_homing_move_begin)
|
2020-02-12 19:03:42 +01:00
|
|
|
self.printer.register_event_handler("homing:homing_move_end",
|
2020-02-12 16:08:30 +01:00
|
|
|
self.handle_homing_move_end)
|
|
|
|
self.heaters_to_disable = config.get("heaters", "")
|
|
|
|
self.disable_heaters = []
|
|
|
|
self.steppers_needing_quiet = config.get("steppers", "")
|
|
|
|
self.flaky_steppers = []
|
2020-04-25 19:27:41 +02:00
|
|
|
self.pheaters = self.printer.try_load_module(config, 'heaters')
|
2020-02-12 16:08:30 +01:00
|
|
|
self.target_save = {}
|
|
|
|
|
|
|
|
def handle_connect(self):
|
|
|
|
# heaters to disable
|
2020-04-25 19:27:41 +02:00
|
|
|
all_heaters = self.pheaters.get_all_heaters()
|
2020-02-12 16:08:30 +01:00
|
|
|
self.disable_heaters = [n.strip()
|
|
|
|
for n in self.heaters_to_disable.split(',')]
|
|
|
|
if self.disable_heaters == [""]:
|
|
|
|
self.disable_heaters = all_heaters
|
|
|
|
else:
|
|
|
|
if not all(x in all_heaters for x in self.disable_heaters):
|
|
|
|
raise self.printer.config_error(
|
|
|
|
"One or more of these heaters are unknown: %s" % (
|
|
|
|
self.disable_heaters))
|
|
|
|
# steppers valid?
|
|
|
|
kin = self.printer.lookup_object('toolhead').get_kinematics()
|
|
|
|
all_steppers = [s.get_name() for s in kin.get_steppers()]
|
|
|
|
self.flaky_steppers = [n.strip()
|
|
|
|
for n in self.steppers_needing_quiet.split(',')]
|
|
|
|
if self.flaky_steppers == [""]:
|
|
|
|
return
|
|
|
|
if not all(x in all_steppers for x in self.flaky_steppers):
|
|
|
|
raise self.printer.config_error(
|
|
|
|
"One or more of these steppers are unknown: %s" % (
|
|
|
|
self.flaky_steppers))
|
|
|
|
def check_eligible(self, endstops):
|
|
|
|
if self.flaky_steppers == [""]:
|
|
|
|
return True
|
|
|
|
steppers_being_homed = [s.get_name()
|
2020-02-12 19:03:42 +01:00
|
|
|
for es in endstops
|
2020-02-12 16:08:30 +01:00
|
|
|
for s in es.get_steppers()]
|
|
|
|
return any(x in self.flaky_steppers for x in steppers_being_homed)
|
|
|
|
def handle_homing_move_begin(self, endstops):
|
|
|
|
if not self.check_eligible(endstops):
|
|
|
|
return
|
|
|
|
for heater_name in self.disable_heaters:
|
2020-04-25 19:27:41 +02:00
|
|
|
heater = self.pheaters.lookup_heater(heater_name)
|
2020-02-12 16:08:30 +01:00
|
|
|
self.target_save[heater_name] = heater.get_temp(0)[1]
|
|
|
|
heater.set_temp(0.)
|
|
|
|
def handle_homing_move_end(self, endstops):
|
|
|
|
if not self.check_eligible(endstops):
|
|
|
|
return
|
|
|
|
for heater_name in self.disable_heaters:
|
2020-04-25 19:27:41 +02:00
|
|
|
heater = self.pheaters.lookup_heater(heater_name)
|
2020-02-12 16:08:30 +01:00
|
|
|
heater.set_temp(self.target_save[heater_name])
|
|
|
|
|
|
|
|
def load_config(config):
|
|
|
|
return HomingHeaters(config)
|