X-Git-Url: https://git.ayoreis.com/hackapet/Adafruit_Blinka.git/blobdiff_plain/8072ee88e2c51c62815934066dbd6de838fc913c..18bc57adc610625742d7be9bc3422d02615d6d4f:/src/digitalio.py diff --git a/src/digitalio.py b/src/digitalio.py index 8634e41..4b0036b 100755 --- a/src/digitalio.py +++ b/src/digitalio.py @@ -61,6 +61,8 @@ from adafruit_blinka import Enum, ContextManaged class DriveMode(Enum): + """Drive Mode Enumeration""" + PUSH_PULL = None OPEN_DRAIN = None @@ -70,6 +72,8 @@ DriveMode.OPEN_DRAIN = DriveMode() class Direction(Enum): + """Direction Enumeration""" + INPUT = None OUTPUT = None @@ -79,6 +83,8 @@ Direction.OUTPUT = Direction() class Pull(Enum): + """PullUp/PullDown Enumeration""" + UP = None DOWN = None # NONE=None @@ -91,6 +97,8 @@ Pull.DOWN = Pull() class DigitalInOut(ContextManaged): + """DigitalInOut CircuitPython compatibility implementation""" + _pin = None def __init__(self, pin): @@ -98,29 +106,33 @@ class DigitalInOut(ContextManaged): self.direction = Direction.INPUT def switch_to_output(self, value=False, drive_mode=DriveMode.PUSH_PULL): + """Switch the Digital Pin Mode to Output""" self.direction = Direction.OUTPUT self.value = value self.drive_mode = drive_mode def switch_to_input(self, pull=None): + """Switch the Digital Pin Mode to Input""" self.direction = Direction.INPUT self.pull = pull def deinit(self): + """Deinitialize the Digital Pin""" del self._pin @property def direction(self): + """Get or Set the Digital Pin Direction""" return self.__direction @direction.setter - def direction(self, dir): - self.__direction = dir - if dir is Direction.OUTPUT: + def direction(self, value): + self.__direction = value + if value is Direction.OUTPUT: self._pin.init(mode=Pin.OUT) self.value = False self.drive_mode = DriveMode.PUSH_PULL - elif dir is Direction.INPUT: + elif value is Direction.INPUT: self._pin.init(mode=Pin.IN) self.pull = None else: @@ -128,6 +140,7 @@ class DigitalInOut(ContextManaged): @property def value(self): + """Get or Set the Digital Pin Value""" return self._pin.value() == 1 @value.setter @@ -139,10 +152,10 @@ class DigitalInOut(ContextManaged): @property def pull(self): + """Get or Set the Digital Pin Direction""" if self.direction is Direction.INPUT: return self.__pull - else: - raise AttributeError("Not an input") + raise AttributeError("Not an input") @pull.setter def pull(self, pul): @@ -166,10 +179,10 @@ class DigitalInOut(ContextManaged): @property def drive_mode(self): + """Get or Set the Digital Pin Drive Mode""" if self.direction is Direction.OUTPUT: return self.__drive_mode # - else: - raise AttributeError("Not an output") + raise AttributeError("Not an output") @drive_mode.setter def drive_mode(self, mod):