Skip to content
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

adding optional service function #106

Closed
wants to merge 1 commit into from
Closed

Conversation

siddacious
Copy link
Contributor

I got frustrated by how much time my sensor project was taking trying to talk to IO, so I did some digging and found that the vast majority of the time taken to do a POST to IO (or probably any HTTP request) is spent polling the ready pin of the Airlift module to see if it's ready to talk.

I added an optional argument to the ESP32SPI class to allow the user to provide a function that gets called each cycle while waiting on the ESP32. Super useful! Now I can read buttons and do stuff while waiting for WiFi to be done

@siddacious siddacious requested review from brentru and a team September 28, 2020 02:06
@tannewt
Copy link
Member

tannewt commented Sep 28, 2020

Is it waiting for ready in the middle of a request or at the start? If it's the start, then we could expose readiness directly. Passing in a function to call when idle is definitely advanced and needs documentation at the class level in addition to the example.

@siddacious
Copy link
Contributor Author

@tannewt it's waiting whenever it wants to send a command to the ESP which happen happens nearly every time you interact with it

@tannewt
Copy link
Member

tannewt commented Sep 29, 2020

I'm wary of adding this callback because it's a non-standard way to do concurrency AND this library is a huge hodge podge already.

Instead, we could actually start to do asyncio per the long CircuitPython issue: adafruit/circuitpython#1380

For monitoring buttons, could you use gamepad in the meantime?

@siddacious
Copy link
Contributor Author

It is indeed a bit of a hack, but it was easier than refactoring the whole library to have a non-blocking API 😅

I am already using gamepadshift to read the buttons on an edgebadge but I can't call it to check for button presses if the ESP32SPI library has the only thread/instruction pointer/whatever.

I'm all for starting on async/concurrency. I've been doing a lot more "eventy" coding recently and I fear that if not given additional tools I might accidentally write full-fledged OS :|

I'll close this for now but I'm going to open an issue for the context thievery if there isn't already one

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.

2 participants