attempt i2c lock 10 times at most

This commit is contained in:
foamyguy 2021-12-05 12:44:00 -06:00
parent 346e8d3542
commit c0abb195bf

View file

@ -64,10 +64,14 @@ class PyBadge(PyBadgerBase):
self._accelerometer = None
if i2c is not None:
while not i2c.try_lock():
pass
_i2c_devices = i2c.scan()
i2c.unlock()
_i2c_devices = []
for i in range(10):
# try lock 10 times to avoid infinite loop in sphinx build
if i2c.try_lock():
_i2c_devices = i2c.scan()
i2c.unlock()
break
# PyBadge LC doesn't have accelerometer
if int(0x18) in _i2c_devices or int(0x19) in _i2c_devices: