Skip to content

Switch up backlight and Sprite/TileGrid #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 31, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions adafruit_slideshow.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ class SlideShow:
slideshow.brightness -= 0.001
"""

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

# Setup the display
self._group = displayio.Group()
self._display = display
display.show(self._group)

self._backlight_pwm = backlight_pwm
if not backlight_pwm and fade_effect:
self._display.auto_brightness = False

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

def _set_backlight(self, brightness):
full_brightness = 2 ** 16 - 1
self._backlight_pwm.duty_cycle = int(full_brightness * brightness)
if self._backlight_pwm:
full_brightness = 2 ** 16 - 1
self._backlight_pwm.duty_cycle = int(full_brightness * brightness)
else:
try:
self._display.brightness = brightness
except RuntimeError:
pass

@property
def brightness(self):
Expand Down Expand Up @@ -303,7 +313,7 @@ def advance(self):
if not odb:
raise RuntimeError("No valid images")

sprite = displayio.Sprite(odb, pixel_shader=displayio.ColorConverter(), position=(0, 0))
sprite = self._sprite_class(odb, pixel_shader=displayio.ColorConverter(), position=(0, 0))
self._group.append(sprite)
self._display.wait_for_frame()

Expand Down