Skip to content

Commit

Permalink
heater_fan: log a warning if pin is non among initial pins
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
kdomanski committed Jan 31, 2024
1 parent 600e89a commit b4e87ca
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
6 changes: 6 additions & 0 deletions klippy/extras/heater_fan.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# Copyright (C) 2016-2020 Kevin O'Connor <[email protected]>
#
# This file may be distributed under the terms of the GNU GPLv3 license.
import logging
from . import fan

PIN_MIN_TIME = 0.100
Expand All @@ -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()
Expand Down
11 changes: 11 additions & 0 deletions klippy/mcu.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit b4e87ca

Please sign in to comment.