Skip to content

Commit 6374df7

Browse files
authored
Use saner names for the pin attributes
I think that `d_or_c` is as confusing as `dc`, possibly more, when the parameter is still called `dc`. If we wanted to be hyper-correct and stick to Python's style, we should call it `data_or_command`, but then for consistency we would also need things like `master_in_slave_out` and so on, and I think this is an overkill. Since the pin is usually labelled `dc` on the physical modules anyways, I think it's perfectly fine to use that — it's also consistent with the usage in Arduino and other drivers. I added `_pin` so make the linter shut up and also to clarify that this is indeed a pin. I also changed the name of `res` to `reset_pin` to be consistent (the label for that pin on the modules is sometimes `rs` and sometimes `rst` so keeping the shortcut is not helpful).
1 parent e1275e9 commit 6374df7

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

adafruit_ssd1306.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -176,28 +176,28 @@ def __init__(self, width, height, spi, dc, res, cs, *,
176176
res.switch_to_output(value=0)
177177
self.spi_device = spi_device.SPIDevice(spi, cs, baudrate=baudrate,
178178
polarity=polarity, phase=phase)
179-
self.d_or_c = dc
180-
self.res = res
179+
self.dc_pin = dc
180+
self.reset_pin = res
181181
self.buffer = bytearray((height // 8) * width)
182182
framebuffer = framebuf.FrameBuffer1(self.buffer, width, height)
183183
super().__init__(framebuffer, width, height, external_vcc)
184184

185185
def write_cmd(self, cmd):
186186
"""Send a command to the SPI device"""
187-
self.d_or_c.value = 0
187+
self.dc_pin.value = 0
188188
with self.spi_device as spi:
189189
spi.write(bytearray([cmd]))
190190

191191
def write_framebuf(self):
192192
"""write to the frame buffer via SPI"""
193-
self.d_or_c.value = 1
193+
self.dc_pin.value = 1
194194
with self.spi_device as spi:
195195
spi.write(self.buffer)
196196

197197
def poweron(self):
198198
"""Turn power off on the device"""
199-
self.res.value = 1
199+
self.reset_pin.value = 1
200200
time.sleep(0.001)
201-
self.res.value = 0
201+
self.reset_pin.value = 0
202202
time.sleep(0.010)
203-
self.res.value = 1
203+
self.reset_pin.value = 1

0 commit comments

Comments
 (0)