Skip to content

Commit 1f6d0d7

Browse files
committed
Implement sleep/wake states for display
Added: self._is_awake - stores current state of the display is_awake - property that returns the current state sleep() - method that puts display to sleep wake() - method that wakes display from sleep
1 parent 92a8e4a commit 1f6d0d7

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

adafruit_displayio_ssd1306.py

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
b"\xAF\x00" # DISPLAY_ON
5252
)
5353

54-
# pylint: disable=too-few-public-methods
54+
5555
class SSD1306(displayio.Display):
5656
"""SSD1306 driver"""
5757

@@ -78,3 +78,33 @@ def __init__(self, bus, **kwargs):
7878
brightness_command=0x81,
7979
single_byte_bounds=True,
8080
)
81+
self._is_awake = True # Display starts in active state (_INIT_SEQUENCE)
82+
83+
@property
84+
def is_awake(self):
85+
"""
86+
The power state of the display. (read-only)
87+
88+
True if the display is active, False if in sleep mode.
89+
"""
90+
return self._is_awake
91+
92+
def sleep(self):
93+
"""
94+
Put display into sleep mode
95+
96+
Display uses < 10uA in sleep mode
97+
Display remembers display data and operation mode active prior to sleeping
98+
MP can access (update) the built-in display RAM
99+
"""
100+
if self._is_awake:
101+
self.bus.send(int(0xAE), "") # 0xAE = display off, sleep mode
102+
self._is_awake = False
103+
104+
def wake(self):
105+
"""
106+
Wake display from sleep mode
107+
"""
108+
if not self._is_awake:
109+
self.bus.send(int(0xAF), "") # 0xAF = display on
110+
self._is_awake = True

0 commit comments

Comments
 (0)