Struct max6675_hal::Max6675
source · pub struct Max6675<Spi, SpiError>where
Spi: SpiDevice<Error = SpiError>,{ /* private fields */ }
Expand description
§Max6675
A representation of the MAX6675 digital thermocouple converter. Maintains an SPI connection to the device.
Implementations§
source§impl<Spi, SpiError> Max6675<Spi, SpiError>where
Spi: SpiDevice<Error = SpiError>,
impl<Spi, SpiError> Max6675<Spi, SpiError>where
Spi: SpiDevice<Error = SpiError>,
sourcepub fn new(spi: Spi) -> Result<Self, Max6675Error<SpiError>>
pub fn new(spi: Spi) -> Result<Self, Max6675Error<SpiError>>
Creates a new Max6675 representation.
For the spi
argument, you should pass in your embedded-hal
device’s
SPI implementation filled with appropriate details.
§Usage
Since the Spi
(SPI) arguments is generic, you’ll have to make some
decisions based on the hardware you’re using!
Please follow this general template:
ⓘ
// first, define what pins you're connecting to
let so_pin = pins.("your miso pin").into_pull_up_input();
let cs_pin = pins.("your cs pin").into_output();
let sck_pin = pins.("your sck/clock pin").into_output();
// you may need a mosi pin for your device's SPI, though the max6675 doesn't use one.
// if so, just pick some pin that you're not using ☺️
let dummy_mosi = pins.("some pin you're not using").into_output();
let (spi, _) = device-hal::spi::Spi::new(
sck_pin, dummy_mosi, so_pin, cs_pin,
device-hal::spi::Settings {
// pick some settings that roughly align like so:
data_order: MostSignificantFirst,
clock: 4MhzClockSpeed,
mode: embedded_hal::spi::MODE_1,
}
);
let mut max = Max6675::new(spi)?; // your spi here
sourcepub fn free(self) -> Spi
pub fn free(self) -> Spi
Destructs the MAX6675
into its bare components, as recommended by the
HAL Design Patterns.
use max6675_hal::Max6675;
// pretend there's some spi setup code above...
let mut max = Max6675::new(spi).unwrap();
let mut spi = max.free();
sourcepub fn read_raw(&mut self) -> Result<[u8; 2], Max6675Error<SpiError>>
pub fn read_raw(&mut self) -> Result<[u8; 2], Max6675Error<SpiError>>
Tries to read thermocouple temperature, leaving it as a raw ADC count.
use max6675_hal::Max6675;
// pretend there's some spi setup code above...
let mut max = Max6675::new(spi).unwrap();
assert_eq!(max.read_raw().unwrap(), [0xc, 0x80]);
sourcepub fn read_celsius(&mut self) -> Result<Temperature, Max6675Error<SpiError>>
pub fn read_celsius(&mut self) -> Result<Temperature, Max6675Error<SpiError>>
Tries to read the thermocouple’s temperature in Celsius.
use max6675_hal::Max6675;
// pretend there's some spi setup code above...
let mut max = Max6675::new(spi).unwrap();
assert_approx_eq!(max.read_celsius().unwrap().into_inner(), 100_f32);
sourcepub fn read_fahrenheit(&mut self) -> Result<Temperature, Max6675Error<SpiError>>
pub fn read_fahrenheit(&mut self) -> Result<Temperature, Max6675Error<SpiError>>
Tries to read the thermocouple’s temperature in Fahrenheit.
use max6675_hal::Max6675;
// pretend there's some spi setup code above...
let mut max = Max6675::new(spi).unwrap();
assert_approx_eq!(max.read_fahrenheit().unwrap().into_inner(), 68_f32);
sourcepub fn read_kelvin(&mut self) -> Result<Temperature, Max6675Error<SpiError>>
pub fn read_kelvin(&mut self) -> Result<Temperature, Max6675Error<SpiError>>
Tries to read the thermocouple’s temperature in Kelvin.
use max6675_hal::Max6675;
// pretend there's some spi setup code above...
let mut max = Max6675::new(spi).unwrap();
assert_approx_eq!(max.read_kelvin().unwrap().into_inner(), 373.15_f32);
max.free().done();
Trait Implementations§
source§impl<Spi, SpiError: PartialEq> PartialEq for Max6675<Spi, SpiError>
impl<Spi, SpiError: PartialEq> PartialEq for Max6675<Spi, SpiError>
impl<Spi, SpiError: Copy> Copy for Max6675<Spi, SpiError>
impl<Spi, SpiError> StructuralPartialEq for Max6675<Spi, SpiError>where
Spi: SpiDevice<Error = SpiError>,
Auto Trait Implementations§
impl<Spi, SpiError> Freeze for Max6675<Spi, SpiError>where
Spi: Freeze,
impl<Spi, SpiError> RefUnwindSafe for Max6675<Spi, SpiError>where
Spi: RefUnwindSafe,
SpiError: RefUnwindSafe,
impl<Spi, SpiError> Send for Max6675<Spi, SpiError>
impl<Spi, SpiError> Sync for Max6675<Spi, SpiError>
impl<Spi, SpiError> Unpin for Max6675<Spi, SpiError>
impl<Spi, SpiError> UnwindSafe for Max6675<Spi, SpiError>where
Spi: UnwindSafe,
SpiError: UnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more