]> Repositories - hackapet/Adafruit_Blinka.git/blobdiff - src/adafruit_blinka/microcontroller/fake_mcp2221/pin.py
pylint
[hackapet/Adafruit_Blinka.git] / src / adafruit_blinka / microcontroller / fake_mcp2221 / pin.py
index e2cb40f8972cfd70d0e3d54d676e99e1634bf0ba..f3b6b1fb5e5b17fdc80fcf02b981b4be7c20c265 100644 (file)
@@ -3,7 +3,6 @@
 # SPDX-License-Identifier: MIT
 """fake_mcp2221 pin names"""
 import random
-from .fake_mcp2221 import mcp2221
 
 
 class Pin:
@@ -21,28 +20,25 @@ class Pin:
     def __init__(self, pin_id=None):
         self.id = pin_id
         self._mode = None
-        self._prv_val = None
+        self._prv_val = False
 
     def init(self, mode=IN, pull=None):
         """Initialize the Pin"""
         if self.id is None:
             raise RuntimeError("Can not init a None type pin.")
         if pull is not None:
-            raise NotImplementedError("Internal pullups and pulldowns not supported on the MCP2221")
-        if mode in (Pin.IN, Pin.OUT):
-            # All pins can do GPIO
-            pass
-        elif mode == Pin.ADC:
+            raise NotImplementedError(
+                "Internal pullups and pulldowns not supported on the MCP2221"
+            )
+        if mode == Pin.ADC:
             # ADC only available on these pins
             if self.id not in (1, 2, 3):
                 raise ValueError("Pin does not have ADC capabilities")
-            pass
             # Do nothing
         elif mode == Pin.DAC:
             # DAC only available on these pins
             if self.id not in (2, 3):
                 raise ValueError("Pin does not have DAC capabilities")
-            pass
         else:
             raise ValueError("Incorrect pin mode: {}".format(mode))
         self._mode = mode
@@ -53,13 +49,8 @@ class Pin:
         if self._mode in (Pin.IN, Pin.OUT):
             # digital read
             if val is None:
-                # The value returned will toggle between True and False
-                # and will be True on the first digital read
-                # TODO: Behavior needs to be tested
-                if self._prv_val == None or False:
-                    self._prv_val = True
-                else:
-                    self._prv_val = False
+                # The returned value toggles between True and false
+                self._prv_val = not self._prv_val
                 return self._prv_val
             # digital write
             if val in (Pin.LOW, Pin.HIGH):
@@ -95,4 +86,4 @@ G2 = Pin(2)
 G3 = Pin(3)
 
 SCL = Pin()
-SDA = Pin()
\ No newline at end of file
+SDA = Pin()