Skip to content

Commit

Permalink
Autogenerated - Upstream c4754e6
Browse files Browse the repository at this point in the history
  • Loading branch information
Klippy-Tools-Bot committed Oct 11, 2024
1 parent ccdf59c commit 67fa383
Show file tree
Hide file tree
Showing 24 changed files with 411 additions and 277 deletions.
13 changes: 13 additions & 0 deletions klippy/docs/Config_Changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,19 @@ All dates in this document are approximate.

## Changes

20240912: `SET_PIN`, `SET_SERVO`, `SET_FAN_SPEED`, `M106`, and `M107`
commands are now collated. Previously, if many updates to the same
object were issued faster than the minimum scheduling time (typically
100ms) then actual updates could be queued far into the future. Now if
many updates are issued in rapid succession then it is possible that
only the latest request will be applied. If the previous behavior is
requried then consider adding explicit `G4` delay commands between
updates.

20240912: Support for `maximum_mcu_duration` and `static_value`
parameters in `[output_pin]` config sections have been removed. These
options have been deprecated since 20240123.

20240415: The `on_error_gcode` parameter in the `[virtual_sdcard]`
config section now has a default. If this parameter is not specified
it now defaults to `TURN_OFF_HEATERS`. If the previous behavior is
Expand Down
9 changes: 7 additions & 2 deletions klippy/docs/Config_Reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -2458,6 +2458,10 @@ postfix for both sections.
# "calibration_extruder_temp" option is set. Its recommended to heat
# the extruder some distance from the bed to minimize its impact on
# the probe coil temperature. The default is 50.
#max_validation_temp: 60.
# The maximum temperature used to validate the calibration. It is
# recommended to set this to a value between 100 and 120 for enclosed
# printers. The default is 60.
```

## Temperature sensors
Expand Down Expand Up @@ -4997,8 +5001,9 @@ Most Klipper micro-controller implementations only support an
micro-controller supports a 400000 speed (*fast mode*, 400kbit/s), but it must be
[set in the operating system](RPi_microcontroller.md#optional-enabling-i2c)
and the `i2c_speed` parameter is otherwise ignored. The Klipper
"RP2040" micro-controller and ATmega AVR family support a rate of 400000
via the `i2c_speed` parameter. All other Klipper micro-controllers use a
"RP2040" micro-controller and ATmega AVR family and some STM32
(F0, G0, G4, L4, F7, H7) support a rate of 400000 via the `i2c_speed` parameter.
All other Klipper micro-controllers use a
100000 rate and ignore the `i2c_speed` parameter.

```
Expand Down
4 changes: 3 additions & 1 deletion klippy/docs/Eddy_Probe.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ for further details on how to configure a `temperature_probe`. It is
advised to configure the `calibration_position`,
`calibration_extruder_temp`, `extruder_heating_z`, and
`calibration_bed_temp` options, as doing so will automate some of the
steps outlined below.
steps outlined below. If the printer to be calibrated is enclosed, it
is strongly recommended to set the `max_validation_temp` option to a value
between 100 and 120.

Eddy probe manufacturers may offer a stock drift calibration that can be
manually added to `drift_calibration` option of the `[probe_eddy_current]`
Expand Down
28 changes: 28 additions & 0 deletions klippy/docs/G-Codes.md
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,20 @@ enabled.
`SET_FAN_SPEED FAN=config_name SPEED=<speed>` This command sets the
speed of a fan. "speed" must be between 0.0 and 1.0.

