Skip to content

Commit

Permalink
oopsies
Browse files Browse the repository at this point in the history
  • Loading branch information
bwnance committed Feb 2, 2024
1 parent cca74f9 commit 8b9e9a7
Showing 2 changed files with 26 additions and 16 deletions.
20 changes: 12 additions & 8 deletions klippy/extras/angle.py
Original file line number Diff line number Diff line change
@@ -500,6 +500,7 @@ def __init__(self, config):
}
sensor_type = config.getchoice("sensor_type", {s: s for s in sensors})
sensor_class = sensors[sensor_type]
self.sensor_type = sensor_type
self.spi = bus.MCU_SPI_from_config(
config, sensor_class.SPI_MODE, default_speed=sensor_class.SPI_SPEED
)
@@ -508,14 +509,7 @@ def __init__(self, config):
self.sensor_helper = sensor_class(config, self.spi, oid)
# Setup mcu sensor_spi_angle bulk query code
self.query_spi_angle_cmd = self.query_spi_angle_end_cmd = None
mcu.add_config_cmd(
"config_spi_angle oid=%d spi_oid=%d spi_angle_type=%s"
% (oid, self.spi.get_oid(), sensor_type)
)
mcu.add_config_cmd(
"query_spi_angle oid=%d clock=0 rest_ticks=0 time_shift=0" % (oid,),
on_restart=True,
)

mcu.register_config_callback(self._build_config)
mcu.register_response(
self._handle_spi_angle_data, "spi_angle_data", oid
@@ -531,6 +525,16 @@ def __init__(self, config):
)

def _build_config(self):
self.mcu.add_config_cmd(
"config_spi_angle oid=%d spi_oid=%d spi_angle_type=%s"
% (self.oid, self.spi.get_oid(), self.sensor_type)
)
self.mcu.add_config_cmd(
"query_spi_angle oid=%d clock=0 rest_ticks=0 time_shift=0"
% (self.oid,),
on_restart=True,
)

freq = self.mcu.seconds_to_clock(1.0)
while float(TCODE_ERROR << self.time_shift) / freq < 0.002:
self.time_shift += 1
22 changes: 14 additions & 8 deletions klippy/extras/bus.py
Original file line number Diff line number Diff line change
@@ -85,9 +85,11 @@ def get_command_queue(self):

def build_config(self):
if self.pin is None:
mcu.add_config_cmd("config_spi_without_cs oid=%d" % (self.oid,))
self.mcu.add_config_cmd(
"config_spi_without_cs oid=%d" % (self.oid,)
)
else:
mcu.add_config_cmd(
self.mcu.add_config_cmd(
"config_spi oid=%d pin=%s cs_active_high=%d"
% (self.oid, self.pin, self.cs_active_high)
)
@@ -188,7 +190,7 @@ def __init__(self, mcu, bus, addr, speed, sw_pins=None):
self.bus = bus
self.i2c_address = addr
self.oid = self.mcu.create_oid()
mcu.add_config_cmd("config_i2c oid=%d" % (self.oid,))

# Generate I2C bus config message
if sw_pins is not None:
self.config_fmt = (
@@ -218,6 +220,7 @@ def get_command_queue(self):
return self.cmd_queue

def build_config(self):
self.mcu.add_config_cmd("config_i2c oid=%d" % (self.oid,))
if "%" in self.config_fmt:
bus = resolve_bus_name(self.mcu, "i2c_bus", self.bus)
self.config_fmt = self.config_fmt % (bus,)
@@ -310,15 +313,13 @@ def __init__(self, mcu, pin_desc, cmd_queue=None, value=0):
self.oid = mcu.create_oid()
ppins = mcu.get_printer().lookup_object("pins")
pin_params = ppins.lookup_pin(pin_desc)
self.pin_params = pin_params
self.value = value
if pin_params["chip"] is not mcu:
raise ppins.error(
"Pin %s must be on mcu %s" % (pin_desc, mcu.get_name())
)
mcu.add_config_cmd(
"config_digital_out oid=%d pin=%s value=%d"
" default_value=%d max_duration=%d"
% (self.oid, pin_params["pin"], value, value, 0)
)

mcu.register_config_callback(self.build_config)
if cmd_queue is None:
cmd_queue = mcu.alloc_command_queue()
@@ -335,6 +336,11 @@ def get_command_queue(self):
return self.cmd_queue

def build_config(self):
self.mcu.add_config_cmd(
"config_digital_out oid=%d pin=%s value=%d"
" default_value=%d max_duration=%d"
% (self.oid, self.pin_params["pin"], self.value, self.value, 0)
)
self.update_pin_cmd = self.mcu.lookup_command(
"update_digital_out oid=%c value=%c", cq=self.cmd_queue
)

0 comments on commit 8b9e9a7

Please sign in to comment.