pins: Explicitly pass can_invert and can_pullup to lookup_pin()

Don't pass pin_type to lookup_pin() - instead, if a pin can be
inverted or can have a pullup, then the caller must explicitly specify
that when calling lookup_pin().  This simplifies the code for the
cases where it is not valid to invert or pullup.

Explicitly pass the pin_type to setup_pin() and have ppins.setup_pin()
apply default pullup and invert flags.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2018-07-26 09:44:45 -04:00
parent 7a9553b38a
commit 273a98d39a
13 changed files with 39 additions and 50 deletions

View file

@ -15,21 +15,21 @@ class PrinterMultiPin:
self.pin_type = None
self.pin_list = [pin.strip() for pin in config.get('pins').split(',')]
self.mcu_pins = []
def setup_pin(self, pin_params):
def setup_pin(self, pin_type, pin_params):
ppins = self.printer.lookup_object('pins')
pin_name = pin_params['pin']
pin = self.printer.lookup_object('multi_pin ' + pin_name, None)
if pin is not self:
if pin is None:
raise ppins.error("multi_pin %s not configured" % (pin_name,))
return pin.setup_pin(pin_params)
return pin.setup_pin(pin_type, pin_params)
if self.pin_type is not None:
raise ppins.error("Can't setup multi_pin %s twice" % (pin_name,))
self.pin_type = pin_params['type']
self.pin_type = pin_type
invert = ""
if pin_params['invert']:
invert = "!"
self.mcu_pins = [ppins.setup_pin(self.pin_type, invert + pin_desc)
self.mcu_pins = [ppins.setup_pin(pin_type, invert + pin_desc)
for pin_desc in self.pin_list]
return self
def get_mcu(self):