diff --git a/.gitignore b/.gitignore index c83f8b7..439d971 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ +# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries +# +# SPDX-License-Identifier: Unlicense *.mpy .idea __pycache__ @@ -8,4 +11,4 @@ bundles *.DS_Store .eggs dist -**/*.egg-info \ No newline at end of file +**/*.egg-info 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 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/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) diff --git a/adafruit_displayio_sh1107.py b/adafruit_displayio_sh1107.py index 310f1e0..0b22b73 100644 --- a/adafruit_displayio_sh1107.py +++ b/adafruit_displayio_sh1107.py @@ -46,11 +46,10 @@ 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 ) -# 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._is_awake = True # Display starts in active state (_INIT_SEQUENCE) + + @property + 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 + + 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._is_awake: + self.bus.send(int(0xAE), "") # 0xAE = display off, sleep mode + self._is_awake = False + + def wake(self): + """ + Wake display from sleep mode + """ + if not self._is_awake: + self.bus.send(int(0xAF), "") # 0xAF = display on + self._is_awake = True diff --git a/examples/displayio_sh1107_game_of_life.py b/examples/displayio_sh1107_game_of_life.py index 6ba794b..56206e1 100644 --- a/examples/displayio_sh1107_game_of_life.py +++ b/examples/displayio_sh1107_game_of_life.py @@ -1,8 +1,12 @@ +# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries +# +# SPDX-License-Identifier: Unlicense """ Author: Mark Roberts (mdroberts1243) from Adafruit code 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 db36fa8..929d4cb 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 diff --git a/examples/displayio_sh1107_simpletest.py b/examples/displayio_sh1107_simpletest.py index 89aa34a..f4f14d6 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 @@ -5,6 +8,7 @@ """ + import board import displayio import terminalio diff --git a/setup.py b/setup.py index cd57940..edc785f 100644 --- a/setup.py +++ b/setup.py @@ -10,16 +10,17 @@ 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( @@ -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