From: Dan White Date: Tue, 10 Jul 2012 18:10:17 +0000 (-0500) Subject: clarify usbio.py function docs X-Git-Tag: calibrations~34 X-Git-Url: http://git.whiteaudio.com/gitweb/?a=commitdiff_plain;h=9b5a3a729d1b46ef52413682100bb660e234d979;p=430.git clarify usbio.py function docs --- diff --git a/python-lib/usbio.py b/python-lib/usbio.py index f632969..98517ee 100644 --- a/python-lib/usbio.py +++ b/python-lib/usbio.py @@ -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