From 652ef19bf298c84bbe4430725a72a4218b4c6781 Mon Sep 17 00:00:00 2001 From: PRC-SAK Date: Wed, 27 Jan 2021 17:05:37 -0800 Subject: [PATCH 01/12] Remove extra \x00 in DISPLAY ON of _INIT_SEQUENCE --- adafruit_displayio_sh1107.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_displayio_sh1107.py b/adafruit_displayio_sh1107.py index 310f1e0..ad66468 100644 --- a/adafruit_displayio_sh1107.py +++ b/adafruit_displayio_sh1107.py @@ -46,7 +46,7 @@ b"\xb0\x00" # set page address = 0 (POR) b"\xa4\x00" # entire display off, retain RAM, normal status (POR) b"\xa6\x00" # normal (not reversed) display - b"\xAF\x00\x00" # DISPLAY_ON + b"\xaf\x00" # DISPLAY_ON ) From 25031b0edec3791bef155805960e6f36d4573b36 Mon Sep 17 00:00:00 2001 From: PRC-SAK Date: Thu, 28 Jan 2021 11:09:07 -0800 Subject: [PATCH 02/12] Implement sleep/wake states for display Added: self._awake - stores current state of the display state - property that returns the current state sleep() - method that puts display to sleep wake() - method that wakes display from sleep --- adafruit_displayio_sh1107.py | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/adafruit_displayio_sh1107.py b/adafruit_displayio_sh1107.py index ad66468..cdacab0 100644 --- a/adafruit_displayio_sh1107.py +++ b/adafruit_displayio_sh1107.py @@ -50,7 +50,6 @@ ) -# pylint: disable=too-few-public-methods class SH1107(displayio.Display): """SSD1107 driver""" @@ -73,3 +72,36 @@ def __init__(self, bus, **kwargs): # set page address = 0xB0 - 0xBF (16 pages) SH1107_addressing=True, ) + self._awake = True # Display starts in active state (_INIT_SEQUENCE) + + @property + def state(self): + """ + The power state of the display. (read-only) + + True if the display is active, False if in sleep mode. + """ + return self._awake + + def sleep(self): + """ + Put display into sleep mode + + The display uses < 5uA in sleep mode + Sleep mode does the following: + 1) Stops the oscillator and DC-DC circuits + 2) Stops the OLED drive + 3) Remembers display data and operation mode active prior to sleeping + 4) The MP can access (update) the built-in display RAM + """ + if self._awake: + self.bus.send(int(0xAE), "") # 0xAE = display off, sleep mode + self._awake = False + + def wake(self): + """ + Wake display from sleep mode + """ + if not self._awake: + self.bus.send(int(0xAF), "") # 0xAF = display on + self._awake = True From 55250574e4245898a21bffeb0f0744d41cfe0920 Mon Sep 17 00:00:00 2001 From: PRC-SAK Date: Thu, 28 Jan 2021 18:31:05 -0800 Subject: [PATCH 03/12] Update .pre-commit-config.yaml Received error during PR submission checks that the rev: fields of the black and reuse-tool repos cannot be mutable objects. Changed rev from "latest" to the current version numbers for each repo. --- .pre-commit-config.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index fbda35c..07f886c 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -4,11 +4,11 @@ repos: - repo: https://github.com/python/black - rev: latest + rev: 20.8b1 hooks: - id: black - repo: https://github.com/fsfe/reuse-tool - rev: latest + rev: v0.12.1 hooks: - id: reuse - repo: https://github.com/pre-commit/pre-commit-hooks From f7a2ae084873cfcca0a200929b825bbdcd3dd4e0 Mon Sep 17 00:00:00 2001 From: PRC-SAK Date: Thu, 28 Jan 2021 18:49:57 -0800 Subject: [PATCH 04/12] Update copyright and licensing headers PR check-in failed Pre-commit hooks test indicating these files had missing copyright and licensing info. Added headers as per @dherrada. --- .gitignore | 3 +++ .pylintrc | 3 +++ examples/displayio_sh1107_game_of_life.py | 3 +++ examples/displayio_sh1107_random_motion.py | 7 ++++--- examples/displayio_sh1107_simpletest.py | 11 +++++------ 5 files changed, 18 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index c83f8b7..3c0f06d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ +# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries +# +# SPDX-License-Identifier: Unlicense *.mpy .idea __pycache__ diff --git a/.pylintrc b/.pylintrc index d8f0ee8..62ee415 100644 --- a/.pylintrc +++ b/.pylintrc @@ -1,3 +1,6 @@ +# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries +# +# SPDX-License-Identifier: Unlicense [MASTER] # A comma-separated list of package or module names from where C extensions may diff --git a/examples/displayio_sh1107_game_of_life.py b/examples/displayio_sh1107_game_of_life.py index 6ba794b..e8397ce 100644 --- a/examples/displayio_sh1107_game_of_life.py +++ b/examples/displayio_sh1107_game_of_life.py @@ -1,3 +1,6 @@ +# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries +# +# SPDX-License-Identifier: Unlicense """ Author: Mark Roberts (mdroberts1243) from Adafruit code Conway's game of life. diff --git a/examples/displayio_sh1107_random_motion.py b/examples/displayio_sh1107_random_motion.py index db36fa8..526ff6f 100644 --- a/examples/displayio_sh1107_random_motion.py +++ b/examples/displayio_sh1107_random_motion.py @@ -1,3 +1,6 @@ +# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries +# +# SPDX-License-Identifier: Unlicense """ Author: Mark Roberts (mdroberts1243) from Adafruit code This test will initialize the display using displayio and draw a solid white @@ -44,9 +47,7 @@ inner_bitmap = displayio.Bitmap(WIDTH - BORDER * 2, HEIGHT - BORDER * 2, 1) inner_palette = displayio.Palette(1) inner_palette[0] = 0x000000 # Black -inner_sprite = displayio.TileGrid( - inner_bitmap, pixel_shader=inner_palette, x=BORDER, y=BORDER -) +inner_sprite = displayio.TileGrid(inner_bitmap, pixel_shader=inner_palette, x=BORDER, y=BORDER) splash.append(inner_sprite) # Draw some white squares diff --git a/examples/displayio_sh1107_simpletest.py b/examples/displayio_sh1107_simpletest.py index 89aa34a..3fa4993 100644 --- a/examples/displayio_sh1107_simpletest.py +++ b/examples/displayio_sh1107_simpletest.py @@ -1,3 +1,6 @@ +# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries +# +# SPDX-License-Identifier: Unlicense """ Author: Mark Roberts (mdroberts1243) from Adafruit code This test will initialize the display using displayio and draw a solid white @@ -42,9 +45,7 @@ inner_bitmap = displayio.Bitmap(WIDTH - BORDER * 2, HEIGHT - BORDER * 2, 1) inner_palette = displayio.Palette(1) inner_palette[0] = 0x000000 # Black -inner_sprite = displayio.TileGrid( - inner_bitmap, pixel_shader=inner_palette, x=BORDER, y=BORDER -) +inner_sprite = displayio.TileGrid(inner_bitmap, pixel_shader=inner_palette, x=BORDER, y=BORDER) splash.append(inner_sprite) # Draw some white squares @@ -65,9 +66,7 @@ text_area = label.Label(terminalio.FONT, text=text1, color=0xFFFFFF, x=8, y=8) splash.append(text_area) text2 = "SH1107" -text_area2 = label.Label( - terminalio.FONT, text=text2, scale=2, color=0xFFFFFF, x=9, y=44 -) +text_area2 = label.Label(terminalio.FONT, text=text2, scale=2, color=0xFFFFFF, x=9, y=44) splash.append(text_area2) while True: From 1ff1d3782883ff88736563c7d0d5593d95e16fec Mon Sep 17 00:00:00 2001 From: PRC-SAK Date: Thu, 28 Jan 2021 19:25:25 -0800 Subject: [PATCH 05/12] Fix end-of-file error in .gitignore --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 3c0f06d..439d971 100644 --- a/.gitignore +++ b/.gitignore @@ -11,4 +11,4 @@ bundles *.DS_Store .eggs dist -**/*.egg-info \ No newline at end of file +**/*.egg-info From b61ba8851e7fc1adb387f0268f76d9f657d6df27 Mon Sep 17 00:00:00 2001 From: PRC-SAK Date: Thu, 28 Jan 2021 20:23:03 -0800 Subject: [PATCH 06/12] Reblacken examples using default black line length --- examples/displayio_sh1107_game_of_life.py | 1 + examples/displayio_sh1107_random_motion.py | 4 +++- examples/displayio_sh1107_simpletest.py | 9 +++++++-- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/examples/displayio_sh1107_game_of_life.py b/examples/displayio_sh1107_game_of_life.py index e8397ce..56206e1 100644 --- a/examples/displayio_sh1107_game_of_life.py +++ b/examples/displayio_sh1107_game_of_life.py @@ -6,6 +6,7 @@ Conway's game of life. """ + import random import time diff --git a/examples/displayio_sh1107_random_motion.py b/examples/displayio_sh1107_random_motion.py index 526ff6f..929d4cb 100644 --- a/examples/displayio_sh1107_random_motion.py +++ b/examples/displayio_sh1107_random_motion.py @@ -47,7 +47,9 @@ inner_bitmap = displayio.Bitmap(WIDTH - BORDER * 2, HEIGHT - BORDER * 2, 1) inner_palette = displayio.Palette(1) inner_palette[0] = 0x000000 # Black -inner_sprite = displayio.TileGrid(inner_bitmap, pixel_shader=inner_palette, x=BORDER, y=BORDER) +inner_sprite = displayio.TileGrid( + inner_bitmap, pixel_shader=inner_palette, x=BORDER, y=BORDER +) splash.append(inner_sprite) # Draw some white squares diff --git a/examples/displayio_sh1107_simpletest.py b/examples/displayio_sh1107_simpletest.py index 3fa4993..f4f14d6 100644 --- a/examples/displayio_sh1107_simpletest.py +++ b/examples/displayio_sh1107_simpletest.py @@ -8,6 +8,7 @@ """ + import board import displayio import terminalio @@ -45,7 +46,9 @@ inner_bitmap = displayio.Bitmap(WIDTH - BORDER * 2, HEIGHT - BORDER * 2, 1) inner_palette = displayio.Palette(1) inner_palette[0] = 0x000000 # Black -inner_sprite = displayio.TileGrid(inner_bitmap, pixel_shader=inner_palette, x=BORDER, y=BORDER) +inner_sprite = displayio.TileGrid( + inner_bitmap, pixel_shader=inner_palette, x=BORDER, y=BORDER +) splash.append(inner_sprite) # Draw some white squares @@ -66,7 +69,9 @@ text_area = label.Label(terminalio.FONT, text=text1, color=0xFFFFFF, x=8, y=8) splash.append(text_area) text2 = "SH1107" -text_area2 = label.Label(terminalio.FONT, text=text2, scale=2, color=0xFFFFFF, x=9, y=44) +text_area2 = label.Label( + terminalio.FONT, text=text2, scale=2, color=0xFFFFFF, x=9, y=44 +) splash.append(text_area2) while True: From 09362df07c9dc514f46e9d3093903166371a83df Mon Sep 17 00:00:00 2001 From: PRC-SAK Date: Thu, 28 Jan 2021 20:42:22 -0800 Subject: [PATCH 07/12] Address pylint errors and blacken Addressed the following pylint errors: unused-import [13,1] redefined-builtin [16,1] wrong-import-order [16,1] wrong-import-order [17,1] --- setup.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/setup.py b/setup.py index cd57940..8a65ee5 100644 --- a/setup.py +++ b/setup.py @@ -10,16 +10,16 @@ https://github.com/pypa/sampleproject """ -from setuptools import setup, find_packages - # To use a consistent encoding -from codecs import open +from codecs import open as open_codec from os import path +from setuptools import setup + here = path.abspath(path.dirname(__file__)) # Get the long description from the README file -with open(path.join(here, "README.rst"), encoding="utf-8") as f: +with open_codec(path.join(here, "README.rst"), encoding="utf-8") as f: long_description = f.read() setup( From 732e1489e2a79d47eb9fc5ee9ea3bd9fe661e415 Mon Sep 17 00:00:00 2001 From: PRC-SAK Date: Thu, 28 Jan 2021 21:26:36 -0800 Subject: [PATCH 08/12] Fix black formatting issue (different versions?) --- setup.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 8a65ee5..edc785f 100644 --- a/setup.py +++ b/setup.py @@ -10,6 +10,7 @@ https://github.com/pypa/sampleproject """ + # To use a consistent encoding from codecs import open as open_codec from os import path @@ -34,7 +35,9 @@ # Author details author="Adafruit Industries", author_email="circuitpython@adafruit.com", - install_requires=["Adafruit-Blinka",], + install_requires=[ + "Adafruit-Blinka", + ], # Choose your license license="MIT", # See https://pypi.python.org/pypi?%3Aaction=list_classifiers From 5b88c42a838eddd3b931d293ed90a7a23b171b30 Mon Sep 17 00:00:00 2001 From: PRC-SAK Date: Thu, 28 Jan 2021 21:40:17 -0800 Subject: [PATCH 09/12] Fix docstring formatting for Sphinx --- adafruit_displayio_sh1107.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/adafruit_displayio_sh1107.py b/adafruit_displayio_sh1107.py index cdacab0..4087870 100644 --- a/adafruit_displayio_sh1107.py +++ b/adafruit_displayio_sh1107.py @@ -89,10 +89,10 @@ def sleep(self): The display uses < 5uA in sleep mode Sleep mode does the following: - 1) Stops the oscillator and DC-DC circuits - 2) Stops the OLED drive - 3) Remembers display data and operation mode active prior to sleeping - 4) The MP can access (update) the built-in display RAM + 1) Stops the oscillator and DC-DC circuits + 2) Stops the OLED drive + 3) Remembers display data and operation mode active prior to sleeping + 4) The MP can access (update) the built-in display RAM """ if self._awake: self.bus.send(int(0xAE), "") # 0xAE = display off, sleep mode From 166dae82ed8b57f52f9f8f8405b33766bf279df0 Mon Sep 17 00:00:00 2001 From: PRC-SAK Date: Tue, 2 Feb 2021 10:16:12 -0800 Subject: [PATCH 10/12] Change name of display state property Changed name of display state property from "active" to "is_awake" to clarify it refers to the display state. --- adafruit_displayio_sh1107.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/adafruit_displayio_sh1107.py b/adafruit_displayio_sh1107.py index 4087870..50b9fbd 100644 --- a/adafruit_displayio_sh1107.py +++ b/adafruit_displayio_sh1107.py @@ -72,7 +72,7 @@ def __init__(self, bus, **kwargs): # set page address = 0xB0 - 0xBF (16 pages) SH1107_addressing=True, ) - self._awake = True # Display starts in active state (_INIT_SEQUENCE) + self.is_awake = True # Display starts in active state (_INIT_SEQUENCE) @property def state(self): @@ -81,7 +81,7 @@ def state(self): True if the display is active, False if in sleep mode. """ - return self._awake + return self.is_awake def sleep(self): """ @@ -94,14 +94,14 @@ def sleep(self): 3) Remembers display data and operation mode active prior to sleeping 4) The MP can access (update) the built-in display RAM """ - if self._awake: + if self.is_awake: self.bus.send(int(0xAE), "") # 0xAE = display off, sleep mode - self._awake = False + self.is_awake = False def wake(self): """ Wake display from sleep mode """ - if not self._awake: + if not self.is_awake: self.bus.send(int(0xAF), "") # 0xAF = display on - self._awake = True + self.is_awake = True From 66d21f22b40b790c6efc12fa1a0e88b24cad39f1 Mon Sep 17 00:00:00 2001 From: PRC-SAK Date: Tue, 2 Feb 2021 10:59:53 -0800 Subject: [PATCH 11/12] Change module reference in Usage Example (#3) --- README.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.rst b/README.rst index cf5f9e4..50fd2b2 100644 --- a/README.rst +++ b/README.rst @@ -64,7 +64,7 @@ Usage Example import displayio import terminalio import bitmap_label as label # from adafruit_display_text - import mdroberts1243_displayio_sh1107 + import adafruit_displayio_sh1107 displayio.release_displays() #oled_reset = board.D9 @@ -78,7 +78,7 @@ Usage Example HEIGHT = 64 BORDER = 2 - display = mdroberts1243_displayio_sh1107.SH1107(display_bus, width=WIDTH, height=HEIGHT) + display = adafruit_displayio_sh1107.SH1107(display_bus, width=WIDTH, height=HEIGHT) # Make the display context splash = displayio.Group(max_size=10) From 7f3a7b206960dbe157fe2d008068415efa2b63d0 Mon Sep 17 00:00:00 2001 From: PRC-SAK Date: Wed, 3 Feb 2021 19:30:40 -0800 Subject: [PATCH 12/12] Address API change request Changed property name from state to is_awake Made self._is_awake private --- adafruit_displayio_sh1107.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/adafruit_displayio_sh1107.py b/adafruit_displayio_sh1107.py index 50b9fbd..0b22b73 100644 --- a/adafruit_displayio_sh1107.py +++ b/adafruit_displayio_sh1107.py @@ -72,16 +72,16 @@ def __init__(self, bus, **kwargs): # set page address = 0xB0 - 0xBF (16 pages) SH1107_addressing=True, ) - self.is_awake = True # Display starts in active state (_INIT_SEQUENCE) + self._is_awake = True # Display starts in active state (_INIT_SEQUENCE) @property - def state(self): + def is_awake(self): """ The power state of the display. (read-only) True if the display is active, False if in sleep mode. """ - return self.is_awake + return self._is_awake def sleep(self): """ @@ -94,14 +94,14 @@ def sleep(self): 3) Remembers display data and operation mode active prior to sleeping 4) The MP can access (update) the built-in display RAM """ - if self.is_awake: + if self._is_awake: self.bus.send(int(0xAE), "") # 0xAE = display off, sleep mode - self.is_awake = False + self._is_awake = False def wake(self): """ Wake display from sleep mode """ - if not self.is_awake: + if not self._is_awake: self.bus.send(int(0xAF), "") # 0xAF = display on - self.is_awake = True + self._is_awake = True