Skip to content

Commit c0abb19

Browse files
committed
attempt i2c lock 10 times at most
1 parent 346e8d3 commit c0abb19

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

adafruit_pybadger/pybadge.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,14 @@ def __init__(self):
6464
self._accelerometer = None
6565

6666
if i2c is not None:
67-
while not i2c.try_lock():
68-
pass
69-
_i2c_devices = i2c.scan()
70-
i2c.unlock()
67+
_i2c_devices = []
68+
69+
for i in range(10):
70+
# try lock 10 times to avoid infinite loop in sphinx build
71+
if i2c.try_lock():
72+
_i2c_devices = i2c.scan()
73+
i2c.unlock()
74+
break
7175

7276
# PyBadge LC doesn't have accelerometer
7377
if int(0x18) in _i2c_devices or int(0x19) in _i2c_devices:

0 commit comments

Comments
 (0)