-
Notifications
You must be signed in to change notification settings - Fork 12
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
Humidity API #22
base: master
Are you sure you want to change the base?
Humidity API #22
Conversation
libtock_platform = { path = "../../platform" } | ||
|
||
[dev-dependencies] | ||
libtock_unittest = { path = "../../unittest" } |
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.
Add newline
/// Initiate a humidity measurement. | ||
/// | ||
/// This function is used both for synchronous and asynchronous readings | ||
pub fn read_humidity() -> Result<(), ErrorCode> { |
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.
pub fn read_humidity() -> Result<(), ErrorCode> { | |
pub fn read() -> Result<(), ErrorCode> { |
} | ||
|
||
/// Register an events listener | ||
pub fn register_listener<'share, F: Fn(i32)>( |
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 should be Fn(u32)
.
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.
Delete this.
@@ -29,6 +29,12 @@ pub mod gpio { | |||
PullDown, PullNone, PullUp, | |||
}; | |||
} | |||
|
|||
pub mod humidity { |
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.
Export the HumidityListener
.
// The `upcall_on_command` field is set to Some(value) if an upcall(with value as its argument) should be called when read command is received, | ||
// or None otherwise. It was needed for testing `read_sync` library function which simulates a synchronous humidity read, | ||
// because it was impossible to schedule an upcall during the `synchronous` read in other ways. |
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.
Move this as a comment next to the field.
@@ -24,6 +25,7 @@ pub use alarm::Alarm; | |||
pub use buttons::Buttons; | |||
pub use console::Console; | |||
pub use gpio::{Gpio, GpioMode, InterruptEdge, PullMode}; | |||
pub use humidity::Humidity; |
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.
Export HumidityListener
.
match Humidity::exists() { | ||
Ok(()) => writeln!(Console::writer(), "humidity driver available").unwrap(), | ||
Err(_) => { | ||
writeln!(Console::writer(), "humidity driver unavailable").unwrap(); | ||
return; | ||
} | ||
} |
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.
match Humidity::exists() { | |
Ok(()) => writeln!(Console::writer(), "humidity driver available").unwrap(), | |
Err(_) => { | |
writeln!(Console::writer(), "humidity driver unavailable").unwrap(); | |
return; | |
} | |
} | |
if Humidity::exists().is_err() { | |
writeln!(Console::writer(), "humidity driver unavailable").unwrap(); | |
return; | |
} |
Heavily inspired from the work done here.
I observed that the C implementation is similar to the one for temperature and this conversion should be compatible.
One thing to note is that in the C files the humidity is represented as an
unsigned int
, whereas in my conversion I left it asi32
.