`SET_FAN_SPEED PIN=config_name TEMPLATE=<template_name>
[<param_x>=<literal>]`: If `TEMPLATE` is specified then it assigns a
[display_template](Config_Reference.md#display_template) to the given
fan. For example, if one defined a `[display_template
my_fan_template]` config section then one could assign
`TEMPLATE=my_fan_template` here. The display_template should produce a
string containing a floating point number with the desired value. The
template will be continuously evaluated and the fan will be
automatically set to the resulting speed. One may set display_template
parameters to use during template evaluation (parameters will be
parsed as Python literals). If TEMPLATE is an empty string then this
command will clear any previous template assigned to the pin (one can
then use `SET_FAN_SPEED` commands to manage the values directly).

### [filament_switch_sensor]

The following command is available when a
Expand Down Expand Up @@ -857,6 +871,20 @@ output `VALUE`. VALUE should be 0 or 1 for "digital" output pins. For
PWM pins, set to a value between 0.0 and 1.0, or between 0.0 and
`scale` if a scale is configured in the output_pin config section.

`SET_PIN PIN=config_name TEMPLATE=<template_name> [<param_x>=<literal>]`:
If `TEMPLATE` is specified then it assigns a
[display_template](Config_Reference.md#display_template) to the given
pin. For example, if one defined a `[display_template
my_pin_template]` config section then one could assign
`TEMPLATE=my_pin_template` here. The display_template should produce a
string containing a floating point number with the desired value. The
template will be continuously evaluated and the pin will be
automatically set to the resulting value. One may set display_template
parameters to use during template evaluation (parameters will be
parsed as Python literals). If TEMPLATE is an empty string then this
command will clear any previous template assigned to the pin (one can
then use `SET_PIN` commands to manage the values directly).

### [palette2]

The following commands are available when the
Expand Down
2 changes: 1 addition & 1 deletion klippy/extras/ads1220.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def hexify(byte_array):
return "[%s]" % (", ".join([hex(b) for b in byte_array]))


class ADS1220():
class ADS1220:
def __init__(self, config):
self.printer = printer = config.get_printer()
self.name = config.get_name().split()[-1]
Expand Down
18 changes: 1 addition & 17 deletions klippy/extras/bus.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def __init__(self, mcu, bus, addr, speed, sw_pins=None):
% (self.oid, speed, addr))
self.cmd_queue = self.mcu.alloc_command_queue()
self.mcu.register_config_callback(self.build_config)
self.i2c_write_cmd = self.i2c_read_cmd = self.i2c_modify_bits_cmd = None
self.i2c_write_cmd = self.i2c_read_cmd = None
def get_oid(self):
return self.oid
def get_mcu(self):
Expand All @@ -180,9 +180,6 @@ def build_config(self):
"i2c_read oid=%c reg=%*s read_len=%u",
"i2c_read_response oid=%c response=%*s", oid=self.oid,
cq=self.cmd_queue)
self.i2c_modify_bits_cmd = self.mcu.lookup_command(
"i2c_modify_bits oid=%c reg=%*s clear_set_bits=%*s",
cq=self.cmd_queue)
def i2c_write(self, data, minclock=0, reqclock=0):
if self.i2c_write_cmd is None:
# Send setup message via mcu initialization
Expand All @@ -197,19 +194,6 @@ def i2c_write_wait_ack(self, data, minclock=0, reqclock=0):
minclock=minclock, reqclock=reqclock)
def i2c_read(self, write, read_len):
return self.i2c_read_cmd.send([self.oid, write, read_len])
def i2c_modify_bits(self, reg, clear_bits, set_bits,
minclock=0, reqclock=0):
clearset = clear_bits + set_bits
if self.i2c_modify_bits_cmd is None:
# Send setup message via mcu initialization
reg_msg = "".join(["%02x" % (x,) for x in reg])
clearset_msg = "".join(["%02x" % (x,) for x in clearset])
self.mcu.add_config_cmd(
"i2c_modify_bits oid=%d reg=%s clear_set_bits=%s" % (
self.oid, reg_msg, clearset_msg), is_init=True)
return
self.i2c_modify_bits_cmd.send([self.oid, reg, clearset],
minclock=minclock, reqclock=reqclock)

def MCU_I2C_from_config(config, default_addr=None, default_speed=100000):
# Load bus parameters
Expand Down
4 changes: 1 addition & 3 deletions klippy/extras/controller_fan.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,7 @@ def callback(self, eventtime):
self.last_on += 1
if speed != self.last_speed:
self.last_speed = speed
curtime = self.printer.get_reactor().monotonic()
print_time = self.fan.get_mcu().estimated_print_time(curtime)
self.fan.set_speed(print_time + PIN_MIN_TIME, speed)
self.fan.set_speed(speed)
return eventtime + 1.

def load_config_prefix(config):
Expand Down
9 changes: 4 additions & 5 deletions klippy/extras/dotstar.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Support for "dotstar" leds
#
# Copyright (C) 2019-2022 Kevin O'Connor <[email protected]>
# Copyright (C) 2019-2024 Kevin O'Connor <[email protected]>
#
# This file may be distributed under the terms of the GNU GPLv3 license.
from . import bus
from . import bus, led

