Skip to content

Commit 624becc

Browse files
committed
feat: Added property for OLED display sleep
1 parent 38ee9b5 commit 624becc

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

adafruit_macropad.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,6 @@ def __init__(
243243
layout_class: type[KeyboardLayoutBase] = KeyboardLayoutUS,
244244
keycode_class: type[Keycode] = Keycode,
245245
):
246-
247246
if rotation not in (0, 90, 180, 270):
248247
raise ValueError("Only 90 degree rotations are supported.")
249248

@@ -291,6 +290,7 @@ def _keys_and_pixels(
291290
if not isinstance(board.DISPLAY, type(None)):
292291
self.display = board.DISPLAY
293292
self.display.rotation = rotation
293+
self._display_sleep = False
294294

295295
# Define audio:
296296
self._speaker_enable = digitalio.DigitalInOut(board.SPEAKER_ENABLE)
@@ -324,6 +324,25 @@ def _keys_and_pixels(
324324
# No MIDI ports available.
325325
self._midi = None
326326

327+
@property
328+
def display_sleep(self) -> bool:
329+
"""Whether the display is currently asleep."""
330+
return self._display_sleep
331+
332+
@display_sleep.setter
333+
def display_sleep(self, sleep: bool) -> None:
334+
"""Change the sleep status of the display.
335+
336+
If the display is put to sleep, it stops the OLED drive and greatly
337+
reduces its power usage. The current content of the display is kept
338+
in the memory and can still be updated.
339+
"""
340+
if self._display_sleep == sleep:
341+
return
342+
command = 0xAE if sleep else 0xAF
343+
self.display.bus.send(command, b"")
344+
self._display_sleep = sleep
345+
327346
@property
328347
def pixels(self) -> Optional[_PixelMapLite]:
329348
"""Sequence-like object representing the twelve NeoPixel LEDs in a 3 x 4 grid on the

0 commit comments

Comments
 (0)