Skip to content

Implement SSD1306 sleep/wake functionality #19

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 18, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 32 additions & 2 deletions adafruit_displayio_ssd1306.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@
b"\xda\x01\x12" # Set com configuration
b"\xdb\x01\x40" # Set vcom configuration
b"\x8d\x01\x14" # Enable charge pump
b"\xAF\x00\x00" # DISPLAY_ON
b"\xAF\x00" # DISPLAY_ON
)

# pylint: disable=too-few-public-methods

class SSD1306(displayio.Display):
"""SSD1306 driver"""

Expand All @@ -78,3 +78,33 @@ def __init__(self, bus, **kwargs):
brightness_command=0x81,
single_byte_bounds=True,
)
self._is_awake = True # Display starts in active state (_INIT_SEQUENCE)

@property
def is_awake(self):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename to awake

"""
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):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be part of the awake property = setting it to True or False puts it to sleep or not

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"""
Put display into sleep mode

Display uses < 10uA in sleep mode
Display remembers display data and operation mode active prior to sleeping
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