diff --git a/.gitignore b/.gitignore index dfae8c4..0ff8cfc 100644 --- a/.gitignore +++ b/.gitignore @@ -32,3 +32,7 @@ distribute-*.tar.gz # idea .idea/ + + +.* +!.gitignore diff --git a/quick2wire/i2c.py b/quick2wire/i2c.py index 0b6b9fe..1322beb 100644 --- a/quick2wire/i2c.py +++ b/quick2wire/i2c.py @@ -7,7 +7,7 @@ from ctypes import create_string_buffer, sizeof, c_int, byref, pointer, addressof, string_at from quick2wire.board_revision import revision -assert sys.version_info.major >= 3, __name__ + " is only supported on Python 3" +#assert sys.version_info.major >= 3, __name__ + " is only supported on Python 3" default_bus = 1 if revision() > 1 else 0 diff --git a/quick2wire/parts/pcf8591.py b/quick2wire/parts/pcf8591.py index 63f67fe..21e0d16 100644 --- a/quick2wire/parts/pcf8591.py +++ b/quick2wire/parts/pcf8591.py @@ -88,6 +88,14 @@ _ANALOGUE_OUTPUT_ENABLE_FLAG = 1 << 6 +def to_byte(x): + """convert to byte, input can be string or int, + for support both py2 and py3""" + try: + return ord(x) + except TypeError: + return x + class PCF8591(object): """API to query and control an PCF8591 A/D and D/A converter via I2C. @@ -246,8 +254,8 @@ def direction(self): return In def get(self): - return self.get_raw() / self._scale + return to_byte(self.get_raw()) / self._scale value = property(get) def get_raw(self):