1pub mod am2302;
2mod binutils;
3mod cdev;
4
5use am2302::Reading;
6use cdev::push_pull;
7use thiserror::Error;
8
9#[derive(Error, Debug)]
10pub enum Am2302ReadError {
11 #[error("Could not read AM2302")]
12 ReadError,
13}
14
15pub fn try_read(gpio_number: u32) -> Result<Reading, Am2302ReadError> {
16 let all_data = push_pull(gpio_number);
17 for data in all_data.windows(40) {
18 let result = Reading::from_binary_vector(&data);
19 if let Ok(reading) = result {
20 return Ok(reading);
21 }
22 }
23 Err(Am2302ReadError::ReadError)
24}