clarify usbio.py function docs
authorDan White <dan@whiteaudio.com>
Tue, 10 Jul 2012 18:10:17 +0000 (13:10 -0500)
committerDan White <dan@whiteaudio.com>
Tue, 10 Jul 2012 18:10:17 +0000 (13:10 -0500)
python-lib/usbio.py

index f632969a736774f2146041ca55d8c002b8aece3e..98517ee27df31b6c54227e45b4af84ddbf8b1985 100644 (file)
@@ -43,6 +43,19 @@ def log2(x):
     return log(x) / log(2)
 
 def truth(v):
+    """Returns a truth value of the given value.
+
+    Allows patterns like: truth(~False) == True
+    the pythonic way is: True is not False
+    while: "True == ~False" returns False an NOT expected"
+
+    in python:
+        ~True == int(-2)
+        ~False == int(-1)
+
+    This returns v if v is a bool, returns False if v is an int and is one of
+    [0, -2], True of bool(v) is True, and False otherwise.
+    """
     if isinstance(v, (int, intbv)):
         # NB: ~True == -2
         #     ~False == -1
@@ -72,7 +85,8 @@ class I2C(object):
     def __init__(self, interface=ftdi.INTERFACE_A, scl=0, sda=1,
                     vid=0x0403, pid=0x6011, delay=0.001, timeout=100,
                     pindir=0xc0, pinstate=0xc0):
-        """Bitbanged I2C for use on FT4232H ports C and D.
+        """Bitbanged I2C for use on FT4232H ports C and D.  Uses the libftdi
+        python bindings.
 
         interface = [0,1,2,3]
         scl/sda = port pin numbers