stepper: detect duplicate endstops

When adding steppers to a `PrinterRail`, detect duplicated `endstop_pin`
settings and add them to the already-registered endstop.

Signed-off-by: Lasse Dalegaard <dalegaard@gmail.com>
This commit is contained in:
Lasse Dalegaard 2021-08-24 17:07:58 +02:00 committed by KevinOConnor
parent 9014677cbd
commit caec91b149
1 changed files with 26 additions and 6 deletions

View File

@ -264,6 +264,7 @@ class PrinterRail:
self.stepper_units_in_radians = units_in_radians self.stepper_units_in_radians = units_in_radians
self.steppers = [] self.steppers = []
self.endstops = [] self.endstops = []
self.endstop_map = {}
self.add_extra_stepper(config) self.add_extra_stepper(config)
mcu_stepper = self.steppers[0] mcu_stepper = self.steppers[0]
self.get_name = mcu_stepper.get_name self.get_name = mcu_stepper.get_name
@ -336,18 +337,37 @@ class PrinterRail:
def add_extra_stepper(self, config): def add_extra_stepper(self, config):
stepper = PrinterStepper(config, self.stepper_units_in_radians) stepper = PrinterStepper(config, self.stepper_units_in_radians)
self.steppers.append(stepper) self.steppers.append(stepper)
if self.endstops and config.get('endstop_pin', None) is None: endstop_pin = config.get('endstop_pin', None)
if self.endstops and endstop_pin is None:
# No endstop defined - use primary endstop # No endstop defined - use primary endstop
self.endstops[0][0].add_stepper(stepper) self.endstops[0][0].add_stepper(stepper)
return return
printer = config.get_printer() printer = config.get_printer()
ppins = printer.lookup_object('pins') ppins = printer.lookup_object('pins')
mcu_endstop = ppins.setup_pin('endstop', config.get('endstop_pin')) pin_params = ppins.parse_pin(endstop_pin, True, True)
mcu_endstop.add_stepper(stepper) # Normalize pin name
pin_name = "%s:%s" % (pin_params['chip_name'], pin_params['pin'])
# Look for already-registered endstop
endstop = self.endstop_map.get(pin_name, None)
if endstop is None:
# New endstop, register it
mcu_endstop = ppins.setup_pin('endstop', endstop_pin)
self.endstop_map[pin_name] = {'endstop': mcu_endstop,
'invert': pin_params['invert'],
'pullup': pin_params['pullup']}
name = stepper.get_name(short=True) name = stepper.get_name(short=True)
self.endstops.append((mcu_endstop, name)) self.endstops.append((mcu_endstop, name))
query_endstops = printer.load_object(config, 'query_endstops') query_endstops = printer.load_object(config, 'query_endstops')
query_endstops.register_endstop(mcu_endstop, name) query_endstops.register_endstop(mcu_endstop, name)
else:
mcu_endstop = endstop['endstop']
changed_invert = pin_params['invert'] != endstop['invert']
changed_pullup = pin_params['pullup'] != endstop['pullup']
if changed_invert or changed_pullup:
raise error("Pinter rail %s shared endstop pin %s "
"must specify the same pullup/invert settings" % (
self.get_name(), pin_name))
mcu_endstop.add_stepper(stepper)
def setup_itersolve(self, alloc_func, *params): def setup_itersolve(self, alloc_func, *params):
for stepper in self.steppers: for stepper in self.steppers:
stepper.setup_itersolve(alloc_func, *params) stepper.setup_itersolve(alloc_func, *params)