From 92a8e4a2a378b2778bbd77fd07b7504889ec7180 Mon Sep 17 00:00:00 2001 From: PRC-SAK Date: Wed, 17 Feb 2021 22:33:04 -0800 Subject: [PATCH 1/2] Remove extra \x00 from DISPLAY ON in _INIT_SEQUENCE --- adafruit_displayio_ssd1306.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_displayio_ssd1306.py b/adafruit_displayio_ssd1306.py index 4b704f4..f8ae937 100644 --- a/adafruit_displayio_ssd1306.py +++ b/adafruit_displayio_ssd1306.py @@ -48,7 +48,7 @@ b"\xda\x01\x12" # Set com configuration b"\xdb\x01\x40" # Set vcom configuration b"\x8d\x01\x14" # Enable charge pump - b"\xAF\x00\x00" # DISPLAY_ON + b"\xAF\x00" # DISPLAY_ON ) # pylint: disable=too-few-public-methods From 1f6d0d7e36f23547a4e57c63d921c47deefb4e58 Mon Sep 17 00:00:00 2001 From: PRC-SAK Date: Thu, 18 Feb 2021 00:37:17 -0800 Subject: [PATCH 2/2] 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 --- adafruit_displayio_ssd1306.py | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/adafruit_displayio_ssd1306.py b/adafruit_displayio_ssd1306.py index f8ae937..4fe7cee 100644 --- a/adafruit_displayio_ssd1306.py +++ b/adafruit_displayio_ssd1306.py @@ -51,7 +51,7 @@ b"\xAF\x00" # DISPLAY_ON ) -# pylint: disable=too-few-public-methods + class SSD1306(displayio.Display): """SSD1306 driver""" @@ -78,3 +78,33 @@ def __init__(self, bus, **kwargs): brightness_command=0x81, single_byte_bounds=True, ) + self._is_awake = True # Display starts in active state (_INIT_SEQUENCE) + + @property + def is_awake(self): + """ + The power state of the display. (read-only) + + True if the display is active, False if in sleep mode. + """ + return self._is_awake + + def sleep(self): + """ + Put display into sleep mode + + Display uses < 10uA in sleep mode + Display remembers display data and operation mode active prior to sleeping + MP can access (update) the built-in display RAM + """ + if self._is_awake: + self.bus.send(int(0xAE), "") # 0xAE = display off, sleep mode + self._is_awake = False + + def wake(self): + """ + Wake display from sleep mode + """ + if not self._is_awake: + self.bus.send(int(0xAF), "") # 0xAF = display on + self._is_awake = True