Skip to content

Commit

Permalink
feat(utils): supported limited number of i2c lock tries
Browse files Browse the repository at this point in the history
  • Loading branch information
ssube committed Dec 23, 2019
1 parent 2e87fca commit 173168c
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions prometheus_express/utils.py
Expand Up @@ -13,9 +13,15 @@ def check_network(eth):
return True


def scan_i2c_bus(i2c):
def scan_i2c_bus(i2c, timeout=10):
attempt=0

while not i2c.try_lock():
pass
if attempt < timeout:
attempt += 1
pass
else:
return False

print('I2C devices:', [
hex(x) for x in i2c.scan()
Expand Down

0 comments on commit 173168c

Please sign in to comment.