Module humidity

Source
Expand description

Async Humidity Sensor API

This API provides generic methods for interfacing with humidity sensors specifically.

§For HAL authors

Here is an example for the implementation of the RelativeHumiditySensor and RelativityHumidityThresholdWait traits for a humidity sensor.

use embedded_sensors_hal_async::sensor;
use embedded_sensors_hal_async::humidity::{RelativeHumiditySensor, Percentage};

// A struct representing a humidity sensor.
pub struct MyHumiditySensor {
    // ...
}

#[derive(Clone, Copy, Debug)]
pub enum Error {
    // ...
}

impl sensor::Error for Error {
    fn kind(&self) -> sensor::ErrorKind {
        match *self {
            // ...
        }
    }
}

impl sensor::ErrorType for MyHumiditySensor {
    type Error = Error;
}

impl RelativeHumiditySensor for MyHumiditySensor {
    async fn relative_humidity(&mut self) -> Result<Percentage, Self::Error> {
        // ...
        Ok(42.0)
    }
}

impl RelativeHumidityThresholdWait for MyHumiditySensor {
    async fn wait_for_relative_humidity_low(
        &mut self,
        threshold: Percentage)
    -> Result<(), Self::Error> {
        // Enable lower threshold alerts for sensor...
        // Await alert (e.g. GPIO level change)...
        // Disable alerts for sensor...

        Ok(())
    }

    async fn wait_for_relative_humidity_high(
        &mut self,
        threshold: Percentage)
    -> Result<(), Self::Error> {
        // Enable upper threshold alerts for sensor...
        // Await alert (e.g. await GPIO level change)...
        // Disable alerts for sensor...

        Ok(())
    }

    async fn wait_for_relative_humidity_out_of_range(
        &mut self,
        threshold_low: Percentage,
        threshold_high: Percentage
    ) -> Result<(), Self::Error> {
        // Enable lower and upper threshold alerts for sensor...
        // Await alert (e.g. await GPIO level change)...
        // Disable alerts for sensor...

        Ok(())
    }
}

Traits§

RelativeHumiditySensor
Async Relative Humidity Sensor methods.
RelativeHumidityThresholdWait
Asynchronously wait for RelativeHumidity measurements to exceed specified thresholds.

Type Aliases§

Percentage
Associates the units relative humidity (RH) samples are measured in with the underlying data type.