]> Repositories - hackapet/Adafruit_Blinka.git/blobdiff - python/digitalio/__init__.py
Top level package now defines only uart and spi ports. pin submodule handles pins
[hackapet/Adafruit_Blinka.git] / python / digitalio / __init__.py
index 3905e0245c61b66678fa898a41e278a580dc768b..db8a1a4637beddecbaa00ea543197ab9985ece3e 100644 (file)
@@ -1,6 +1,6 @@
 from machine import Pin
 from agnostic import board as boardId
-from mcp import Enum
+from mcp import Enum,ContextManaged
 
 
 class DriveMode(Enum):
@@ -26,7 +26,7 @@ Pull.DOWN = Pull()
 #Pull.NONE = Pull()
 
 
-class DigitalInOut(object):
+class DigitalInOut(ContextManaged):
     _pin = None
 
     def __init__(self, pin):
@@ -45,12 +45,6 @@ class DigitalInOut(object):
     def deinit(self):
         del self._pin
 
-    def __enter__(self):
-        return self
-
-    def __exit__(self, exc_type, exc_value, traceback):
-        self.deinit()
-
     @property
     def direction(self):
         return self.__direction
@@ -70,12 +64,12 @@ class DigitalInOut(object):
 
     @property
     def value(self):
-        return self._pin.value()
+        return self._pin.value() is 1
 
     @value.setter
     def value(self, val):
         if self.direction is Direction.OUTPUT:
-            self._pin.value(val)
+            self._pin.value(1 if val else 0)
         else:
             raise AttributeError("Not an output")