Skip to content

Commit 59efbef

Browse files
authored
Merge pull request #2 from SAK917/main
Implement SH1107 sleep/wake functionality
2 parents ce37ae0 + 7f3a7b2 commit 59efbef

9 files changed

+63
-11
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
2+
#
3+
# SPDX-License-Identifier: Unlicense
14
*.mpy
25
.idea
36
__pycache__
@@ -8,4 +11,4 @@ bundles
811
*.DS_Store
912
.eggs
1013
dist
11-
**/*.egg-info
14+
**/*.egg-info

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44

55
repos:
66
- repo: https://github.com/python/black
7-
rev: latest
7+
rev: 20.8b1
88
hooks:
99
- id: black
1010
- repo: https://github.com/fsfe/reuse-tool
11-
rev: latest
11+
rev: v0.12.1
1212
hooks:
1313
- id: reuse
1414
- repo: https://github.com/pre-commit/pre-commit-hooks

.pylintrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
2+
#
3+
# SPDX-License-Identifier: Unlicense
14
[MASTER]
25

36
# A comma-separated list of package or module names from where C extensions may

README.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ Usage Example
6464
import displayio
6565
import terminalio
6666
import bitmap_label as label # from adafruit_display_text
67-
import mdroberts1243_displayio_sh1107
67+
import adafruit_displayio_sh1107
6868
6969
displayio.release_displays()
7070
#oled_reset = board.D9
@@ -78,7 +78,7 @@ Usage Example
7878
HEIGHT = 64
7979
BORDER = 2
8080
81-
display = mdroberts1243_displayio_sh1107.SH1107(display_bus, width=WIDTH, height=HEIGHT)
81+
display = adafruit_displayio_sh1107.SH1107(display_bus, width=WIDTH, height=HEIGHT)
8282
8383
# Make the display context
8484
splash = displayio.Group(max_size=10)

adafruit_displayio_sh1107.py

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,10 @@
4646
b"\xb0\x00" # set page address = 0 (POR)
4747
b"\xa4\x00" # entire display off, retain RAM, normal status (POR)
4848
b"\xa6\x00" # normal (not reversed) display
49-
b"\xAF\x00\x00" # DISPLAY_ON
49+
b"\xaf\x00" # DISPLAY_ON
5050
)
5151

5252

53-
# pylint: disable=too-few-public-methods
5453
class SH1107(displayio.Display):
5554
"""SSD1107 driver"""
5655

@@ -73,3 +72,36 @@ def __init__(self, bus, **kwargs):
7372
# set page address = 0xB0 - 0xBF (16 pages)
7473
SH1107_addressing=True,
7574
)
75+
self._is_awake = True # Display starts in active state (_INIT_SEQUENCE)
76+
77+
@property
78+
def is_awake(self):
79+
"""
80+
The power state of the display. (read-only)
81+
82+
True if the display is active, False if in sleep mode.
83+
"""
84+
return self._is_awake
85+
86+
def sleep(self):
87+
"""
88+
Put display into sleep mode
89+
90+
The display uses < 5uA in sleep mode
91+
Sleep mode does the following:
92+
1) Stops the oscillator and DC-DC circuits
93+
2) Stops the OLED drive
94+
3) Remembers display data and operation mode active prior to sleeping
95+
4) The MP can access (update) the built-in display RAM
96+
"""
97+
if self._is_awake:
98+
self.bus.send(int(0xAE), "") # 0xAE = display off, sleep mode
99+
self._is_awake = False
100+
101+
def wake(self):
102+
"""
103+
Wake display from sleep mode
104+
"""
105+
if not self._is_awake:
106+
self.bus.send(int(0xAF), "") # 0xAF = display on
107+
self._is_awake = True

examples/displayio_sh1107_game_of_life.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1+
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
2+
#
3+
# SPDX-License-Identifier: Unlicense
14
"""
25
Author: Mark Roberts (mdroberts1243) from Adafruit code
36
Conway's game of life.
47
"""
58

9+
610
import random
711
import time
812

examples/displayio_sh1107_random_motion.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
2+
#
3+
# SPDX-License-Identifier: Unlicense
14
"""
25
Author: Mark Roberts (mdroberts1243) from Adafruit code
36
This test will initialize the display using displayio and draw a solid white

examples/displayio_sh1107_simpletest.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1+
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
2+
#
3+
# SPDX-License-Identifier: Unlicense
14
"""
25
Author: Mark Roberts (mdroberts1243) from Adafruit code
36
This test will initialize the display using displayio and draw a solid white
47
background, a smaller black rectangle, miscellaneous stuff and some white text.
58
69
"""
710

11+
812
import board
913
import displayio
1014
import terminalio

setup.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,17 @@
1010
https://github.com/pypa/sampleproject
1111
"""
1212

13-
from setuptools import setup, find_packages
1413

1514
# To use a consistent encoding
16-
from codecs import open
15+
from codecs import open as open_codec
1716
from os import path
1817

18+
from setuptools import setup
19+
1920
here = path.abspath(path.dirname(__file__))
2021

2122
# Get the long description from the README file
22-
with open(path.join(here, "README.rst"), encoding="utf-8") as f:
23+
with open_codec(path.join(here, "README.rst"), encoding="utf-8") as f:
2324
long_description = f.read()
2425

2526
setup(
@@ -34,7 +35,9 @@
3435
# Author details
3536
author="Adafruit Industries",
3637
author_email="[email protected]",
37-
install_requires=["Adafruit-Blinka",],
38+
install_requires=[
39+
"Adafruit-Blinka",
40+
],
3841
# Choose your license
3942
license="MIT",
4043
# See https://pypi.python.org/pypi?%3Aaction=list_classifiers

0 commit comments

Comments
 (0)