Skip to content

Commit 6fc9415

Browse files
authored
Reused i2c from init
1 parent f7f2c58 commit 6fc9415

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

adafruit_vl53l1x.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ class VL53L1X:
7777

7878
def __init__(self, i2c, address=41):
7979
self.i2c_device = i2c_device.I2CDevice(i2c, address)
80+
self._i2c = i2c
8081
model_id, module_type, mask_rev = self.model_info
8182
if model_id != 0xEA or module_type != 0xCC or mask_rev != 0x10:
8283
raise RuntimeError("Wrong sensor ID or type!")
@@ -302,12 +303,12 @@ def _read_register(self, address, length=1):
302303
i2c.readinto(data)
303304
return data
304305

305-
def set_address(self, i2c, new_address):
306+
def set_address(self, new_address):
306307
"""
307308
Set a new I2C address to the instantaited object. This is only called when using
308309
multiple VL53L0X sensors on the same I2C bus (SDA & SCL pins). See also the
309310
`example <examples.html#multiple-vl53l1x-on-same-i2c-bus>`_ for proper usage.
310311
"""
311312
new_addres_as_byte_string = new_address.to_bytes(1, "little")
312313
self._write_register(0x01, new_addres_as_byte_string)
313-
self.i2c_device = i2c_device.I2CDevice(i2c, new_address)
314+
self.i2c_device = i2c_device.I2CDevice(self._i2c, new_address)

0 commit comments

Comments
 (0)