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, $SampleType:ty, $unit:expr) => {
14 paste::paste! {
15 #[doc = concat!(" Asynchronously wait for ", stringify!($SensorName), " measurements to exceed specified thresholds.")]
16 pub trait [<$SensorName ThresholdWait>]: ErrorType {
17 #[doc = concat!(" Wait for ", stringify!($SensorName), " to be measured below the given threshold (in ", $unit, ").")]
18 async fn [<wait_for_ $SensorName:snake _low>](&mut self, threshold: $SampleType) -> Result<(), Self::Error>;
19
20 #[doc = concat!(" Wait for ", stringify!($SensorName), " to be measured above the given threshold (in ", $unit, ").")]
21 async fn [<wait_for_ $SensorName:snake _high>](&mut self, threshold: $SampleType) -> Result<(), Self::Error>;
22
23 #[doc = concat!(" Wait for ", stringify!($SensorName), " to be measured above or below the given high and low thresholds (in ", $unit, ").")]
24 async fn [<wait_for_ $SensorName:snake _out_of_range>](
25 &mut self,
26 threshold_low: $SampleType,
27 threshold_high: $SampleType,
28 ) -> Result<(), Self::Error>;
29 }
30
31 impl<T: [<$SensorName ThresholdWait>] + ?Sized> [<$SensorName ThresholdWait>] for &mut T {
32 async fn [<wait_for_ $SensorName:snake _low>](&mut self, threshold: $SampleType) -> Result<(), Self::Error> {
33 T::[<wait_for_ $SensorName:snake _low>](self, threshold).await
34 }
35
36 async fn [<wait_for_ $SensorName:snake _high>](&mut self, threshold: $SampleType) -> Result<(), Self::Error> {
37 T::[<wait_for_ $SensorName:snake _high>](self, threshold).await
38 }
39
40 async fn [<wait_for_ $SensorName:snake _out_of_range>](
41 &mut self,
42 threshold_low: $SampleType,
43 threshold_high: $SampleType,
44 ) -> Result<(), Self::Error> {
45 T::[<wait_for_ $SensorName:snake _out_of_range>](self, threshold_low, threshold_high).await
46 }
47 }
48 }
49 };
50}