8000 Add property for OLED display sleep mode by kalehmann · Pull Request #44 · adafruit/Adafruit_CircuitPython_MacroPad · GitHub
[go: up one dir, main page]

Skip to content

Add property for OLED display sleep mode #44

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 1 commit into from
May 1, 2023
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
26 changes: 25 additions & 1 deletion adafruit_macropad.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,6 @@ def __init__(
layout_class: type[KeyboardLayoutBase] = KeyboardLayoutUS,
keycode_class: type[Keycode] = Keycode,
):

if rotation not in (0, 90, 180, 270):
raise ValueError("Only 90 degree rotations are supported.")

Expand Down Expand Up @@ -291,6 +290,7 @@ def _keys_and_pixels(
if not isinstance(board.DISPLAY, type(None)):
self.display = board.DISPLAY
self.display.rotation = rotation
self._display_sleep = False

# Define audio:
self._speaker_enable = digitalio.DigitalInOut(board.SPEAKER_ENABLE)
Expand Down Expand Up @@ -324,6 +324,30 @@ def _keys_and_pixels(
# No MIDI ports available.
self._midi = None

@property
def display_sleep(self) -> bool:
"""The power saver mode of the display. Set it to put the display to
sleep or wake it up again.

If the display is put to sleep, it stops the OLED drive and greatly
reduces its power usage. The display mode and current content of the
display are still kept in the memory of the displays microprocessor and
can be updated nevertheless.
"""
return self._display_sleep

@display_sleep.setter
def display_sleep(self, sleep: bool) -> None:
if self._display_sleep == sleep:
return
# See https://cdn-shop.adafruit.com/product-files/5228/5223-ds.pdf#page=13
if sleep:
command = 0xAE
else:
command = 0xAF
self.display.bus.send(command, b"")
self._display_sleep = sleep

@property
def pixels(self) -> Optional[_PixelMapLite]:
"""Sequence-like object representing the twelve NeoPixel LEDs in a 3 x 4 grid on the
Expand Down
0