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

Add support for reading asynchronously with mio::Evented and tokio_core::Stream #26

Merged
merged 1 commit into from
Dec 18, 2016

Conversation

emosenkis
Copy link
Contributor

No description provided.

@emosenkis
Copy link
Contributor Author

This should fix #22 and is probably the right way to address #23

@emosenkis
Copy link
Contributor Author

CI is failing only for Rust 1.5.0, seemingly because mio 0.6.1 does something in its Cargo.toml that isn't compatible with older versions.

@posborne
Copy link
Member

@emosenkis Go ahead and make the changes to bump the minimum supported version up to what is required.

@posborne
Copy link
Member

r? @nastevens

@emosenkis
Copy link
Contributor Author

@posborne Done (I had to bump the minimum Rust version again for futures-rs compatibility and also replace my use of the new ? operator with try!()). Would you like me to also increment the version number in Cargo.toml and squash my commits?

@@ -15,6 +15,14 @@ interrupts) GPIOs from userspace.
See https://www.kernel.org/doc/Documentation/gpio/sysfs.txt
"""

[features]
default = ["tokio"]
Copy link
Member

Choose a reason for hiding this comment

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

I'm on the fence on including tokio in the default features as it is not a small dependency and may send users down a bit of a tangent. At least for now, I'm guessing most users will still be using this library for just basic control or dealing with polling in a blocking fashion. Obviously, they are not forced to use the feature, but many people will not disable it.

@posborne
Copy link
Member

Thanks for the change @emosenkis. Would you mind adding an example that showcases the asynchronous usage?

I think a good example could be as simple as demonstrating how you could use the async features to poll multiple pins concurrently without the use of threads. You could base this off of what is present for interrupt.rs but make the program take a variable number of arguments (each being a pin to add to the group of pins polled).

Finally, some mention of the asynchronous features would be nice to add to the top-level README documentation.

@emosenkis
Copy link
Contributor Author

@posborne Done.

Copy link
Member

@nastevens nastevens left a comment

Choose a reason for hiding this comment

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

Great changes - thanks for the PR! Just a few minor suggestions.

@@ -1,6 +1,6 @@
[package]
name = "sysfs_gpio"
version = "0.4.4"
version = "0.4.5"
Copy link
Member

Choose a reason for hiding this comment

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

This seems like a big enough backwards compatible change that it could probably be a new minor version. What do you think @posborne?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My two cents: I don't see any reason to bump the minor version for a change that's 100% backwards compatible (therefore requiring everyone to update their Cargo.toml)

Copy link
Member

Choose a reason for hiding this comment

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

Let's bump the version if we are going to have tokio be part of the default features. Dropping a bunch of extra features/dependencies on a user of the library when they did a cargo update doesn't seem polite. Plus, we dropped support for older versions of Rust - that is enough in my book to go to 0.5.0.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The new features are no longer enabled by default. Unless they are manually enabled, there is no additional dependency and no change in the minimum Rust version (the new dependencies are what caused the change in Rust version compatibility).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let me know if you still want me to change the version to 0.5.0.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, let's bump it as we are dropping official support for the older versions of rust.

@@ -447,7 +486,8 @@ impl PinPoller {
/// making this call. This call makes use of epoll under the
/// covers. If it is desirable to poll on multiple GPIOs or
/// other event source, you will need to implement that logic
/// yourself.
/// yourself or poll asynchronously using the integration with
Copy link
Member

Choose a reason for hiding this comment

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

I think it'd be fine to remove the "do it yourself" option in favor of using the mio/tokio option.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

#[cfg(feature = "mio-evented")]
impl AsyncPinPoller {
fn new(pin_num: u64) -> Result<Self> {
let devfile: File = try!(File::open(&format!("/sys/class/gpio/gpio{}/value", pin_num)));
Copy link
Member

Choose a reason for hiding this comment

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

Is the explicit File type needed here? It seems like type inference would figure it out.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@emosenkis
Copy link
Contributor Author

I bumped the version as requested but also changed the new API slightly since I realized that reading the pin's value is unnecessary if interrupt is only enabled for one edge.

@posborne
Copy link
Member

@emosenkis Any changes coming in or do you think this is ready for a merge?

@emosenkis
Copy link
Contributor Author

@posborne The only issue I'm aware of is that when using PinStream and PinValueStream, it immediately triggers. I think I should probably try to consume that initial event before it gets to the user. I also want to squash my commits before you merge.

@posborne
Copy link
Member

No problem, let me know when you are happy with things and I'll do another final review before merging and cutting 0.5.0. Thanks again for the contribution!

@emosenkis
Copy link
Contributor Author

@posborne Ready for merge. I fixed the issue with the bogus first event and did a little bit of cleanup and optimization. I tested the example on real hardware with a rotary encoder/button and it works as expected.

@posborne
Copy link
Member

Excellent, thanks again!

@posborne posborne merged commit bd9f5b5 into rust-embedded:master Dec 18, 2016
@emosenkis
Copy link
Contributor Author

Would you be willing to cut 0.5.0 and upload it to crates.io? I have a rotary encoder library that depends on it which I'd like to release.

@posborne
Copy link
Member

Yes, I'll release 0.5.0 this afternoon.

@posborne
Copy link
Member

@pheki pheki mentioned this pull request Feb 27, 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.

None yet

3 participants