Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions adafruit_tca9548a.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SPDX-FileCopyrightText: 2018 Carter Nelson for Adafruit Industries

Check failure on line 1 in adafruit_tca9548a.py

View workflow job for this annotation

GitHub Actions / test

reformatted
#
# SPDX-License-Identifier: MIT

Expand Down Expand Up @@ -103,6 +103,18 @@
"""Class which provides interface to TCA9548A I2C multiplexer."""

def __init__(self, i2c: I2C, address: int = _DEFAULT_ADDRESS) -> None:
tries = 0
while not i2c.try_lock():
if (tries >= 200):
raise ValueError("Unable to lock I2C bus.")
tries += 1
time.sleep(0)

if address not in i2c.scan():
i2c.unlock()
raise ValueError(f"No TCA9548A detected at {hex(address)}.")
i2c.unlock()

self.i2c = i2c
self.address = address
self.channels = [None] * 8
Expand Down
Loading