Skip to content

Commit dad4acf

Browse files
authoredDec 13, 2021
Merge pull request #54 from FoamyGuy/pybadge_lc_compatibility
Pybadge LC compatibility
2 parents 75785b6 + 2e6781e commit dad4acf

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed
 

‎adafruit_pybadger/pybadge.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,24 @@ def __init__(self):
6464
self._accelerometer = None
6565

6666
if i2c is not None:
67-
int1 = digitalio.DigitalInOut(board.ACCELEROMETER_INTERRUPT)
68-
try:
69-
self._accelerometer = adafruit_lis3dh.LIS3DH_I2C(
70-
i2c, address=0x19, int1=int1
71-
)
72-
except ValueError:
73-
self._accelerometer = adafruit_lis3dh.LIS3DH_I2C(i2c, int1=int1)
67+
_i2c_devices = []
68+
69+
for _ 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
75+
76+
# PyBadge LC doesn't have accelerometer
77+
if int(0x18) in _i2c_devices or int(0x19) in _i2c_devices:
78+
int1 = digitalio.DigitalInOut(board.ACCELEROMETER_INTERRUPT)
79+
try:
80+
self._accelerometer = adafruit_lis3dh.LIS3DH_I2C(
81+
i2c, address=0x19, int1=int1
82+
)
83+
except ValueError:
84+
self._accelerometer = adafruit_lis3dh.LIS3DH_I2C(i2c, int1=int1)
7485

7586
# NeoPixels
7687
self._neopixels = neopixel.NeoPixel(

0 commit comments

Comments
 (0)
Please sign in to comment.