Skip to content

Initial release #1

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 15 commits into from
Oct 11, 2018
Merged

Initial release #1

merged 15 commits into from
Oct 11, 2018

Conversation

kattni
Copy link
Contributor

@kattni kattni commented Oct 8, 2018

No description provided.

@kattni
Copy link
Contributor Author

kattni commented Oct 8, 2018

Tested on Hollowing with invalid file present on board.

self._file_list = self._get_filenames()
if self._order == SlideShow.RANDOM:
self._file_list = sorted(self._file_list, key=lambda x: random.random())
self._images = self._get_next_image()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unindent. Shouldn't be in the if. Looks like that was my bad. I only tested random. :(

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was testing it with alphabetical and it seemed to be working so I didn't think anything of it. On closer investigation it was only mostly working. Fixed.

Copy link
Collaborator

@sommersoft sommersoft left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple small things.

With regards to type-checking for arguments, there are a couple more spots you could check (dwell is int), but I think they'll fail with standard exceptions anyway.

FADE_IN = 0
SHOW_IMG = 1
FADE_OUT = 2
LOAD_IMG = 3
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are all internal variables. Should start with _? (_FADE_IN)

Also, now that I read further down...these should also move outside of the SlideShow() class. The variables themselves don't change, the self._current_state does, so you don't need to recreate them for every instance of the class. Calls to self.FADE_IN etc will also need to change after that.

return self._order

@order.setter
def order(self, order):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there are only 2 options, I would check that the supplied argument meets one of them:

def order(self, order):
    if not order in [ALPHA, RANDOM]:
        raise ValueError("Order must be either 'RANDOM' or 'ALPHA'")

This should also be checked in __init__.

Copy link
Member

@tannewt tannewt Oct 8, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

__init__ can do self.order = order to call the setter instead of setting _order directly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So every instance of _order gets changed to order then?

kattni added 3 commits October 9, 2018 16:29
Added ability to choose whether slideshow will automatically cycle
through the images or whether you would like to specify an input
to manually cycle through the slideshow. Added backlight brightness
level control. Added ability to cycle forwards or backwards through
image list. Added ability to turn off the fade in/out effects
during image transition - this means the redraw effect of the image
changing is visible, but it also means you can advance more quickly
through the list if you choose to. Documentation updated. Various
linting fixes.
@jerryneedell
Copy link
Contributor

I found a minor bug in the slideshow_simpletest.py:

change
slideshow.order = slideshow.ALPHA
to
slideshow.order = adafruit_slideshow.PlayBackMode.ALPHA

@kattni
Copy link
Contributor Author

kattni commented Oct 9, 2018

@jerryneedell I already found that and updated it. Thanks for catching it though! Travis failed on it for me.

Copy link
Contributor

@caternuson caternuson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found a few minor things.

while slideshow.update():
pass

Example code for Hollowing Express. Sets ``dwell`` to 0 seconds, turns ``auto_advance`` off,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/Hollowing/Hallowing

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:face_palm: Thank you for catching this.


**Hardware:**

* `Adafruit Hollowing M0 Express <https://www.adafruit.com/product/3900>`_
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/Hollowing/Hallowing

if slideshow should auto play, ``False`` if you want to control advancement
manually. Default is ``True``.

Example code for Hollowing Express. With this example, the slideshow will play through once
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/Hollowing/Hallowing

docs/index.rst Outdated
.. toctree::
:caption: Related Products

Adafruit Hollowing M0 Express <https://www.adafruit.com/product/3900>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/Hollowing/Hallowing

Copy link
Member

@tannewt tannewt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These internals are more complicated than they need to be. In particular:

  • There aren't really 5 states, there are two: waiting or advancing. That way you only need to track the time.
  • You don't need a generator. Instead, just save the current index on self.

I've gone through and reworked this PR and PRed to it (so meta!) here: kattni#1 The PR also includes fixes for these inline comments.

Overall the API looked really good! I only changed how brightness works. Thanks for getting it this far! All the knobs are nice!


# pylint: disable=too-many-arguments
def __init__(self, folder="/", order=PlayBackMode.RANDOM, loop=True, dwell=3, fade_effect=True,
auto_advance=True):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about adding *, after self to force these as kwargs? Otherwise things can get confusing with the multiple boolean options.

if self.order == PlayBackMode.RANDOM:
self._file_list = sorted(self._file_list, key=lambda x: random.random())

def backlight_level_up(self, step=16):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not have a max_brightness property instead? That way you can just += to change it.

except ValueError as error:
print("Incompatible image:", imagename, str(error))

return True
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why return anything?

self._show_bmp(imagename)
self._current_state = _FADE_IN
except ValueError as error:
print("Incompatible image:", imagename, str(error))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its weird to print from within a library. I'd suggest either now catching the exception or silently passing.

odb = displayio.OnDiskBitmap(image)
face = displayio.Sprite(odb, pixel_shader=displayio.ColorConverter(), position=(0, 0))
self._group.append(face)
board.DISPLAY.wait_for_frame()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will close the image file too early. It should be open until the sprite is popped from the group. We don't check this currently but it should check and throw an error.

slideshow.loop = False

# Set the order to alphabetical.
slideshow.order = PlayBackMode.ALPHA
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't the examples use the constructor arguments instead? I'd only expect the properties to be used when changing from within the loop.

time.sleep(0.01)

def update(self):
"""Updates the slideshow to the next image."""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would change this comment because it won't always go to the next image.

@tannewt
Copy link
Member

tannewt commented Oct 10, 2018

The extra states jumped out at me because each if for the current state wasn't exclusive (elif). That meant that in practice you'd transition through multiple states (_FADE_OUT always goes to _LOAD_IMAGE for example) in a single call each time, which is a good sign you don't need them separate.

Copy link
Member

@tannewt tannewt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Thanks for taking my changes

@tannewt tannewt merged commit 0ac5f42 into adafruit:master Oct 11, 2018
@kattni
Copy link
Contributor Author

kattni commented Oct 11, 2018

In commit caee24a, added the ability to call the name of the current image being displayed with slideshow.current_image_name. Apparently using markdown in a commit message caused it to not include the rest of the commit message.

kattni pushed a commit that referenced this pull request Nov 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants