From 9aab1b8b6418b2daaf585c799f745cda3727a7c8 Mon Sep 17 00:00:00 2001 From: siddacious Date: Thu, 30 Jan 2020 16:30:45 -0800 Subject: [PATCH 1/3] updating string format to match BusIO --- adafruit_debug_i2c.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/adafruit_debug_i2c.py b/adafruit_debug_i2c.py index 5578845..f9431de 100644 --- a/adafruit_debug_i2c.py +++ b/adafruit_debug_i2c.py @@ -40,7 +40,7 @@ __version__ = "0.0.0-auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_Debug_I2C.git" - +from re import sub class DebugI2C: """ @@ -107,7 +107,9 @@ def readfrom_into(self, address, buffer, *args, start=0, end=None): """ self._i2c.readfrom_into(address, buffer, *args, start=start, end=end) - print("i2c.readfrom_into at address {}:".format(hex(address)), [hex(i) for i in buffer]) + + in_buffer_str = sub("\[|\]|'", "", str([hex(i) for i in buffer])) + print("\tI2CREAD @ {} ::".format(hex(address)), in_buffer_str) def scan(self): """ @@ -146,7 +148,9 @@ def writeto(self, address, buffer, *args, **kwargs): buffer is written """ self._i2c.writeto(address, buffer, *args, **kwargs) - print("i2c.writeto at address {}:".format(hex(address)), [hex(i) for i in buffer]) + + out_buffer_str = sub("\[|\]|'", "", str( [hex(i) for i in buffer])) + print("\tI2CWRITE @ {} ::".format(hex(address)), out_buffer_str) def _writeto_then_readfrom(self, address, buffer_out, buffer_in, *args, out_start=0, out_end=None, in_start=0, in_end=None): @@ -167,9 +171,11 @@ def _writeto_then_readfrom(self, address, buffer_out, buffer_in, *args, out_star :param int in_end: End of the slice; this index is not included. Defaults to ``len(buffer_in)`` """ - print("i2c.writeto_then_readfrom.buffer_out at address {}:".format(hex(address)), - [hex(i) for i in buffer_out[out_start:out_end]]) + out_buffer_str = sub("\[|\]|'", "", str([hex(i) for i in buffer_out[out_start:out_end]])) + print("\tI2CWRITE @ {} ::".format(hex(address)), out_buffer_str) + self._i2c.writeto_then_readfrom(address, buffer_out, buffer_in, *args, out_start=out_start, out_end=out_end, in_start=in_start, in_end=in_end) - print("i2c.writeto_then_readfrom.buffer_in at address {}:".format(hex(address)), - [hex(i) for i in buffer_in[in_start:in_end]]) + + in_buffer_str = sub("\[|\]|'", "", str([hex(i) for i in buffer_in[in_start:in_end]])) + print("\tI2CREAD @ {} ::".format(hex(address)), in_buffer_str) From e2192b305db063390a4130c2deb610ee50cd20b3 Mon Sep 17 00:00:00 2001 From: siddacious Date: Thu, 30 Jan 2020 16:48:02 -0800 Subject: [PATCH 2/3] fixing lint --- adafruit_debug_i2c.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/adafruit_debug_i2c.py b/adafruit_debug_i2c.py index f9431de..ea4703a 100644 --- a/adafruit_debug_i2c.py +++ b/adafruit_debug_i2c.py @@ -73,6 +73,7 @@ class DebugI2C: print(accelerometer.acceleration) """ + #pylint: disable=anomalous-backslash-in-string def __init__(self, i2c): self._i2c = i2c if hasattr(self._i2c, 'writeto_then_readfrom'): @@ -149,7 +150,7 @@ def writeto(self, address, buffer, *args, **kwargs): """ self._i2c.writeto(address, buffer, *args, **kwargs) - out_buffer_str = sub("\[|\]|'", "", str( [hex(i) for i in buffer])) + out_buffer_str = sub("\[|\]|'", "", str([hex(i) for i in buffer])) print("\tI2CWRITE @ {} ::".format(hex(address)), out_buffer_str) def _writeto_then_readfrom(self, address, buffer_out, buffer_in, *args, out_start=0, From 3ae6294e1d9b73e32e718654eea078449a5e6083 Mon Sep 17 00:00:00 2001 From: siddacious Date: Thu, 30 Jan 2020 17:03:51 -0800 Subject: [PATCH 3/3] removing sub --- adafruit_debug_i2c.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/adafruit_debug_i2c.py b/adafruit_debug_i2c.py index ea4703a..e07f4a9 100644 --- a/adafruit_debug_i2c.py +++ b/adafruit_debug_i2c.py @@ -40,7 +40,6 @@ __version__ = "0.0.0-auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_Debug_I2C.git" -from re import sub class DebugI2C: """ @@ -73,7 +72,6 @@ class DebugI2C: print(accelerometer.acceleration) """ - #pylint: disable=anomalous-backslash-in-string def __init__(self, i2c): self._i2c = i2c if hasattr(self._i2c, 'writeto_then_readfrom'): @@ -109,7 +107,7 @@ def readfrom_into(self, address, buffer, *args, start=0, end=None): """ self._i2c.readfrom_into(address, buffer, *args, start=start, end=end) - in_buffer_str = sub("\[|\]|'", "", str([hex(i) for i in buffer])) + in_buffer_str = ", ".join([hex(i) for i in buffer]) print("\tI2CREAD @ {} ::".format(hex(address)), in_buffer_str) def scan(self): @@ -150,7 +148,7 @@ def writeto(self, address, buffer, *args, **kwargs): """ self._i2c.writeto(address, buffer, *args, **kwargs) - out_buffer_str = sub("\[|\]|'", "", str([hex(i) for i in buffer])) + out_buffer_str = ", ".join([hex(i) for i in buffer]) print("\tI2CWRITE @ {} ::".format(hex(address)), out_buffer_str) def _writeto_then_readfrom(self, address, buffer_out, buffer_in, *args, out_start=0, @@ -172,11 +170,11 @@ def _writeto_then_readfrom(self, address, buffer_out, buffer_in, *args, out_star :param int in_end: End of the slice; this index is not included. Defaults to ``len(buffer_in)`` """ - out_buffer_str = sub("\[|\]|'", "", str([hex(i) for i in buffer_out[out_start:out_end]])) + out_buffer_str = ", ".join([hex(i) for i in buffer_out[out_start:out_end]]) print("\tI2CWRITE @ {} ::".format(hex(address)), out_buffer_str) self._i2c.writeto_then_readfrom(address, buffer_out, buffer_in, *args, out_start=out_start, out_end=out_end, in_start=in_start, in_end=in_end) - in_buffer_str = sub("\[|\]|'", "", str([hex(i) for i in buffer_in[in_start:in_end]])) + in_buffer_str = ", ".join([hex(i) for i in buffer_in[in_start:in_end]]) print("\tI2CREAD @ {} ::".format(hex(address)), in_buffer_str)