Skip to content

Commit 8226c2a

Browse files
authored
Merge pull request #19 from SAK917/master
Implement SSD1306 sleep/wake functionality
2 parents 62a513c + 1f6d0d7 commit 8226c2a

File tree

1 file changed

+32
-2
lines changed

1 file changed

+32
-2
lines changed

adafruit_displayio_ssd1306.py

+32-2
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@
4848
b"\xda\x01\x12" # Set com configuration
4949
b"\xdb\x01\x40" # Set vcom configuration
5050
b"\x8d\x01\x14" # Enable charge pump
51-
b"\xAF\x00\x00" # DISPLAY_ON
51+
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)