Skip to content

Conversation

@calex257
Copy link

@calex257 calex257 commented Apr 2, 2023

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 as i32.

@calex257 calex257 marked this pull request as draft April 2, 2023 10:13
libtock_platform = { path = "../../platform" }

[dev-dependencies]
libtock_unittest = { path = "../../unittest" } No newline at end of file

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> {

Choose a reason for hiding this comment

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

Suggested change
pub fn read_humidity() -> Result<(), ErrorCode> {
pub fn read() -> Result<(), ErrorCode> {

}

/// Register an events listener
pub fn register_listener<'share, F: Fn(i32)>(

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).

Choose a reason for hiding this comment

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

Delete this.

};
}

pub mod humidity {

Choose a reason for hiding this comment

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

Export the HumidityListener.

Comment on lines +12 to +14
// 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.

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.

pub use buttons::Buttons;
pub use console::Console;
pub use gpio::{Gpio, GpioMode, InterruptEdge, PullMode};
pub use humidity::Humidity;

Choose a reason for hiding this comment

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

Export HumidityListener.

Comment on lines +18 to +24
match Humidity::exists() {
Ok(()) => writeln!(Console::writer(), "humidity driver available").unwrap(),
Err(_) => {
writeln!(Console::writer(), "humidity driver unavailable").unwrap();
return;
}
}

Choose a reason for hiding this comment

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

Suggested change
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;
}

@DanutAldea DanutAldea mentioned this pull request Apr 26, 2023
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