Skip to content

Commit ee44670

Browse files
committed
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.
1 parent bf50dd3 commit ee44670

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

Adafruit_VCNL4000/Adafruit_VCNL4000.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,16 @@ def __init__(self, address=0x13):
4646
def read_proximity(self):
4747
self.i2c.write8(VCNL4000_COMMAND, VCNL4000_MEASUREPROXIMITY)
4848
while True:
49+
time.sleep(0.001)
4950
result = self.i2c.readU8(VCNL4000_COMMAND)
50-
if (result and VCNL4000_PROXIMITYREADY):
51+
if (result & VCNL4000_PROXIMITYREADY):
5152
return self.i2c.readU16(VCNL4000_PROXIMITYDATA)
52-
time.sleep(0.001)
5353

5454
# Read data from ambient sensor
5555
def read_ambient(self):
5656
self.i2c.write8(VCNL4000_COMMAND, VCNL4000_MEASUREAMBIENT)
5757
while True:
58+
time.sleep(0.001)
5859
result = self.i2c.readU8(VCNL4000_COMMAND)
59-
if (result and VCNL4000_AMBIENTREADY):
60+
if (result & VCNL4000_AMBIENTREADY):
6061
return self.i2c.readU16(VCNL4000_AMBIENTDATA)
61-
time.sleep(0.001)

0 commit comments

Comments
 (0)