Skip to content

Initial Working Version #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 23 commits into from
Aug 10, 2020
Merged

Initial Working Version #1

merged 23 commits into from
Aug 10, 2020

Conversation

makermelissa
Copy link
Collaborator

This uses a combo of the RGB Matrix, RGB Matrix Shield, and Metro M4 Airlift Lite.

@makermelissa makermelissa requested a review from a team July 24, 2020 23:38
@ladyada
Copy link
Member

ladyada commented Jul 24, 2020

@jedgarpark please test for melissa

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.

Thanks for this initial work! Two questions:

  1. How much memory is used by this library?
  2. How much of this is duplicated from PyPortal?

The PyPortal library is monolithic and I'd love to see an iteration that better enables loading just the code needed for what someone is trying to do. For example, the SD card and fetching logic could be split from the graphics.

README.rst Outdated
:alt: Documentation Status

.. image:: https://img.shields.io/discord/327254708534116352.svg
:target: https://discord.gg/nBQh6qu
Copy link
Member

Choose a reason for hiding this comment

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

I don't think this invite link is active anymore. Looks like we need to update the cookiecutter.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ok, I can remove the link at least.

Copy link
Member

Choose a reason for hiding this comment

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

https://github.com/adafruit/Adafruit_CircuitPython_AHTx0/pull/2/files

@dherrada Does cookiecutter need to be updated for the new discord link?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks for the correct link

Comment on lines 78 to 91
class Fake_Requests:
"""For faking 'requests' using a local file instead of the network."""

def __init__(self, filename):
self._filename = filename
with open(filename, "r") as file:
self.text = file.read()

def json(self):
"""json parsed version for local requests."""
import json # pylint: disable=import-outside-toplevel

return json.loads(self.text)

Copy link
Member

Choose a reason for hiding this comment

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

Can we split this out into a separate library since it's shared with PyPortal? (I have modifications to this in my PyPortal copy and duplicating it here will leave it behind.)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That's probably a good idea. There's a Blinka version of the PyPortal library as well that also shares this.

@makermelissa
Copy link
Collaborator Author

  1. As for how much memory this uses, how would I tell?
  2. Mostly the network stuff is a duplicate of PyPortal.

I went for a less monolithic approach with this library which is why the add_text() function needs to be called after initialization, though I'm sure there's room for improvement. Like I could make it so it doesn't automatically connect to WiFi in case the user just wants to initialize the RGB Matrix, but it kind of defeats the purpose of this library. Also, I'm pretty sure I remove the SD card stuff from here since there's no SD card on a Metro M4 Airlift Lite.

@tannewt
Copy link
Member

tannewt commented Jul 28, 2020

1. As for how much memory this uses, how would I tell?

gc.mem_free() before and after the import is a decent approximation.

2. Mostly the network stuff is a duplicate of PyPortal.

Could we split it out? Some of it does a fetch and writes the result to the FS right? That'd be handy on it's own.

I went for a less monolithic approach with this library which is why the add_text() function needs to be called after initialization, though I'm sure there's room for improvement. Like I could make it so it doesn't automatically connect to WiFi in case the user just wants to initialize the RGB Matrix, but it kind of defeats the purpose of this library. Also, I'm pretty sure I remove the SD card stuff from here since there's no SD card on a Metro M4 Airlift Lite.

I think there needs to be more curation of what is in this library based on what it's purpose is. Now is the time to do it before folks are using it.

I think there are three layers to it that could be split out separately and build on each other.

  1. The "FeatherWing" scenario where the library does board/project specific initialization like connecting the display and esp coprocessor but nothing else.
  2. The graphics layer that has the normal "adafruit quotes" style layout and abstracts away the group stuff.
  3. The highest level that ties in internet URL to the graphics form.

There are a number of other helpers that should be split into their own libraries like wget and fake requests.

@makermelissa
Copy link
Collaborator Author

makermelissa commented Jul 28, 2020

By "FeatherWing" scenario, are you referring to the FeatherWing library and how we handled the board initialization automatically?

For the memory, it looks like it takes about 65K based on before and after the import.

Are you proposing the 3 layers in the same library or different libraries?

@makermelissa
Copy link
Collaborator Author

I'm working on splitting this up into multiple files and for the moment will just keep them in the same library. Then we can split them off later without much change other than additional install requirements.

@tannewt
Copy link
Member

tannewt commented Jul 29, 2020

By "FeatherWing" scenario, are you referring to the FeatherWing library and how we handled the board initialization automatically?

Yup exactly.

I'm working on splitting this up into multiple files and for the moment will just keep them in the same library. Then we can split them off later without much change other than additional install requirements.

Thanks! That's a great start.

@makermelissa
Copy link
Collaborator Author

I want to verify the examples first. This is close. I'll re-request a review when ready.

@makermelissa makermelissa requested a review from tannewt August 4, 2020 20:16
@makermelissa
Copy link
Collaborator Author

It's ready again for review.

@jedgarpark
Copy link

This is working great for the On Air sign!

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.

A couple small things. Otherwise, it's a good start in splitting it apart. Thanks!

now = time.struct_time(
(year, month, mday, hours, minutes, seconds, week_day, year_day, is_dst)
)
print(now)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
print(now)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good catch.


def manager(self, secrets):
"""Initialize and return the WiFi Manager"""
return adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(self.esp, secrets, None)
Copy link
Member

Choose a reason for hiding this comment

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

Want to cache this instead since you'll call it every IO request?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sounds good.

:param file_or_color: The filename of the chosen background image, or a hex color.

"""
print("Set background to ", file_or_color)
Copy link
Member

Choose a reason for hiding this comment

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

Should these bare prints be behind the _debug attribute?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think this particular one is more useful regardless of the debug status.


def json(self):
"""json parsed version for local requests."""
import json # pylint: disable=import-outside-toplevel
Copy link
Member

Choose a reason for hiding this comment

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

This can be at the top level now.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sounds good.

"""json parsed version for local requests."""
import json # pylint: disable=import-outside-toplevel

return json.loads(self.text)
Copy link
Member

Choose a reason for hiding this comment

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

Use json.load here and open the file here as well. That way it never loads the full string into memory.

Copy link
Collaborator Author

@makermelissa makermelissa Aug 7, 2020

Choose a reason for hiding this comment

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

Although this suggestion will improve the .json() function, I think this will break trying to access the .text property unless json() is called first. I created a text property that loads and returns the text of the file as well. It doesn't store it and use memory, so it may require multiple file reads.

@makermelissa
Copy link
Collaborator Author

I made the requested changes. I modified the FakeRequests so that it doesn't store the text, but created a text property so it doesn't break things.

@makermelissa makermelissa requested a review from tannewt August 7, 2020 01:18
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. Thank you!

@tannewt tannewt merged commit 89b4a87 into adafruit:master Aug 10, 2020
@makermelissa
Copy link
Collaborator Author

Thank you :)

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.

4 participants