stepper: Simplify PrinterRail init
Use add_extra_stepper() during class init. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
0e30b862c7
commit
0204de46a6
|
@ -74,17 +74,13 @@ class PrinterStepper:
|
||||||
class PrinterRail:
|
class PrinterRail:
|
||||||
def __init__(self, config, need_position_minmax=True,
|
def __init__(self, config, need_position_minmax=True,
|
||||||
default_position_endstop=None):
|
default_position_endstop=None):
|
||||||
# Primary stepper
|
# Primary stepper and endstop
|
||||||
stepper = PrinterStepper(config)
|
self.steppers = []
|
||||||
self.steppers = [stepper]
|
self.endstops = []
|
||||||
self.name = stepper.get_name(short=True)
|
self.add_extra_stepper(config)
|
||||||
self.get_commanded_position = stepper.get_commanded_position
|
self.get_commanded_position = self.steppers[0].get_commanded_position
|
||||||
# Primary endstop and its position
|
# Primary endstop position
|
||||||
printer = config.get_printer()
|
mcu_endstop = self.endstops[0][0]
|
||||||
ppins = printer.lookup_object('pins')
|
|
||||||
mcu_endstop = ppins.setup_pin('endstop', config.get('endstop_pin'))
|
|
||||||
self.endstops = [(mcu_endstop, self.name)]
|
|
||||||
stepper.add_to_endstop(mcu_endstop)
|
|
||||||
if hasattr(mcu_endstop, "get_position_endstop"):
|
if hasattr(mcu_endstop, "get_position_endstop"):
|
||||||
self.position_endstop = mcu_endstop.get_position_endstop()
|
self.position_endstop = mcu_endstop.get_position_endstop()
|
||||||
elif default_position_endstop is None:
|
elif default_position_endstop is None:
|
||||||
|
@ -92,8 +88,6 @@ class PrinterRail:
|
||||||
else:
|
else:
|
||||||
self.position_endstop = config.getfloat(
|
self.position_endstop = config.getfloat(
|
||||||
'position_endstop', default_position_endstop)
|
'position_endstop', default_position_endstop)
|
||||||
query_endstops = printer.try_load_module(config, 'query_endstops')
|
|
||||||
query_endstops.register_endstop(mcu_endstop, self.name)
|
|
||||||
# Axis range
|
# Axis range
|
||||||
if need_position_minmax:
|
if need_position_minmax:
|
||||||
self.position_min = config.getfloat('position_min', 0.)
|
self.position_min = config.getfloat('position_min', 0.)
|
||||||
|
@ -142,17 +136,18 @@ class PrinterRail:
|
||||||
def add_extra_stepper(self, config):
|
def add_extra_stepper(self, config):
|
||||||
stepper = PrinterStepper(config)
|
stepper = PrinterStepper(config)
|
||||||
self.steppers.append(stepper)
|
self.steppers.append(stepper)
|
||||||
mcu_endstop = self.endstops[0][0]
|
if self.endstops and config.get('endstop_pin', None) is None:
|
||||||
endstop_pin = config.get('endstop_pin', None)
|
# No endstop defined - use primary endstop
|
||||||
if endstop_pin is not None:
|
stepper.add_to_endstop(self.endstops[0][0])
|
||||||
|
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', endstop_pin)
|
mcu_endstop = ppins.setup_pin('endstop', config.get('endstop_pin'))
|
||||||
|
stepper.add_to_endstop(mcu_endstop)
|
||||||
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.try_load_module(config, 'query_endstops')
|
query_endstops = printer.try_load_module(config, 'query_endstops')
|
||||||
query_endstops.register_endstop(mcu_endstop, name)
|
query_endstops.register_endstop(mcu_endstop, name)
|
||||||
stepper.add_to_endstop(mcu_endstop)
|
|
||||||
def add_to_endstop(self, mcu_endstop):
|
def add_to_endstop(self, mcu_endstop):
|
||||||
for stepper in self.steppers:
|
for stepper in self.steppers:
|
||||||
stepper.add_to_endstop(mcu_endstop)
|
stepper.add_to_endstop(mcu_endstop)
|
||||||
|
|
Loading…
Reference in New Issue