Skip to content

Commit 7bccc3c

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

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

adafruit_macropad.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,7 @@ def _keys_and_pixels(
291291
if not isinstance(board.DISPLAY, type(None)):
292292
self.display = board.DISPLAY
293293
self.display.rotation = rotation
294+
self._display_sleep = False
294295

295296
# Define audio:
296297
self._speaker_enable = digitalio.DigitalInOut(board.SPEAKER_ENABLE)
@@ -324,6 +325,25 @@ def _keys_and_pixels(
324325
# No MIDI ports available.
325326
self._midi = None
326327

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

0 commit comments

Comments
 (0)