Skip to content

Commit c2ad8e1

Browse files
authored
Merge pull request #10 from tannewt/update_for_4
Switch up backlight and Sprite/TileGrid
2 parents d188670 + 25479c8 commit c2ad8e1

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

adafruit_slideshow.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ class SlideShow:
149149
slideshow.brightness -= 0.001
150150
"""
151151

152-
def __init__(self, display, backlight_pwm, *, folder="/", order=PlayBackOrder.ALPHABETICAL,
152+
def __init__(self, display, backlight_pwm=None, *, folder="/", order=PlayBackOrder.ALPHABETICAL,
153153
loop=True, dwell=3, fade_effect=True, auto_advance=True,
154154
direction=PlayBackDirection.FORWARD):
155155
self.loop = loop
@@ -184,13 +184,17 @@ def __init__(self, display, backlight_pwm, *, folder="/", order=PlayBackOrder.AL
184184
self._current_image = -1
185185
self._image_file = None
186186
self._brightness = 0.5
187+
# 4.0.0 Beta 2 replaces Sprite with TileGrid so use either.
188+
self._sprite_class = getattr(displayio, "Sprite", displayio.TileGrid)
187189

188190
# Setup the display
189191
self._group = displayio.Group()
190192
self._display = display
191193
display.show(self._group)
192194

193195
self._backlight_pwm = backlight_pwm
196+
if not backlight_pwm and fade_effect:
197+
self._display.auto_brightness = False
194198

195199
# Show the first image
196200
self.advance()
@@ -221,8 +225,14 @@ def _reorder_images(self):
221225
self._file_list = sorted(self._file_list, key=lambda x: random.random())
222226

223227
def _set_backlight(self, brightness):
224-
full_brightness = 2 ** 16 - 1
225-
self._backlight_pwm.duty_cycle = int(full_brightness * brightness)
228+
if self._backlight_pwm:
229+
full_brightness = 2 ** 16 - 1
230+
self._backlight_pwm.duty_cycle = int(full_brightness * brightness)
231+
else:
232+
try:
233+
self._display.brightness = brightness
234+
except RuntimeError:
235+
pass
226236

227237
@property
228238
def brightness(self):
@@ -303,7 +313,7 @@ def advance(self):
303313
if not odb:
304314
raise RuntimeError("No valid images")
305315

306-
sprite = displayio.Sprite(odb, pixel_shader=displayio.ColorConverter(), position=(0, 0))
316+
sprite = self._sprite_class(odb, pixel_shader=displayio.ColorConverter(), position=(0, 0))
307317
self._group.append(sprite)
308318
self._display.wait_for_frame()
309319

0 commit comments

Comments
 (0)