class DriveMode(Enum):
+ """Drive Mode Enumeration"""
+
PUSH_PULL = None
OPEN_DRAIN = None
class Direction(Enum):
+ """Direction Enumeration"""
+
INPUT = None
OUTPUT = None
class Pull(Enum):
+ """PullUp/PullDown Enumeration"""
+
UP = None
DOWN = None
# NONE=None
class DigitalInOut(ContextManaged):
+ """DigitalInOut CircuitPython compatibility implementation"""
+
_pin = None
def __init__(self, pin):
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:
@property
def value(self):
+ """Get or Set the Digital Pin Value"""
return self._pin.value() == 1
@value.setter
@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):
@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):