use connection::Connection;
use temperature::Temperature;
use thiserror::Error;
pub mod connection;
pub mod temperature;
#[derive(Debug, Error)]
pub enum Max6675Error {
#[error("We couldn't connect to the provided SPI path. See std::io::Error: {source}")]
IoError {
#[from]
source: std::io::Error,
},
#[error("The MAX6675 detected an open circuit (bit D2 was high). Please check the thermocouple connection and try again.")]
OpenCircuitError,
}
#[derive(Debug)]
pub struct Max6675 {
connection: Connection,
}
impl Max6675 {
pub fn new(spi_connection_path: impl AsRef<str>) -> Result<Self, Max6675Error> {
Ok(Self {
connection: Connection::new(spi_connection_path)?,
})
}
pub fn read_celsius(&mut self) -> Result<Temperature, Max6675Error> {
Ok(Temperature::Celsius(self.connection.read_as_celsius()?))
}
pub fn read_fahrenheit(&mut self) -> Result<Temperature, Max6675Error> {
Ok(self.read_celsius()?.to_fahrenheit())
}
pub fn read_kelvin(&mut self) -> Result<Temperature, Max6675Error> {
Ok(self.read_celsius()?.to_kelvin())
}
pub fn read_raw(&mut self) -> Result<[u8; 2], Max6675Error> {
self.connection.read_raw()
}
}