mirror of https://github.com/Desuuuu/klipper.git
pins: Rename parse_pin_desc() to lookup_pin()
Always set the pin_params['type'] field on a pin lookup. Rename parse_pin_desc() to lookup_pin() to make the change more clear. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
a6025686b6
commit
265b9097d5
|
@ -186,8 +186,8 @@ class PrinterServo:
|
||||||
|
|
||||||
class ad5206:
|
class ad5206:
|
||||||
def __init__(self, printer, config):
|
def __init__(self, printer, config):
|
||||||
enable_pin_params = pins.get_printer_pins(printer).parse_pin_desc(
|
enable_pin_params = pins.get_printer_pins(printer).lookup_pin(
|
||||||
config.get('enable_pin'))
|
'digital_out', config.get('enable_pin'))
|
||||||
self.mcu = enable_pin_params['chip']
|
self.mcu = enable_pin_params['chip']
|
||||||
self.pin = enable_pin_params['pin']
|
self.pin = enable_pin_params['pin']
|
||||||
self.mcu.add_config_object(self)
|
self.mcu.add_config_object(self)
|
||||||
|
|
|
@ -180,7 +180,9 @@ class PrinterPins:
|
||||||
error = error
|
error = error
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.chips = {}
|
self.chips = {}
|
||||||
def parse_pin_desc(self, pin_desc, can_invert=False, can_pullup=False):
|
def lookup_pin(self, pin_type, pin_desc):
|
||||||
|
can_invert = pin_type in ['stepper', 'endstop', 'digital_out', 'pwm']
|
||||||
|
can_pullup = pin_type == 'endstop'
|
||||||
pullup = invert = 0
|
pullup = invert = 0
|
||||||
if can_pullup and pin_desc.startswith('^'):
|
if can_pullup and pin_desc.startswith('^'):
|
||||||
pullup = 1
|
pullup = 1
|
||||||
|
@ -194,8 +196,11 @@ class PrinterPins:
|
||||||
chip_name, pin = [s.strip() for s in pin_desc.split(':', 1)]
|
chip_name, pin = [s.strip() for s in pin_desc.split(':', 1)]
|
||||||
if chip_name not in self.chips:
|
if chip_name not in self.chips:
|
||||||
raise error("Unknown pin chip name '%s'" % (chip_name,))
|
raise error("Unknown pin chip name '%s'" % (chip_name,))
|
||||||
return {'chip': self.chips[chip_name], 'pin': pin,
|
return {'chip': self.chips[chip_name], 'chip_name': chip_name,
|
||||||
'invert': invert, 'pullup': pullup}
|
'type': pin_type, 'pin': pin, 'invert': invert, 'pullup': pullup}
|
||||||
|
def setup_pin(self, pin_type, pin_desc):
|
||||||
|
pin_params = self.lookup_pin(pin_type, pin_desc)
|
||||||
|
return pin_params['chip'].setup_pin(pin_params)
|
||||||
def register_chip(self, chip_name, chip):
|
def register_chip(self, chip_name, chip):
|
||||||
chip_name = chip_name.strip()
|
chip_name = chip_name.strip()
|
||||||
if chip_name in self.chips:
|
if chip_name in self.chips:
|
||||||
|
@ -209,9 +214,4 @@ def get_printer_pins(printer):
|
||||||
return printer.objects['pins']
|
return printer.objects['pins']
|
||||||
|
|
||||||
def setup_pin(printer, pin_type, pin_desc):
|
def setup_pin(printer, pin_type, pin_desc):
|
||||||
ppins = get_printer_pins(printer)
|
return get_printer_pins(printer).setup_pin(pin_type, pin_desc)
|
||||||
can_invert = pin_type in ['stepper', 'endstop', 'digital_out', 'pwm']
|
|
||||||
can_pullup = pin_type == 'endstop'
|
|
||||||
pin_params = ppins.parse_pin_desc(pin_desc, can_invert, can_pullup)
|
|
||||||
pin_params['type'] = pin_type
|
|
||||||
return pin_params['chip'].setup_pin(pin_params)
|
|
||||||
|
|
|
@ -16,8 +16,8 @@ class PrinterStepper:
|
||||||
# Stepper definition
|
# Stepper definition
|
||||||
self.mcu_stepper = pins.setup_pin(
|
self.mcu_stepper = pins.setup_pin(
|
||||||
printer, 'stepper', config.get('step_pin'))
|
printer, 'stepper', config.get('step_pin'))
|
||||||
dir_pin_params = pins.get_printer_pins(printer).parse_pin_desc(
|
dir_pin_params = pins.get_printer_pins(printer).lookup_pin(
|
||||||
config.get('dir_pin'), can_invert=True)
|
'digital_out', config.get('dir_pin'))
|
||||||
self.mcu_stepper.setup_dir_pin(dir_pin_params)
|
self.mcu_stepper.setup_dir_pin(dir_pin_params)
|
||||||
self.step_dist = config.getfloat('step_distance', above=0.)
|
self.step_dist = config.getfloat('step_distance', above=0.)
|
||||||
self.mcu_stepper.setup_step_distance(self.step_dist)
|
self.mcu_stepper.setup_step_distance(self.step_dist)
|
||||||
|
|
Loading…
Reference in New Issue