BACKGROUND_PRIORITY_CLOCK = 0x7fffffff00000000

Expand All @@ -22,9 +22,8 @@ def __init__(self, config):
self.spi = bus.MCU_SPI(mcu, None, None, 0, 500000, sw_spi_pins)
# Initialize color data
self.chain_count = config.getint('chain_count', 1, minval=1)
pled = printer.load_object(config, "led")
self.led_helper = pled.setup_helper(config, self.update_leds,
self.chain_count)
self.led_helper = led.LEDHelper(config, self.update_leds,
self.chain_count)
self.prev_data = None
# Register commands
printer.register_event_handler("klippy:connect", self.handle_connect)
Expand Down
37 changes: 19 additions & 18 deletions klippy/extras/fan.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
# Printer cooling fan
#
# Copyright (C) 2016-2020 Kevin O'Connor <[email protected]>
# Copyright (C) 2016-2024 Kevin O'Connor <[email protected]>
#
# This file may be distributed under the terms of the GNU GPLv3 license.
from . import pulse_counter

FAN_MIN_TIME = 0.100
from . import pulse_counter, output_pin

class Fan:
def __init__(self, config, default_shutdown_speed=0.):
self.printer = config.get_printer()
self.last_fan_value = 0.
self.last_fan_time = 0.
self.last_fan_value = self.last_req_value = 0.
# Read config
self.max_power = config.getfloat('max_power', 1., above=0., maxval=1.)
self.kick_start_time = config.getfloat('kick_start_time', 0.1,
Expand All @@ -36,6 +33,10 @@ def __init__(self, config, default_shutdown_speed=0.):
self.enable_pin = ppins.setup_pin('digital_out', enable_pin)
self.enable_pin.setup_max_duration(0.)

# Create gcode request queue
self.gcrq = output_pin.GCodeRequestQueue(config, self.mcu_fan.get_mcu(),
self._apply_speed)

# Setup tachometer
self.tachometer = FanTachometer(config)

Expand All @@ -45,37 +46,37 @@ def __init__(self, config, default_shutdown_speed=0.):

def get_mcu(self):
return self.mcu_fan.get_mcu()
def set_speed(self, print_time, value):
def _apply_speed(self, print_time, value):
if value < self.off_below:
value = 0.
value = max(0., min(self.max_power, value * self.max_power))
if value == self.last_fan_value:
return
print_time = max(self.last_fan_time + FAN_MIN_TIME, print_time)
return "discard", 0.
if self.enable_pin:
if value > 0 and self.last_fan_value == 0:
self.enable_pin.set_digital(print_time, 1)
elif value == 0 and self.last_fan_value > 0:
self.enable_pin.set_digital(print_time, 0)
if (value and value < self.max_power and self.kick_start_time
if (value and self.kick_start_time
and (not self.last_fan_value or value - self.last_fan_value > .5)):
# Run fan at full speed for specified kick_start_time
self.last_req_value = value
self.last_fan_value = self.max_power
self.mcu_fan.set_pwm(print_time, self.max_power)
print_time += self.kick_start_time
return "delay", self.kick_start_time
self.last_fan_value = self.last_req_value = value
self.mcu_fan.set_pwm(print_time, value)
self.last_fan_time = print_time
self.last_fan_value = value
def set_speed(self, value, print_time=None):
self.gcrq.send_async_request(value, print_time)
def set_speed_from_command(self, value):
toolhead = self.printer.lookup_object('toolhead')
toolhead.register_lookahead_callback((lambda pt:
self.set_speed(pt, value)))
self.gcrq.queue_gcode_request(value)
def _handle_request_restart(self, print_time):
self.set_speed(print_time, 0.)
self.set_speed(0., print_time)

def get_status(self, eventtime):
tachometer_status = self.tachometer.get_status(eventtime)
return {
'speed': self.last_fan_value,
'speed': self.last_req_value,
'rpm': tachometer_status['rpm'],
}

Expand Down
22 changes: 19 additions & 3 deletions klippy/extras/fan_generic.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Support fans that are controlled by gcode
#
# Copyright (C) 2016-2020 Kevin O'Connor <[email protected]>
# Copyright (C) 2016-2024 Kevin O'Connor <[email protected]>
#
# This file may be distributed under the terms of the GNU GPLv3 license.
from . import fan
from . import fan, output_pin

class PrinterFanGeneric:
cmd_SET_FAN_SPEED_help = "Sets the speed of a fan"
Expand All @@ -12,6 +12,9 @@ def __init__(self, config):
self.fan = fan.Fan(config, default_shutdown_speed=0.)
self.fan_name = config.get_name().split()[-1]

# Template handling
self.template_eval = output_pin.lookup_template_eval(config)

gcode = self.printer.lookup_object("gcode")
gcode.register_mux_command("SET_FAN_SPEED", "FAN",
self.fan_name,
Expand All @@ -20,8 +23,21 @@ def __init__(self, config):

def get_status(self, eventtime):
return self.fan.get_status(eventtime)
def _template_update(self, text):
try:
value = float(text)
except ValueError as e:
logging.exception("fan_generic template render error")
self.fan.set_speed(value)
def cmd_SET_FAN_SPEED(self, gcmd):
speed = gcmd.get_float('SPEED', 0.)
speed = gcmd.get_float('SPEED', None, 0.)
template = gcmd.get('TEMPLATE', None)
if (speed is None) == (template is None):
raise gcmd.error("SET_FAN_SPEED must specify SPEED or TEMPLATE")
# Check for template setting
if template is not None:
self.template_eval.set_template(gcmd, self._template_update)
return
self.fan.set_speed_from_command(speed)

def load_config_prefix(config):
Expand Down
4 changes: 1 addition & 3 deletions klippy/extras/heater_fan.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ def callback(self, eventtime):
speed = self.fan_speed
if speed != self.last_speed:
self.last_speed = speed
curtime = self.printer.get_reactor().monotonic()
print_time = self.fan.get_mcu().estimated_print_time(curtime)
self.fan.set_speed(print_time + PIN_MIN_TIME, speed)
self.fan.set_speed(speed)
return eventtime + 1.

def load_config_prefix(config):
Expand Down
3 changes: 2 additions & 1 deletion klippy/extras/heaters.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,8 @@ def load_config(self, config):
try:
dconfig = pconfig.read_config(filename)
except Exception:
raise config.config_error("Cannot load config '%s'" % (filename,))
logging.exception("Unable to load temperature_sensors.cfg")
raise config.error("Cannot load config '%s'" % (filename,))
for c in dconfig.get_prefix_sections(''):
self.printer.load_object(dconfig, c.get_name())
def add_sensor_factory(self, sensor_type, sensor_factory):
Expand Down
30 changes: 14 additions & 16 deletions klippy/extras/hx71x.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
SAMPLE_ERROR_LONG_READ = 0x40000000

# Implementation of HX711 and HX717
class HX71xBase():
class HX71xBase:
def __init__(self, config, sensor_type,
sample_rate_options, default_sample_rate,
gain_options, default_gain):
Expand Down Expand Up @@ -145,23 +145,21 @@ def _process_batch(self, eventtime):
'overflows': self.ffreader.get_last_overflows()}


class HX711(HX71xBase):
def __init__(self, config):
super(HX711, self).__init__(config, "hx711",
# HX711 sps options
{80: 80, 10: 10}, 80,
# HX711 gain/channel options
{'A-128': 1, 'B-32': 2, 'A-64': 3}, 'A-128')
def HX711(config):
return HX71xBase(config, "hx711",
# HX711 sps options
{80: 80, 10: 10}, 80,
# HX711 gain/channel options
{'A-128': 1, 'B-32': 2, 'A-64': 3}, 'A-128')


class HX717(HX71xBase):
def __init__(self, config):
super(HX717, self).__init__(config, "hx717",
# HX717 sps options
{320: 320, 80: 80, 20: 20, 10: 10}, 320,
# HX717 gain/channel options
{'A-128': 1, 'B-64': 2, 'A-64': 3,
'B-8': 4}, 'A-128')
def HX717(config):
return HX71xBase(config, "hx717",
# HX717 sps options
{320: 320, 80: 80, 20: 20, 10: 10}, 320,
# HX717 gain/channel options
{'A-128': 1, 'B-64': 2, 'A-64': 3,
'B-8': 4}, 'A-128')


HX71X_SENSOR_TYPES = {
Expand Down
Loading

0 comments on commit 67fa383

Please sign in to comment.