From b4e87ca67c66b9542165a5791f1cb87cad7b014b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20Doma=C5=84ski?= Date: Sun, 28 Jan 2024 03:24:11 +0100 Subject: [PATCH] heater_fan: log a warning if pin is non among initial pins MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This will poke a user towards configuring it as a safety measure, i.e. cooling the heater if a restart fails. Example output: `Heater fan's pin '!PA1' is not among initial pins of MCU 'toolhead'. Consider adding it for safety.` Signed-off-by: Kamil DomaƄski --- klippy/extras/heater_fan.py | 6 ++++++ klippy/mcu.py | 11 +++++++++++ 2 files changed, 17 insertions(+) diff --git a/klippy/extras/heater_fan.py b/klippy/extras/heater_fan.py index ab4c8a81e7f6..6aeee7f2a702 100644 --- a/klippy/extras/heater_fan.py +++ b/klippy/extras/heater_fan.py @@ -3,6 +3,7 @@ # Copyright (C) 2016-2020 Kevin O'Connor # # This file may be distributed under the terms of the GNU GPLv3 license. +import logging from . import fan PIN_MIN_TIME = 0.100 @@ -19,6 +20,11 @@ def __init__(self, config): self.fan_speed = config.getfloat("fan_speed", 1., minval=0., maxval=1.) self.last_speed = 0. def handle_ready(self): + if not self.fan.mcu_fan.is_initial_pin(): + logging.warning( + "Heater fan's pin '%s' is not among initial pins of MCU '%s'. " + "Consider adding it for safety." + % (self.fan.mcu_fan.raw_pin_string(), self.fan.get_mcu()._name)) pheaters = self.printer.lookup_object('heaters') self.heaters = [pheaters.lookup_heater(n) for n in self.heater_names] reactor = self.printer.get_reactor() diff --git a/klippy/mcu.py b/klippy/mcu.py index f9b547c94479..6c96cf323dcf 100644 --- a/klippy/mcu.py +++ b/klippy/mcu.py @@ -384,6 +384,17 @@ def __init__(self, mcu, pin_params): self._last_clock = 0 self._pwm_max = 0. self._set_cmd = None + def raw_pin_string(self): + ppins = self._mcu._printer.lookup_object('pins') + pin_resolver = ppins.get_pin_resolver(self._mcu._name) + pin_real_name = pin_resolver.aliases.get(self._pin, self._pin) + if self._invert: + return '!'+pin_real_name + else: + return pin_real_name + def is_initial_pin(self): + initial_pins = self._mcu.get_constants().get('INITIAL_PINS', '') + return (self.raw_pin_string() in initial_pins.split(',')) def get_mcu(self): return self._mcu def setup_max_duration(self, max_duration):