From ee44670d05e252490dc3f7ad83f58598a86c40fa Mon Sep 17 00:00:00 2001 From: Code Simian Date: Mon, 8 Dec 2014 10:31:26 -0500 Subject: [PATCH] Two small changes: 1. Fixed bug where boolean "and" was incorrectly used instead of bitwise "&". We're testing a bit in a byte. 2. Moved the sleep call to BEFORE the first read. Occasional errors with immediate read after write. --- Adafruit_VCNL4000/Adafruit_VCNL4000.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Adafruit_VCNL4000/Adafruit_VCNL4000.py b/Adafruit_VCNL4000/Adafruit_VCNL4000.py index 4d307536..5bf98be0 100755 --- a/Adafruit_VCNL4000/Adafruit_VCNL4000.py +++ b/Adafruit_VCNL4000/Adafruit_VCNL4000.py @@ -46,16 +46,16 @@ def __init__(self, address=0x13): def read_proximity(self): self.i2c.write8(VCNL4000_COMMAND, VCNL4000_MEASUREPROXIMITY) while True: + time.sleep(0.001) result = self.i2c.readU8(VCNL4000_COMMAND) - if (result and VCNL4000_PROXIMITYREADY): + if (result & VCNL4000_PROXIMITYREADY): return self.i2c.readU16(VCNL4000_PROXIMITYDATA) - time.sleep(0.001) # Read data from ambient sensor def read_ambient(self): self.i2c.write8(VCNL4000_COMMAND, VCNL4000_MEASUREAMBIENT) while True: + time.sleep(0.001) result = self.i2c.readU8(VCNL4000_COMMAND) - if (result and VCNL4000_AMBIENTREADY): + if (result & VCNL4000_AMBIENTREADY): return self.i2c.readU16(VCNL4000_AMBIENTDATA) - time.sleep(0.001)