-
Notifications
You must be signed in to change notification settings - Fork 22
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
Conversation
@jedgarpark please test for melissa |
There was a problem hiding this 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:
- How much memory is used by this library?
- 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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
adafruit_matrixportal.py
Outdated
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) | ||
|
There was a problem hiding this comment.
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.)
There was a problem hiding this comment.
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.
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. |
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 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.
There are a number of other helpers that should be split into their own libraries like wget and fake requests. |
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? |
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. |
Yup exactly.
Thanks! That's a great start. |
I want to verify the examples first. This is close. I'll re-request a review when ready. |
It's ready again for review. |
This is working great for the On Air sign! |
There was a problem hiding this 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!
adafruit_matrixportal/network.py
Outdated
now = time.struct_time( | ||
(year, month, mday, hours, minutes, seconds, week_day, year_day, is_dst) | ||
) | ||
print(now) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
print(now) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch.
adafruit_matrixportal/wifi.py
Outdated
|
||
def manager(self, secrets): | ||
"""Initialize and return the WiFi Manager""" | ||
return adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(self.esp, secrets, None) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
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. |
There was a problem hiding this 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!
Thank you :) |
This uses a combo of the RGB Matrix, RGB Matrix Shield, and Metro M4 Airlift Lite.