mcu: Rename add_config_object() to register_config_callback()

Change the name of the config registration method and pass an explicit
reference to the callback to the new method.  This makes the
relationship between mcu registration and build_config() more clear in
the calling code.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2018-09-03 11:48:22 -04:00
parent a8d4a7ef46
commit 30013a1fb8
10 changed files with 29 additions and 26 deletions

View file

@ -46,7 +46,7 @@ class MCU_buttons:
def __init__(self, printer, mcu):
self.reactor = printer.get_reactor()
self.mcu = mcu
mcu.add_config_object(self)
self.mcu.register_config_callback(self.build_config)
self.pin_list = []
self.callbacks = []
self.invert = self.last_button = 0

View file

@ -33,7 +33,7 @@ class HD44780:
self.pins = [pin_params['pin'] for pin_params in pins]
self.mcu = mcu
self.oid = self.mcu.create_oid()
self.mcu.add_config_object(self)
self.mcu.register_config_callback(self.build_config)
self.send_data_cmd = self.send_cmds_cmd = None
# framebuffers
self.text_framebuffer = (bytearray(' '*80), bytearray('~'*80), 0x80)

View file

@ -27,7 +27,7 @@ class ST7920:
self.pins = [pin_params['pin'] for pin_params in pins]
self.mcu = mcu
self.oid = self.mcu.create_oid()
self.mcu.add_config_object(self)
self.mcu.register_config_callback(self.build_config)
self.send_data_cmd = self.send_cmds_cmd = None
self.is_extended = False
# framebuffers

View file

@ -28,7 +28,7 @@ class UC1701:
self.mcu = mcu
self.spi_oid = self.mcu.create_oid()
self.a0_oid = self.mcu.create_oid()
self.mcu.add_config_object(self)
self.mcu.register_config_callback(self.build_config)
self.glyph_buffer = []
self.spi_xfer_cmd = self.set_pin_cmd = None
self.vram = ([bytearray(128) for i in range(8)],

View file

@ -31,7 +31,7 @@ class PrinterProbe:
pin = config.get('pin')
pin_params = ppins.lookup_pin(pin, can_invert=True, can_pullup=True)
mcu = pin_params['chip']
mcu.add_config_object(self)
mcu.register_config_callback(self.build_config)
self.mcu_probe = mcu.setup_pin('endstop', pin_params)
if (config.get('activate_gcode', None) is not None or
config.get('deactivate_gcode', None) is not None):

View file

@ -20,7 +20,7 @@ class pca9685_pwm:
if pin_type not in ['digital_out', 'pwm']:
raise pins.error("Pin type not supported on replicape")
self._mcu = replicape.host_mcu
self._mcu.add_config_object(self)
self._mcu.register_config_callback(self._build_config)
self._bus = REPLICAPE_PCA9685_BUS
self._address = REPLICAPE_PCA9685_ADDRESS
self._cycle_time = REPLICAPE_PCA9685_CYCLE_TIME
@ -53,7 +53,7 @@ class pca9685_pwm:
self._is_static = is_static
self._replicape.note_pwm_start_value(
self._channel, self._start_value, self._shutdown_value)
def build_config(self):
def _build_config(self):
self._pwm_max = self._mcu.get_constant_float("PCA9685_MAX")
cycle_ticks = self._mcu.seconds_to_clock(self._cycle_time)
if self._is_static:
@ -175,7 +175,7 @@ class Replicape:
and self.stepper_dacs):
shift_registers[4] &= ~1
self.sr_enabled = tuple(reversed(shift_registers))
self.host_mcu.add_config_object(self)
self.host_mcu.register_config_callback(self._build_config)
self.sr_oid = self.host_mcu.create_oid()
str_sr_disabled = "".join(["%02x" % (x,) for x in self.sr_disabled])
self.host_mcu.add_config_cmd(
@ -184,7 +184,7 @@ class Replicape:
self.sr_oid, REPLICAPE_SHIFT_REGISTER_BUS, str_sr_disabled))
self.host_mcu.add_config_cmd("spi_send oid=%d data=%s" % (
self.sr_oid, str_sr_disabled), is_init=True)
def build_config(self):
def _build_config(self):
cmd_queue = self.host_mcu.alloc_command_queue()
self.spi_send_cmd = self.host_mcu.lookup_command(
"spi_send oid=%c data=%*s", cq=cmd_queue)

View file

@ -46,7 +46,7 @@ class SensorBase:
oid, spi_oid, chip_type))
mcu.register_msg(self._handle_spi_response,
"thermocouple_result", oid)
mcu.add_config_object(self)
mcu.register_config_callback(self._build_config)
def setup_minmax(self, min_temp, max_temp):
adc_range = [self.calc_adc(min_temp), self.calc_adc(max_temp)]
self.min_sample_value = min(adc_range)
@ -55,7 +55,7 @@ class SensorBase:
self._callback = cb
def get_report_time_delta(self):
return REPORT_TIME
def build_config(self):
def _build_config(self):
clock = self.mcu.get_query_slot(self.oid)
self._report_clock = self.mcu.seconds_to_clock(REPORT_TIME)
self.mcu.add_config_cmd(

View file

@ -38,7 +38,7 @@ class TMC2130:
"config_spi oid=%d bus=%d pin=%s mode=%d rate=%d shutdown_msg=" % (
self.oid, 0, cs_pin_params['pin'], 3, 4000000))
self.spi_send_cmd = self.spi_transfer_cmd = None
self.mcu.add_config_object(self)
self.mcu.register_config_callback(self.build_config)
# Allow virtual endstop to be created
self.diag1_pin = config.get('diag1_pin', None)
ppins.register_chip("tmc2130_" + self.name, self)

View file

@ -112,7 +112,7 @@ class TMC2208:
self.tx_pin = tx_pin_params['pin']
self.oid = self.mcu.create_oid()
self.tmcuart_send_cmd = None
self.mcu.add_config_object(self)
self.mcu.register_config_callback(self.build_config)
# Add DUMP_TMC command
gcode = self.printer.lookup_object("gcode")
gcode.register_mux_command(