Skip to content

Commit

Permalink
format files
Browse files Browse the repository at this point in the history
  • Loading branch information
rogerlz committed May 23, 2024
1 parent 8394dcc commit b7db34e
Show file tree
Hide file tree
Showing 35 changed files with 94 additions and 69 deletions.
12 changes: 6 additions & 6 deletions klippy/extras/bed_mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -793,9 +793,9 @@ def set_adaptive_mesh(self, gcmd):
new_probe_count = max(new_x_probe_count, new_y_probe_count)
# Adaptive meshes require odd number of points
new_probe_count += 1 - (new_probe_count % 2)
self.mesh_config["x_count"] = self.mesh_config[
"y_count"
] = new_probe_count
self.mesh_config["x_count"] = self.mesh_config["y_count"] = (
new_probe_count
)
else:
self.mesh_min = adjusted_mesh_min
self.mesh_max = adjusted_mesh_max
Expand Down Expand Up @@ -1504,9 +1504,9 @@ def __init__(self, config, bedmesh):
self.profiles[name] = {}
zvals = profile.getlists("points", seps=(",", "\n"), parser=float)
self.profiles[name]["points"] = zvals
self.profiles[name][
"mesh_params"
] = params = collections.OrderedDict()
self.profiles[name]["mesh_params"] = params = (
collections.OrderedDict()
)
for key, t in PROFILE_OPTIONS.items():
if t is int:
params[key] = profile.getint(key)
Expand Down
1 change: 1 addition & 0 deletions klippy/extras/bed_tilt.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ def probe_finalize(self, offsets, positions):
"z_adjust": z_offset,
}
logging.info("Initial bed_tilt parameters: %s", params)

# Perform coordinate descent
def adjusted_height(pos, params):
x, y, z = pos
Expand Down
3 changes: 3 additions & 0 deletions klippy/extras/bus.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def resolve_bus_name(mcu, param, bus):
# SPI
######################################################################


# Helper code for working with devices connected to an MCU via an SPI bus
class MCU_SPI:
def __init__(
Expand Down Expand Up @@ -176,6 +177,7 @@ def MCU_SPI_from_config(
# I2C
######################################################################


# Helper code for working with devices connected to an MCU via an I2C bus
class MCU_I2C:
def __init__(self, mcu, bus, addr, speed, sw_pins=None):
Expand Down Expand Up @@ -297,6 +299,7 @@ def MCU_I2C_from_config(config, default_addr=None, default_speed=100000):
# Bus synchronized digital outputs
######################################################################


# Helper code for a gpio that updates on a cmd_queue
class MCU_bus_digital_out:
def __init__(self, mcu, pin_desc, cmd_queue=None, value=0):
Expand Down
3 changes: 3 additions & 0 deletions klippy/extras/delta_calibrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# calibration uses this coordinate system because it allows a position
# to be described independent of the software parameters.


# Load a stable position from a config entry
def load_config_stable(config, option):
return config.getfloatlist(option, count=3)
Expand All @@ -31,6 +32,7 @@ def load_config_stable(config, option):
# How much to prefer a distance measurement over a height measurement
MEASURE_WEIGHT = 0.5


# Convert distance measurements made on the calibration object to
# 3-tuples of (actual_distance, stable_position1, stable_position2)
def measurements_to_distances(measured_params, delta_params):
Expand Down Expand Up @@ -214,6 +216,7 @@ def calculate_params(self, probe_positions, distances):
z_weight = 1.0
if distances:
z_weight = len(distances) / (MEASURE_WEIGHT * len(probe_positions))

# Perform coordinate descent
def delta_errorfunc(params):
try:
Expand Down
1 change: 1 addition & 0 deletions klippy/extras/display/display.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"hd44780_spi": hd44780_spi.hd44780_spi,
}


# Storage of [display_template my_template] config sections
class DisplayTemplate:
def __init__(self, config):
Expand Down
6 changes: 3 additions & 3 deletions klippy/extras/display/menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,9 +311,9 @@ def add_parents(self, parents):
self._parents.append(parents)

def assert_recursive_relation(self, parents=None):
assert self not in (
parents or self._parents
), "Recursive relation of '%s' container" % (self.get_ns(),)
assert self not in (parents or self._parents), (
"Recursive relation of '%s' container" % (self.get_ns(),)
)

def insert_item(self, s, index=None):
self._insert_item(s, index)
Expand Down
6 changes: 3 additions & 3 deletions klippy/extras/exclude_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ def _get_extrusion_offsets(self):
)
if offset is None:
offset = [0.0, 0.0, 0.0, 0.0]
self.extrusion_offsets[
self.toolhead.get_extruder().get_name()
] = offset
self.extrusion_offsets[self.toolhead.get_extruder().get_name()] = (
offset
)
return offset

