embedded_sensors_hal_async/
sensor.rs1pub use embedded_sensors_hal::sensor::{Error, ErrorKind, ErrorType};
9
10#[macro_export]
12macro_rules! decl_threshold_wait {
13 ($SensorName:ident, $SensorTrait:ident, $SampleType:ty, $unit:expr) => {
14 paste::paste! {
15 #[doc = concat!(" Asynchronously set and wait for ", stringify!($SensorName), " measurements to exceed specified thresholds.")]
16 pub trait [<$SensorName ThresholdWait>]: $SensorTrait {
17 #[doc = concat!(" Set lower ", stringify!($SensorName), " threshold (in ", $unit, ").")]
18 async fn [<set_ $SensorName:snake _threshold_low>](&mut self, threshold: $SampleType) -> Result<(), Self::Error>;
19
20 #[doc = concat!(" Set upper ", stringify!($SensorName), " threshold (in ", $unit, ").")]
21 async fn [<set_ $SensorName:snake _threshold_high>](&mut self, threshold: $SampleType) -> Result<(), Self::Error>;
22
23 #[doc = concat!(" Wait for ", stringify!($SensorName), " to be measured above or below the previously set high and low thresholds.")]
24 #[doc = concat!(" Returns the measured ", stringify!($SensorName), " at time threshold is exceeded (in ", $unit, ").")]
25 async fn [<wait_for_ $SensorName:snake _threshold>](&mut self) -> Result<$SampleType, Self::Error>;
26 }
27
28 impl<T: [<$SensorName ThresholdWait>] + ?Sized> [<$SensorName ThresholdWait>] for &mut T {
29 async fn [<set_ $SensorName:snake _threshold_low>](&mut self, threshold: $SampleType) -> Result<(), Self::Error> {
30 T::[<set_ $SensorName:snake _threshold_low>](self, threshold).await
31 }
32
33 async fn [<set_ $SensorName:snake _threshold_high>](&mut self, threshold: $SampleType) -> Result<(), Self::Error> {
34 T::[<set_ $SensorName:snake _threshold_high>](self, threshold).await
35 }
36
37 async fn [<wait_for_ $SensorName:snake _threshold>](&mut self) -> Result<$SampleType, Self::Error> {
38 T::[<wait_for_ $SensorName:snake _threshold>](self).await
39 }
40 }
41 }
42 };
43}