From 4ea85ffc68a09621ffe3259357701a29ef2e6534 Mon Sep 17 00:00:00 2001 From: cerickson Date: Mon, 14 May 2018 14:09:55 -0400 Subject: [PATCH 1/3] Made chip_select default to None, all chip_select usage checks existance first --- adafruit_bus_device/spi_device.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/adafruit_bus_device/spi_device.py b/adafruit_bus_device/spi_device.py index 8e76503..4c147e9 100644 --- a/adafruit_bus_device/spi_device.py +++ b/adafruit_bus_device/spi_device.py @@ -65,25 +65,28 @@ class SPIDevice: with device as spi: spi.write(bytes_read) """ - def __init__(self, spi, chip_select, *, baudrate=100000, polarity=0, phase=0, extra_clocks=0): + def __init__(self, spi, chip_select=None, *, baudrate=100000, polarity=0, phase=0, extra_clocks=0): self.spi = spi self.baudrate = baudrate self.polarity = polarity self.phase = phase self.extra_clocks = extra_clocks self.chip_select = chip_select - self.chip_select.switch_to_output(value=True) + if self.chip_select: + self.chip_select.switch_to_output(value=True) def __enter__(self): while not self.spi.try_lock(): pass self.spi.configure(baudrate=self.baudrate, polarity=self.polarity, phase=self.phase) - self.chip_select.value = False + if self.chip_select: + self.chip_select.value = False return self.spi def __exit__(self, *exc): - self.chip_select.value = True + if self.chip_select: + self.chip_select.value = True if self.extra_clocks > 0: buf = bytearray(1) buf[0] = 0xff From 1993c52b8197bf5c685da328db9afecbd8090dd0 Mon Sep 17 00:00:00 2001 From: cerickson Date: Mon, 14 May 2018 14:57:23 -0400 Subject: [PATCH 2/3] Fixed __init__ args line length for pylint --- adafruit_bus_device/spi_device.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/adafruit_bus_device/spi_device.py b/adafruit_bus_device/spi_device.py index 4c147e9..0826405 100644 --- a/adafruit_bus_device/spi_device.py +++ b/adafruit_bus_device/spi_device.py @@ -65,7 +65,8 @@ class SPIDevice: with device as spi: spi.write(bytes_read) """ - def __init__(self, spi, chip_select=None, *, baudrate=100000, polarity=0, phase=0, extra_clocks=0): + def __init__(self, spi, chip_select=None, *, + baudrate=100000, polarity=0, phase=0, extra_clocks=0): self.spi = spi self.baudrate = baudrate self.polarity = polarity From 85d5cca2872425201eb8d430f7c2ce56aef943cf Mon Sep 17 00:00:00 2001 From: cerickson Date: Mon, 14 May 2018 15:52:55 -0400 Subject: [PATCH 3/3] Fixed trailing space pylint error --- adafruit_bus_device/spi_device.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_bus_device/spi_device.py b/adafruit_bus_device/spi_device.py index 0826405..b8bea8a 100644 --- a/adafruit_bus_device/spi_device.py +++ b/adafruit_bus_device/spi_device.py @@ -65,7 +65,7 @@ class SPIDevice: with device as spi: spi.write(bytes_read) """ - def __init__(self, spi, chip_select=None, *, + def __init__(self, spi, chip_select=None, *, baudrate=100000, polarity=0, phase=0, extra_clocks=0): self.spi = spi self.baudrate = baudrate