X-Git-Url: https://git.ayoreis.com/hackapet/Adafruit_Blinka.git/blobdiff_plain/b76e7eb3aca5c7b91f9026a37b46e7ca50c3a350..5732569ec91a27d3708270e2078b466488d76457:/src/adafruit_blinka/__init__.py?ds=sidebyside diff --git a/src/adafruit_blinka/__init__.py b/src/adafruit_blinka/__init__.py old mode 100644 new mode 100755 index dfcef6c..47622df --- a/src/adafruit_blinka/__init__.py +++ b/src/adafruit_blinka/__init__.py @@ -1,7 +1,11 @@ -"""Module providing runtime utility objects to support the Micro/CircuitPython api""" +""" +`adafruit_blinka` - Runtime utility objects for re-implementation of CircuitPython API +====================================================================================== +* Author(s): cefn +""" -class Enum(object): +class Enum(): """ Object supporting CircuitPython-style of static symbols as seen with Direction.OUTPUT, Pull.UP @@ -27,35 +31,45 @@ class Enum(object): """ for key in dir(cls): val = getattr(cls, key) - if type(val) is cls: + if isinstance(cls, val): yield (key, val) class ContextManaged: + """An object that automatically deinitializes hardware with a context manager.""" def __enter__(self): return self def __exit__(self, exc_type, exc_value, traceback): self.deinit() + # pylint: disable=no-self-use + def deinit(self): + """Free any hardware used by the object.""" + return + # pylint: enable=no-self-use + class Lockable(ContextManaged): + """An object that must be locked to prevent collisions on a microcontroller resource.""" _locked = False def try_lock(self): + """Attempt to grab the lock. Return True on success, False if the lock is already taken.""" if self._locked: return False - else: - self._locked = True - return True + self._locked = True + return True def unlock(self): + """Release the lock so others may use the resource.""" if self._locked: self._locked = False else: raise ValueError("Not locked") def patch_system(): + """Patch modules that may be different due to the platform.""" import sys - from adafruit_blinka import time - sys.modules['time'] = time \ No newline at end of file + from adafruit_blinka.agnostic import time + sys.modules['time'] = time