From 878888f667d50310107f0888d08c49b1272e22dc Mon Sep 17 00:00:00 2001 From: caternuson Date: Thu, 25 Jul 2019 11:43:15 -0700 Subject: [PATCH 1/3] provide writeto_then_readfrom only if needed --- adafruit_tca9548a.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/adafruit_tca9548a.py b/adafruit_tca9548a.py index c42ae73..968482e 100644 --- a/adafruit_tca9548a.py +++ b/adafruit_tca9548a.py @@ -57,6 +57,9 @@ class TCA9548A_Channel(): def __init__(self, tca, channel): self.tca = tca self.channel_switch = bytearray([1 << channel]) + # provide only if needed + if hasattr(self.tca.i2c, 'writeto_then_readfrom'): + setattr(self, 'writeto_then_readfrom', self.writeto_then_readfrom_passthru) def try_lock(self): """Pass thru for try_lock.""" @@ -82,7 +85,7 @@ def writeto(self, address, buffer, **kwargs): raise ValueError("Device address must be different than TCA9548A address.") return self.tca.i2c.writeto(address, buffer, **kwargs) - def writeto_then_readfrom(self, address, buffer_out, buffer_in, **kwargs): + def writeto_then_readfrom_passthru(self, address, buffer_out, buffer_in, **kwargs): """Pass thru for writeto_then_readfrom.""" #In linux, at least, this is a special kernel function call if address == self.tca.address: From 9db81d6aeb593f7e49f6d9f8a77534b4ee5a9d74 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Mon, 5 Aug 2019 19:07:46 -0700 Subject: [PATCH 2/3] Always provide writeto_then_readfrom It's the future! --- adafruit_tca9548a.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/adafruit_tca9548a.py b/adafruit_tca9548a.py index 968482e..b21615c 100644 --- a/adafruit_tca9548a.py +++ b/adafruit_tca9548a.py @@ -57,9 +57,6 @@ class TCA9548A_Channel(): def __init__(self, tca, channel): self.tca = tca self.channel_switch = bytearray([1 << channel]) - # provide only if needed - if hasattr(self.tca.i2c, 'writeto_then_readfrom'): - setattr(self, 'writeto_then_readfrom', self.writeto_then_readfrom_passthru) def try_lock(self): """Pass thru for try_lock.""" @@ -85,12 +82,17 @@ def writeto(self, address, buffer, **kwargs): raise ValueError("Device address must be different than TCA9548A address.") return self.tca.i2c.writeto(address, buffer, **kwargs) - def writeto_then_readfrom_passthru(self, address, buffer_out, buffer_in, **kwargs): + def writeto_then_readfrom(self, address, buffer_out, buffer_in, **kwargs): """Pass thru for writeto_then_readfrom.""" #In linux, at least, this is a special kernel function call if address == self.tca.address: raise ValueError("Device address must be different than TCA9548A address.") - return self.tca.i2c.writeto_then_readfrom(address, buffer_out, buffer_in, **kwargs) + + if hasattr(self.tca.i2c, 'writeto_then_readfrom'): + self.tca.i2c.writeto_then_readfrom(address, buffer_out, buffer_in, **kwargs) + else: + self.tca.i2c.writeto(address, buffer_out, start=kwargs.get("out_start", 0), end=kwargs.get("out_end", None), stop=False) + self.tca.i2c.readfrom_into(address, buffer_in, start=kwargs.get("in_start", 0), end=kwargs.get("in_end", None)) class TCA9548A(): """Class which provides interface to TCA9548A I2C multiplexer.""" From bad25bc3b1de96b9c5b5cc80a63e8ac036f5a2f4 Mon Sep 17 00:00:00 2001 From: caternuson Date: Tue, 6 Aug 2019 14:11:14 -0700 Subject: [PATCH 3/3] lint --- adafruit_tca9548a.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/adafruit_tca9548a.py b/adafruit_tca9548a.py index b21615c..3e3cad0 100644 --- a/adafruit_tca9548a.py +++ b/adafruit_tca9548a.py @@ -87,12 +87,17 @@ def writeto_then_readfrom(self, address, buffer_out, buffer_in, **kwargs): #In linux, at least, this is a special kernel function call if address == self.tca.address: raise ValueError("Device address must be different than TCA9548A address.") - + if hasattr(self.tca.i2c, 'writeto_then_readfrom'): self.tca.i2c.writeto_then_readfrom(address, buffer_out, buffer_in, **kwargs) else: - self.tca.i2c.writeto(address, buffer_out, start=kwargs.get("out_start", 0), end=kwargs.get("out_end", None), stop=False) - self.tca.i2c.readfrom_into(address, buffer_in, start=kwargs.get("in_start", 0), end=kwargs.get("in_end", None)) + self.tca.i2c.writeto(address, buffer_out, + start=kwargs.get("out_start", 0), + end=kwargs.get("out_end", None), + stop=False) + self.tca.i2c.readfrom_into(address, buffer_in, + start=kwargs.get("in_start", 0), + end=kwargs.get("in_end", None)) class TCA9548A(): """Class which provides interface to TCA9548A I2C multiplexer."""