-
Notifications
You must be signed in to change notification settings - Fork 0
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
rename listen methods #3
Comments
Following along on your progress here... This is a good idea, has me thinking about the RF24 library. You could possibly even take it further and eliminate the need for |
Hmm, making I did this sort of intuition in the Circuitpython lib, but I found the first I also thought about having an enum and setting the role of the radio using the enum. But that API seems a bit too verbose. pub enum Role {
Rx,
Tx,
}
// ...
pub fn set_role(&mut self, role: Role) -> Result<(), Self::Error>;
pub fn get_role(&self) -> Role; Where user code would look like: radio.set_role(Role::Rx)?;
// or
if radio.get_role() == Role::Rx {
radio.set_role(Role::Tx)?;
} Furthermore, this whole concept revolves around the fact that the radio's role is a binary state, disregarding other nuances like changing roles or power consumption (standby-I/II modes). I don't think an enum solution is the best fit. |
I'm erring away from this.
I'm not ruling out this idea for added intuition. But I don't think it fits within idiomatic rust convention, where everything is explicit and error checking is always at the forefront. With all of that said, I added a check in rf24-rs/library/src/radio/rf24/radio.rs Lines 138 to 155 in 9fc47fc
In rust, a |
Since I'm writing the API from scratch here, I think it is a good opportunity to consider changes that would be considered backward incompatible in C++. Namely, the
startListening()
andstopListening()
methods.We have had more than a few complaints/requests to adapt the RF24 API functions into something that makes more sense (in human terms of spoken English language). Although that C++ API is rather tied to what maniacBug originally wrote, this lib's API isn't carved in stone (yet).
Proposal
Rename the following methods
start_listening()
->as_rx()
(fallible -- meaning needs SPI transaction)stop_listening()
->as_tx()
(fallible -- meaning needs SPI transaction)is_listening()
->is_rx()
(infallible -- meaning data is returned from cached config register's value; no SPI transaction)The idea is to make the API names as obvious as possible. Our experience, despite all efforts, has been that people would rather not read docs. And if a function's name needs additional explanation (especially for usage in examples), then the name was poorly chosen.
Additional context
I'm not exposing the CE pin for the instantiated radio object. The only case this might be useful is when using
write()
which is similar to C++RF24::writeFast()
. It would be nice to have a way to explicitly exit active TX mode by setting the CE pin LOW after checking transmission's outcome (usingget_status_flags()
). Currently, the only way to do that is to callstop_listening()
while already in TX mode, but this seems non-intuitive.The text was updated successfully, but these errors were encountered: