@@ -243,7 +243,6 @@ def __init__(
243
243
layout_class : type [KeyboardLayoutBase ] = KeyboardLayoutUS ,
244
244
keycode_class : type [Keycode ] = Keycode ,
245
245
):
246
-
247
246
if rotation not in (0 , 90 , 180 , 270 ):
248
247
raise ValueError ("Only 90 degree rotations are supported." )
249
248
@@ -291,6 +290,7 @@ def _keys_and_pixels(
291
290
if not isinstance (board .DISPLAY , type (None )):
292
291
self .display = board .DISPLAY
293
292
self .display .rotation = rotation
293
+ self ._display_sleep = False
294
294
295
295
# Define audio:
296
296
self ._speaker_enable = digitalio .DigitalInOut (board .SPEAKER_ENABLE )
@@ -324,6 +324,30 @@ def _keys_and_pixels(
324
324
# No MIDI ports available.
325
325
self ._midi = None
326
326
327
+ @property
328
+ def display_sleep (self ) -> bool :
329
+ """The power saver mode of the display. Set it to put the display to
330
+ sleep or wake it up again.
331
+
332
+ If the display is put to sleep, it stops the OLED drive and greatly
333
+ reduces its power usage. The display mode and current content of the
334
+ display are still kept in the memory of the displays microprocessor and
335
+ can be updated nevertheless.
336
+ """
337
+ return self ._display_sleep
338
+
339
+ @display_sleep .setter
340
+ def display_sleep (self , sleep : bool ) -> None :
341
+ if self ._display_sleep == sleep :
342
+ return
343
+ # See https://cdn-shop.adafruit.com/product-files/5228/5223-ds.pdf#page=13
344
+ if sleep :
345
+ command = 0xAE
346
+ else :
347
+ command = 0xAF
348
+ self .display .bus .send (command , b"" )
349
+ self ._display_sleep = sleep
350
+
327
351
@property
328
352
def pixels (self ) -> Optional [_PixelMapLite ]:
329
353
"""Sequence-like object representing the twelve NeoPixel LEDs in a 3 x 4 grid on the
0 commit comments