Skip to content

Commit 9db81d6

Browse files
authored
Always provide writeto_then_readfrom
It's the future!
1 parent 878888f commit 9db81d6

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

adafruit_tca9548a.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,6 @@ class TCA9548A_Channel():
5757
def __init__(self, tca, channel):
5858
self.tca = tca
5959
self.channel_switch = bytearray([1 << channel])
60-
# provide only if needed
61-
if hasattr(self.tca.i2c, 'writeto_then_readfrom'):
62-
setattr(self, 'writeto_then_readfrom', self.writeto_then_readfrom_passthru)
6360

6461
def try_lock(self):
6562
"""Pass thru for try_lock."""
@@ -85,12 +82,17 @@ def writeto(self, address, buffer, **kwargs):
8582
raise ValueError("Device address must be different than TCA9548A address.")
8683
return self.tca.i2c.writeto(address, buffer, **kwargs)
8784

88-
def writeto_then_readfrom_passthru(self, address, buffer_out, buffer_in, **kwargs):
85+
def writeto_then_readfrom(self, address, buffer_out, buffer_in, **kwargs):
8986
"""Pass thru for writeto_then_readfrom."""
9087
#In linux, at least, this is a special kernel function call
9188
if address == self.tca.address:
9289
raise ValueError("Device address must be different than TCA9548A address.")
93-
return self.tca.i2c.writeto_then_readfrom(address, buffer_out, buffer_in, **kwargs)
90+
91+
if hasattr(self.tca.i2c, 'writeto_then_readfrom'):
92+
self.tca.i2c.writeto_then_readfrom(address, buffer_out, buffer_in, **kwargs)
93+
else:
94+
self.tca.i2c.writeto(address, buffer_out, start=kwargs.get("out_start", 0), end=kwargs.get("out_end", None), stop=False)
95+
self.tca.i2c.readfrom_into(address, buffer_in, start=kwargs.get("in_start", 0), end=kwargs.get("in_end", None))
9496

9597
class TCA9548A():
9698
"""Class which provides interface to TCA9548A I2C multiplexer."""

0 commit comments

Comments
 (0)