Skip to content

Fix business card display #20

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 5 commits into from
Feb 19, 2020

Conversation

nnja
Copy link
Contributor

@nnja nnja commented Feb 14, 2020

I noticed strange behavior when using the business card function in this library.

The text would display, then hide, then display again. Additionally, the image elements wouldn't appear at the same time.

It looked like this:
circuitpy_before

I made some updates to make the text appear smoothly with the background. It now looks like this:

circuit_py_after

Notes:

  • I removed the call to wait_for_frame(), since the release notes for CircuitPython 5.0.0 Alpha 2 say it's no longer necessary.
  • Removed the target_frames_per_second argument to refresh, since that's the default value.

As a side effect, the text displayed no longer has a black background. That might have been a bug in the original code, since I couldn't find a background color property on adafruit_display_text.label.

Tested on a PyBadge LC.

nnja added 4 commits February 14, 2020 14:36
Per the release notes for CircuitPython 5.0.0 Alpha 2, calling
wait_for_frame is no longer needed, and calling refresh() should
accomplish the same goal.

Additionally, target_frames_per_second is already set to 60 by
default.
When displaying the business card, group the calls to add the
background bitmap and the labels to the group in the same place in
code, allowing them to display at the same time.

This change has removed the black background around the labels, which
appeared to be caused by a bug, since labels don't have a background
color property.
@makermelissa
Copy link
Collaborator

Can you test on the latest stable release (4.1.2)? I don't believe display.refresh() is a function on there, which is why we have the try block.

@nnja
Copy link
Contributor Author

nnja commented Feb 17, 2020

@makermelissa That function is in fact missing in 4.1.2.

I didn't release that the latest version of the libraries supports both CircuitPython 4 and 5. Added back the try/except, and added some comments for clarity. I can remove the comments if you think they're unnecessary.

@makermelissa
Copy link
Collaborator

Thanks. The comments are good. Once we're at 5.0.0 stable, we can change it so it only uses the CP5 method. :)

@makermelissa
Copy link
Collaborator

Hi, tested on a PyGamer with CP 5.0 Beta 5 and it appears to draw it twice still. Black background is gone still, which is good.

@caternuson
Copy link
Contributor

As maybe another way to do this, but 5.x only, try setting display.auto_refresh = False before doing all the group appends, and then setting back to True at the end to show them. This is how I dealt with a similar issue here:
https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/master/TFT_Gizmo_Candy_Hearts/candy_hearts.py#L59

@makermelissa
Copy link
Collaborator

makermelissa commented Feb 18, 2020

The label redrawing issue is fixed on CP 4.0 with this PR. However, while holding down the button on CP 5, it will continue to draw the label over and over. Maybe @caternuson's suggestion would fix it.

@nnja
Copy link
Contributor Author

nnja commented Feb 19, 2020

My goal with this PR was to fix the double redraw / blinking when initially navigating to this screen with one button press. I think redrawing while the button is held down is OK, since I don't think holding down the button is expected user behavior.

That said, I did try @caternuson's approach and it does work fine when the button is held down.

Unfortunately, it made the code overly complex. I don't think it's worth complicating things if the code is temporary until CP5 is out of beta but I'm happy to put in the patch if that's what would work best for the library.

Additionally, using CP5 I still had to call self.display.refresh() after setting self.display.auto_refresh = True, otherwise the background image wouldn't appear. I'm not sure if that's expected behavior or a potential bug.

For reference, here's the code I tried:

        business_card_splash = displayio.Group(max_size=4)
        self.display.show(business_card_splash)
        with open(image_name, "rb") as file_name:
            on_disk_bitmap = displayio.OnDiskBitmap(file_name)
            face_image = displayio.TileGrid(on_disk_bitmap, pixel_shader=displayio.ColorConverter())

            is_cp_version_5 = hasattr(self.display, "auto_refresh")
            if is_cp_version_5:
                # Temporary turn off auto refresh while we change some things
                self.display.auto_refresh = False

            # Add the background and the text to the splash
            business_card_splash.append(face_image)
            for group in business_card_label_groups:
                business_card_splash.append(group)

            if is_cp_version_5:  # Refresh display in CircuitPython 5
                self.display.auto_refresh = True
                self.display.refresh()
            else:  # Refresh display in CircuitPython 4
                self.display.wait_for_frame()

Commenting out self.display.refresh() will prevent the background from appearing in CP5.

@makermelissa
Copy link
Collaborator

Ok, thanks for trying. It's still an improvement on the existing code.

Copy link
Collaborator

@makermelissa makermelissa left a comment

Choose a reason for hiding this comment

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

Thanks for making these changes.

@makermelissa makermelissa merged commit d3da430 into adafruit:master Feb 19, 2020
adafruit-adabot added a commit to adafruit/Adafruit_CircuitPython_Bundle that referenced this pull request Feb 19, 2020
@nnja nnja deleted the fix_business_card_display branch February 19, 2020 05:39
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.

3 participants