-
Notifications
You must be signed in to change notification settings - Fork 5
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
GPIO API design #2
Comments
My own comment from the same community post: I'm not a Rust expert but I've played with it a bit, and am reading up on Rust idioms while I type some thoughts here.
fn main() {
// setup-y things
loop {
// loop-y things
}
}
extern crate particle;
use particle::photon as board;
fn main() {
board::pin_mode(D7, OUTPUT);
particle::publish("Photon is initialized!");
loop {
board::digital_write(D7, HIGH);
delay(1000);
board::digital_write(D7, HIGH);
delay(1000);
}
}
|
Interesting idea. I think that should work out. An alternative would be to provide
I like that :)
Some approaches that come to mind:
Are there more possibilities? I think the first (OO with traits) approach is superior in this case. Potential usage example: extern crate particle;
// Board implementation
use particle::photon as board;
// Traits (probably don't have to be imported explicitly)
use particle::photon::DigitalWrite;
// API
use particle::cloud;
fn main() {
let led_pin = board::D7::new();
cloud::publish("Photon is initialized!");
loop {
led_pin.high();
delay(1000);
led_pin.low();
delay(1000);
}
} We just need to make sure that the pin structs are stateless, as there could be multiple instances of the same pin initialized. That wouldn't really make sense. I'm not sure where functions like delay should live. Regarding Cargo, I opened a separate issue: #10. |
Loving the suggested syntax above (OO with traits). 👍 |
I agree, I'm down with that syntax |
Loving it too, I arrived at a similar idea on the forums before I started reading here: One difference I see between our proposals: |
Quote @m-mcgowan from this post on the community:
The text was updated successfully, but these errors were encountered: