fix ads111x

This commit is contained in:
Nikolay Khabarov
2017-07-09 03:18:00 +03:00
parent baacf6dfdd
commit fdd2c4b059
+5 -5
View File
@@ -30,7 +30,7 @@ class __I2CDev(object):
os.write(self._dev, data) os.write(self._dev, data)
def read(self, n): def read(self, n):
os.read(self._dev, n) return os.read(self._dev, n)
i2c = __I2CDev() i2c = __I2CDev()
@@ -59,13 +59,13 @@ def measure(channel):
i2c.write(data) i2c.write(data)
# wait for conversion # wait for conversion
while True: while True:
i2c.write(data, struct.pack("B", 0x01)) i2c.write(struct.pack("B", 0x01))
if struct.unpack(">H", i2c.read(data, 2))[0] & 0x8000 != 0: if struct.unpack(">H", i2c.read(2))[0] & 0x8000 != 0:
break break
time.sleep(0.0001) time.sleep(0.0001)
# read result # read result
i2c.write(data, struct.pack("B", 0x00)) # conversion register i2c.write(struct.pack("B", 0x00)) # conversion register
v = struct.unpack(">h", i2c.read(data, 2))[0] v = struct.unpack(">h", i2c.read(2))[0]
lock.release() lock.release()
return v / 8000.0 # / 32768.0 * 4.096 according to specified range return v / 8000.0 # / 32768.0 * 4.096 according to specified range