Skip to content

Commit f1184d8

Browse files
committed
Replace depreciated .show() & changes to displayio
1 parent 3cbac14 commit f1184d8

File tree

3 files changed

+55
-12
lines changed

3 files changed

+55
-12
lines changed

README.rst

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,14 @@ Usage Example
6464
6565
import board
6666
import displayio
67+
# Starting in CircuitPython 9.x fourwire will be a seperate internal library
68+
# rather than a component of the displayio library
69+
try:
70+
import fourwire
71+
# Use for I2C
72+
# import i2cdisplaybus
73+
except ImportError:
74+
pass
6775
import terminalio
6876
from adafruit_display_text import label
6977
import adafruit_displayio_ssd1305
@@ -74,12 +82,24 @@ Usage Example
7482
spi = board.SPI()
7583
oled_cs = board.D5
7684
oled_dc = board.D6
77-
display_bus = displayio.FourWire(spi, command=oled_dc, chip_select=oled_cs,
78-
baudrate=1000000, reset=board.D9)
85+
# Check if the version of CircuitPython being used still utilizes FourWise as a
86+
# component of the displayio library
87+
if "FourWire" in dir(displayio):
88+
display_bus = displayio.FourWire(
89+
spi, command=oled_dc, chip_select=oled_cs, baudrate=1000000, reset=board.D9
90+
)
91+
else:
92+
display_bus = fourwire.FourWire(
93+
spi, command=oled_dc, chip_select=oled_cs, baudrate=1000000, reset=board.D9
94+
)
7995
8096
# Use for I2C
8197
# i2c = board.I2C()
98+
#
99+
# For CircuitPython before 9.x
82100
# display_bus = displayio.I2CDisplay(i2c, device_address=0x3c)
101+
# For CircuitPython 9.x and later
102+
# display_bus = I2CDisplayBus(i1c, device_address=0x3c)
83103
84104
WIDTH = 128
85105
HEIGHT = 64 # Change to 32 if needed
@@ -90,7 +110,7 @@ Usage Example
90110
91111
# Make the display context
92112
splash = displayio.Group()
93-
display.show(splash)
113+
display.root_group = splash
94114
95115
color_bitmap = displayio.Bitmap(display.width, display.height, 1)
96116
color_palette = displayio.Palette(1)

adafruit_displayio_ssd1305.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,18 @@
2929

3030
# imports
3131

32-
import displayio
32+
# Starting in CircuitPython 9.x fourwire will be a seperate internal library
33+
# rather than a component of the displayio library
34+
try:
35+
# pylint: disable=useless-import-alias
36+
from fourwire import FourWire as FourWire
37+
from busdisplay import BusDisplay as BusDisplay
38+
from i2cdisplaybus import I2CDisplayBus as I2CDisplayBus
39+
except ImportError:
40+
# pylint: disable=useless-import-alias
41+
from displayio import FourWire as FourWire
42+
from displayio import Display as BusDisplay
43+
from displayio import I2CDisplay as I2CDisplayBus
3344

3445
try:
3546
from typing import Union
@@ -61,7 +72,7 @@
6172

6273

6374
# pylint: disable=too-few-public-methods
64-
class SSD1305(displayio.Display):
75+
class SSD1305(BusDisplay):
6576
"""
6677
SSD1305 driver
6778
@@ -71,9 +82,7 @@ class SSD1305(displayio.Display):
7182
One of (0, 90, 180, 270)
7283
"""
7384

74-
def __init__(
75-
self, bus: Union[displayio.Fourwire, displayio.I2CDisplay], **kwargs
76-
) -> None:
85+
def __init__(self, bus: Union[FourWire, I2CDisplayBus], **kwargs) -> None:
7786
colstart = 0
7887
# Patch the init sequence for 32 pixel high displays.
7988
init_sequence = bytearray(_INIT_SEQUENCE)

examples/displayio_ssd1305_simpletest.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@
88

99
import board
1010
import displayio
11+
12+
# Starting in CircuitPython 9.x fourwire will be a seperate internal library
13+
# rather than a component of the displayio library
14+
try:
15+
import fourwire
16+
except ImportError:
17+
pass
1118
import terminalio
1219
from adafruit_display_text import label
1320
import adafruit_displayio_ssd1305
@@ -21,9 +28,16 @@
2128
spi = board.SPI()
2229
oled_cs = board.D5
2330
oled_dc = board.D6
24-
display_bus = displayio.FourWire(
25-
spi, command=oled_dc, chip_select=oled_cs, baudrate=1000000, reset=oled_reset
26-
)
31+
# Check if the version of CircuitPython being used still utilizes FourWise as a
32+
# component of the displayio library
33+
if "FourWire" in dir(displayio):
34+
display_bus = displayio.FourWire(
35+
spi, command=oled_dc, chip_select=oled_cs, baudrate=1000000, reset=oled_reset
36+
)
37+
else:
38+
display_bus = fourwire.FourWire(
39+
spi, command=oled_dc, chip_select=oled_cs, baudrate=1000000, reset=oled_reset
40+
)
2741

2842
# Use for I2C
2943
# i2c = board.I2C() # uses board.SCL and board.SDA
@@ -39,7 +53,7 @@
3953

4054
# Make the display context
4155
splash = displayio.Group()
42-
display.show(splash)
56+
display.root_group = splash
4357

4458
color_bitmap = displayio.Bitmap(display.width, display.height, 1)
4559
color_palette = displayio.Palette(1)

0 commit comments

Comments
 (0)