rohi_hal/
sensor.rs

1///////////////////////////////////////////////////////////////////////////////
2//
3//  Copyright 2025 Akagi Engineering <admin@akagi.dev>
4//
5//  Licensed under the Apache License, Version 2.0 (the "License");
6//  you may not use this file except in compliance with the License.
7//  You may obtain a copy of the License at
8//
9//      http://www.apache.org/licenses/LICENSE-2.0
10//
11//  Unless required by applicable law or agreed to in writing, software
12//  distributed under the License is distributed on an "AS IS" BASIS,
13//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14//  See the License for the specific language governing permissions and
15//  limitations under the License.
16//
17///////////////////////////////////////////////////////////////////////////////
18//! Robonomics sensors collection provide different kinds of measures via same
19//! async interface. For example, access sensor data for board instance will
20//! looks like:
21//!
22//!   let board = ...
23//!   let sensor = Sensor(&board);
24//!   let temp = sensor.temperature().await;
25//!   println!("{}", temp);
26//!
27
28pub(crate) mod bus;
29use bus::*;
30
31/// Generic sensor data interface.
32pub struct Sensor<'a, T>(pub &'a mut T);
33
34impl<T: ParticulateMatter> Sensor<'_, T> {
35    /// A measurement of PM2.5 fine dust pollution.
36    pub async fn pm10(&mut self) -> Option<u16> {
37        self.0.pm10().await
38    }
39
40    /// A measurement of PM10 fine dust pollution.
41    pub async fn pm25(&mut self) -> Option<u16> {
42        self.0.pm25().await
43    }
44}
45
46impl<T: Humidity> Sensor<'_, T> {
47    /// The measured humidity in tenths of a percent.
48    pub async fn humidity(&mut self) -> Option<u16> {
49        self.0.humidity().await
50    }
51}
52
53impl<T: Temperature> Sensor<'_, T> {
54    /// The measured temperature in tenths of degrees **Celsius**.
55    pub async fn temperature(&mut self) -> Option<i16> {
56        self.0.temperature().await
57    }
58}
59
60impl<T: Pressure> Sensor<'_, T> {
61    /// The measured pressure in **Pascals**.
62    pub async fn pressure(&mut self) -> Option<u32> {
63        self.0.pressure().await
64    }
65}