def get_position(self):
Expand Down
1 change: 0 additions & 1 deletion klippy/extras/firmware_retraction.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ def _get_config_params(self):

# Helper method to register commands and instantiate required objects
def _handle_ready(self):

self.gcode_move = self.printer.lookup_object("gcode_move")
self.toolhead = self.printer.lookup_object("toolhead")

Expand Down
13 changes: 4 additions & 9 deletions klippy/extras/heaters.py
Original file line number Diff line number Diff line change
Expand Up @@ -563,15 +563,10 @@ def load_profile(self, profile_name, gcmd, verbose):
if profile["smooth_time"] is None
else profile["smooth_time"]
)
msg = (
"Target: %.2f\n"
"Tolerance: %.4f\n"
"Control: %s\n"
% (
profile["pid_target"],
profile["pid_tolerance"],
profile["control"],
)
msg = "Target: %.2f\n" "Tolerance: %.4f\n" "Control: %s\n" % (
profile["pid_target"],
profile["pid_tolerance"],
profile["control"],
)
if smooth_time is not None:
msg += "Smooth Time: %.3f\n" % smooth_time
Expand Down
3 changes: 3 additions & 0 deletions klippy/extras/led.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
# Time between each led template update
RENDER_TIME = 0.500


# Helper code for common LED initialization and control
class LEDHelper:
def __init__(self, config, update_func, led_count=1):
Expand Down Expand Up @@ -66,6 +67,7 @@ def cmd_SET_LED(self, gcmd):
transmit = gcmd.get_int("TRANSMIT", 1)
sync = gcmd.get_int("SYNC", 1)
color = (red, green, blue, white)

# Update and transmit data
def lookahead_bgfunc(print_time):
self.set_color(index, color)
Expand Down Expand Up @@ -205,6 +207,7 @@ def cmd_SET_LED_TEMPLATE(self, gcmd):
PIN_MIN_TIME = 0.100
MAX_SCHEDULE_TIME = 5.0


# Handler for PWM controlled LEDs
class PrinterPWMLED:
def __init__(self, config):
Expand Down
1 change: 1 addition & 0 deletions klippy/extras/manual_probe.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ def verify_no_manual_probe(printer):
Z_BOB_MINIMUM = 0.500
BISECT_MAX = 0.200


# Helper script to determine a Z height
class ManualProbeHelper:
def __init__(self, printer, gcmd, finalize_callback):
Expand Down
5 changes: 4 additions & 1 deletion klippy/extras/replicape.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,10 @@ def set_pwm(self, print_time, value):
self._is_enable = is_enable
self._reactor.register_async_callback(
(
lambda e, s=self, pt=print_time, ie=is_enable: s._replicape.note_pwm_enable(
lambda e,
s=self,
pt=print_time,
ie=is_enable: s._replicape.note_pwm_enable(
pt, s._channel, ie
)
)
Expand Down
4 changes: 1 addition & 3 deletions klippy/extras/spi_temperature.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,9 +360,7 @@ def calc_temp(self, adc):
# R_div_nominal = 1. + CVD_A * temp + CVD_B * temp**2
# Solve for temp using quadratic equation:
# temp = (-b +- sqrt(b**2 - 4ac)) / 2a
discriminant = math.sqrt(
CVD_A**2 - 4.0 * CVD_B * (1.0 - R_div_nominal)
)
discriminant = math.sqrt(CVD_A**2 - 4.0 * CVD_B * (1.0 - R_div_nominal))
temp = (-CVD_A + discriminant) / (2.0 * CVD_B)
return temp

Expand Down
1 change: 1 addition & 0 deletions klippy/extras/stepper_enable.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

DISABLE_STALL_TIME = 0.100


# Tracking of shared stepper enable pins
class StepperEnablePin:
def __init__(self, mcu_enable, enable_count):
Expand Down
1 change: 1 addition & 0 deletions klippy/extras/thermistor.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

KELVIN_TO_CELSIUS = -273.15


# Analog voltage to temperature converter for thermistors
class Thermistor:
def __init__(self, pullup, inline_resistor):
Expand Down
6 changes: 2 additions & 4 deletions klippy/extras/tmc2130.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,8 +302,7 @@ def reg_read(self, reg, chain_pos):
params = self.spi.spi_transfer(cmd)
pr = bytearray(params["response"])
pr = pr[
(self.chain_len - chain_pos)
* 5 : (self.chain_len - chain_pos + 1)
(self.chain_len - chain_pos) * 5 : (self.chain_len - chain_pos + 1)
* 5
]
return (pr[1] << 24) | (pr[2] << 16) | (pr[3] << 8) | pr[4]
Expand All @@ -329,8 +328,7 @@ def reg_write(self, reg, val, chain_pos, print_time=None):
)
pr = bytearray(params["response"])
pr = pr[
(self.chain_len - chain_pos)
* 5 : (self.chain_len - chain_pos + 1)
(self.chain_len - chain_pos) * 5 : (self.chain_len - chain_pos + 1)
* 5
]
return (pr[1] << 24) | (pr[2] << 16) | (pr[3] << 8) | pr[4]
Expand Down
2 changes: 2 additions & 0 deletions klippy/extras/tmc_uart.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ def activate(self, instance_id):
# TMC uart communication
######################################################################


# Share mutexes so only one active tmc_uart command on a single mcu at
# a time. This helps limit cpu usage on slower micro-controllers.
class PrinterTMCUartMutexes:
Expand All @@ -85,6 +86,7 @@ def lookup_tmc_uart_mutex(mcu):
TMC_BAUD_RATE = 40000
TMC_BAUD_RATE_AVR = 9000


# Code for sending messages on a TMC uart
class MCU_TMC_uart_bitbang:
def __init__(self, rx_pin_params, tx_pin_params, select_pins_desc):
Expand Down
21 changes: 9 additions & 12 deletions klippy/extras/trad_rack.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@


class TradRack:

VARS_CALIB_BOWDEN_LOAD_LENGTH = "tr_calib_bowden_load_length"
VARS_CALIB_BOWDEN_UNLOAD_LENGTH = "tr_calib_bowden_unload_length"
VARS_CONFIG_BOWDEN_LENGTH = "tr_config_bowden_length"
Expand Down Expand Up @@ -120,11 +119,9 @@ def __init__(self, config):
self.eject_length = config.getfloat(
"eject_length", default=30.0, above=0.0
)
self.config_bowden_length = (
self.bowden_load_length
) = self.bowden_unload_length = config.getfloat(
"bowden_length", above=0.0
)
self.config_bowden_length = self.bowden_load_length = (
self.bowden_unload_length
) = config.getfloat("bowden_length", above=0.0)
self.extruder_load_length = config.getfloat(
"extruder_load_length", above=0.0
)
Expand Down Expand Up @@ -2281,12 +2278,12 @@ def __init__(self, config, buffer_pull_speed, is_extruder_synced):
# Flush tracking
self.flush_timer = self.reactor.register_timer(self._flush_handler)
self.do_kick_flush_timer = True
self.last_flush_time = (
self.last_sg_flush_time
) = self.min_restart_time = 0.0
self.need_flush_time = (
self.step_gen_time
) = self.clear_history_time = 0.0
self.last_flush_time = self.last_sg_flush_time = (
self.min_restart_time
) = 0.0
self.need_flush_time = self.step_gen_time = self.clear_history_time = (
0.0
)
# Kinematic step generation scan window time tracking
self.kin_flush_delay = toolhead.SDS_CHECK_TIME
self.kin_flush_times = []
Expand Down
1 change: 1 addition & 0 deletions klippy/extras/z_tilt.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ def probe_finalize(self, offsets, positions):
z_offset = offsets[2]
logging.info("Calculating bed tilt with: %s", positions)
params = {"x_adjust": 0.0, "y_adjust": 0.0, "z_adjust": z_offset}

# Perform coordinate descent
def adjusted_height(pos, params):
x, y, z = pos
Expand Down
7 changes: 2 additions & 5 deletions klippy/kinematics/delta.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,7 @@ def ratio_to_xy(ratio):
return (
ratio
* math.sqrt(
min_arm_length**2 / (ratio**2 + 1.0)
- half_min_step_dist**2
min_arm_length**2 / (ratio**2 + 1.0) - half_min_step_dist**2
)
+ half_min_step_dist
- radius
Expand Down Expand Up @@ -283,9 +282,7 @@ def get_position_from_stable(self, stable_position):
self.stepdists, self.towers, self.abs_endstops, stable_position
)
]
return mathutil.trilateration(
sphere_coords, [a**2 for a in self.arms]
)
return mathutil.trilateration(sphere_coords, [a**2 for a in self.arms])

def calc_stable_position(self, coord):
# Return a stable_position from a cartesian coordinate
Expand Down
2 changes: 2 additions & 0 deletions klippy/mathutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
# Coordinate descent
######################################################################


# Helper code that implements coordinate descent
def coordinate_descent(adj_params, params, error_func):
# Define potential changes
Expand Down Expand Up @@ -91,6 +92,7 @@ def wrapper():
# Trilateration
######################################################################


# Trilateration finds the intersection of three spheres. See the
# wikipedia article for the details of the algorithm.
def trilateration(sphere_coords, radius2):
Expand Down
12 changes: 3 additions & 9 deletions klippy/mcu.py
Original file line number Diff line number Diff line change
Expand Up @@ -1361,16 +1361,12 @@ def stats(self, eventtime):


Common_MCU_errors = {
(
"Timer too close",
): """
("Timer too close",): """
This often indicates the host computer is overloaded. Check
for other processes consuming excessive CPU time, high swap
usage, disk errors, overheating, unstable voltage, or
similar system problems on the host computer.""",
(
"Missed scheduling of next ",
): """
("Missed scheduling of next ",): """
This is generally indicative of an intermittent
communication failure between micro-controller and host.""",
(
Expand All @@ -1386,9 +1382,7 @@ def stats(self, eventtime):
This generally occurs when the micro-controller has been
requested to step at a rate higher than it is capable of
obtaining.""",
(
"Command request",
): """
("Command request",): """
This generally occurs in response to an M112 G-Code command
or in response to an internal error in the host software.""",
}
Expand Down
1 change: 1 addition & 0 deletions klippy/msgproto.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ def parse(self, s, pos):
"%*s": PT_buffer(),
}


# Lookup the message types for a format string
def lookup_params(msgformat, enumerations={}):
out = []
Expand Down
6 changes: 3 additions & 3 deletions klippy/toolhead.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,9 +296,9 @@ def __init__(self, config):
self.flush_timer = self.reactor.register_timer(self._flush_handler)
self.do_kick_flush_timer = True
self.last_flush_time = self.min_restart_time = 0.0
self.need_flush_time = (
self.step_gen_time
) = self.clear_history_time = 0.0
self.need_flush_time = self.step_gen_time = self.clear_history_time = (
0.0
)
# Kinematic step generation scan window time tracking
self.kin_flush_delay = SDS_CHECK_TIME
self.kin_flush_times = []
Expand Down
Loading

0 comments on commit b7db34e

Please sign in to comment.