Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

disable heaters if a specified mcu is connected #425

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ See the [Danger Features document](https://dangerklipper.io/Danger_Features.html

- [danger_options: configurable homing constants](https://github.com/DangerKlippers/danger-klipper/pull/378)

- [adxl: disable heaters when connected](https://github.com/DangerKlippers/danger-klipper/pull/425)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the message needs improving


If you're feeling adventurous, take a peek at the extra features in the bleeding-edge-v2 branch [feature documentation](docs/Bleeding_Edge.md)
and [feature configuration reference](docs/Config_Reference_Bleeding_Edge.md):

Expand Down
8 changes: 8 additions & 0 deletions docs/Config_Reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -2018,6 +2018,10 @@ cs_pin:
# not recommended to change this rate from the default 3200, and
# rates below 800 will considerably affect the quality of resonance
# measurements.
#disable_heaters:
# A list of heaters to disable when this adxl is connected.
# Useful for Nozzle-ADXL to automatically disable the hotend so you don't
# fry them.
```

### [lis2dw]
Expand All @@ -2039,6 +2043,8 @@ cs_pin:
# above parameters.
#axes_map: x, y, z
# See the "adxl345" section for information on this parameter.
#disable_heaters:
# See the "adxl345" section for information on this parameter.
```

### [mpu9250]
Expand All @@ -2060,6 +2066,8 @@ accelerometers (one may define any number of sections with an
# above parameters. The default "i2c_speed" is 400000.
#axes_map: x, y, z
# See the "adxl345" section for information on this parameter.
#disable_heaters:
# See the "adxl345" section for information on this parameter.
```

### [resonance_tester]
Expand Down
38 changes: 38 additions & 0 deletions klippy/extras/adxl345.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,15 +125,53 @@ def write_impl():
class AccelCommandHelper:
def __init__(self, config, chip):
self.printer = config.get_printer()
self.reactor = self.printer.get_reactor()
self.chip = chip
self.bg_client = None
name_parts = config.get_name().split()
self.base_name = name_parts[0]
self.name = name_parts[-1]
self.register_commands(self.name)
self.disabled_heaters = []
if hasattr(config, "getlist"):
self.disabled_heaters = config.getlist(
"disable_heaters", self.disabled_heaters
)
Zeanon marked this conversation as resolved.
Show resolved Hide resolved
if len(name_parts) == 1:
if self.name == "adxl345" or not config.has_section("adxl345"):
self.register_commands(None)
self.printer.register_event_handler("klippy:ready", self._handle_ready)

def read_accelerometer(self):
toolhead = self.printer.lookup_object("toolhead")
aclient = self.chip.start_internal_client()
toolhead.dwell(1.0)
aclient.finish_measurements()
values = aclient.get_samples()
if not values:
raise Exception("No accelerometer measurements found")

def _handle_ready(self):
self.reactor.register_callback(self._init_accel, self.reactor.NOW)

def _init_accel(self, eventtime=None):
try:
self.read_accelerometer()
connected = True
except Exception as e:
connected = False
for heater_name in self.disabled_heaters:
heater_object = self.printer.lookup_object(heater_name)
if not hasattr(heater_object, "heater"):
raise self.printer.config_error(
"'%s' is not a valid heater." % (heater_name,)
)
heater = heater_object.heater
if not hasattr(heater, "set_enabled"):
raise self.printer.config_error(
"'%s' is not a valid heater." % (heater_name,)
)
heater.set_enabled(not connected)

def register_commands(self, name):
# Register commands
Expand Down
13 changes: 13 additions & 0 deletions klippy/extras/heaters.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ def __init__(self, config, sensor):
self.printer.get_start_args().get("debugoutput") is not None
)
self.can_extrude = self.min_extrude_temp <= 0.0 or is_fileoutput
self.enabled = True
self.max_power = config.getfloat(
"max_power", 1.0, above=0.0, maxval=1.0
)
Expand Down Expand Up @@ -130,6 +131,12 @@ def __init__(self, config, sensor):
"klippy:shutdown", self._handle_shutdown
)

def notify_disabled(self):
raise self.printer.command_error(
"Heater [%s] is disabled due to an "
"accelerometer being connected." % self.short_name
Zeanon marked this conversation as resolved.
Show resolved Hide resolved
)

def lookup_control(self, profile, load_clean=False):
algos = collections.OrderedDict(
{
Expand Down Expand Up @@ -261,6 +268,9 @@ def get_status(self, eventtime):
ret["control_stats"] = control_stats
return ret

def set_enabled(self, enabled):
self.enabled = enabled

def is_adc_faulty(self):
if self.last_temp > self.max_temp or self.last_temp < self.min_temp:
return True
Expand Down Expand Up @@ -1102,6 +1112,9 @@ def check(eventtime):
self.printer.wait_while(check)

def set_temperature(self, heater, temp, wait=False):
if not heater.enabled:
heater.notify_disabled()
return
toolhead = self.printer.lookup_object("toolhead")
toolhead.register_lookahead_callback((lambda pt: None))
heater.set_temp(temp)
Expand Down
1 change: 1 addition & 0 deletions test/klippy/input_shaper.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ shaper_freq_x: 39.3
[adxl345]
cs_pin: PK7
axes_map: -x,-y,z
disable_heaters: extruder

[mpu9250 my_mpu]

Expand Down
Loading