Skip to content

Commit

Permalink
Merge pull request #2 from SAK917/main
Browse files Browse the repository at this point in the history
Implement SH1107 sleep/wake functionality
  • Loading branch information
tannewt authored Feb 4, 2021
2 parents ce37ae0 + 7f3a7b2 commit 59efbef
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 11 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
#
# SPDX-License-Identifier: Unlicense
*.mpy
.idea
__pycache__
Expand All @@ -8,4 +11,4 @@ bundles
*.DS_Store
.eggs
dist
**/*.egg-info
**/*.egg-info
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions .pylintrc
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
36 changes: 34 additions & 2 deletions adafruit_displayio_sh1107.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""

Expand All @@ -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
4 changes: 4 additions & 0 deletions examples/displayio_sh1107_game_of_life.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down
3 changes: 3 additions & 0 deletions examples/displayio_sh1107_random_motion.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 4 additions & 0 deletions examples/displayio_sh1107_simpletest.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
# 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
background, a smaller black rectangle, miscellaneous stuff and some white text.
"""


import board
import displayio
import terminalio
Expand Down
11 changes: 7 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -34,7 +35,9 @@
# Author details
author="Adafruit Industries",
author_email="[email protected]",
install_requires=["Adafruit-Blinka",],
install_requires=[
"Adafruit-Blinka",
],
# Choose your license
license="MIT",
# See https://pypi.python.org/pypi?%3Aaction=list_classifiers
Expand Down

0 comments on commit 59efbef

Please sign in to comment.