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>,

source

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
source

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();
source

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]);
source

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);
source

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);
source

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: Clone> Clone for Max6675<Spi, SpiError>
where Spi: SpiDevice<Error = SpiError> + Clone,

source§

fn clone(&self) -> Max6675<Spi, SpiError>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<Spi, SpiError: Debug> Debug for Max6675<Spi, SpiError>
where Spi: SpiDevice<Error = SpiError> + Debug,

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<Spi, SpiError: PartialEq> PartialEq for Max6675<Spi, SpiError>
where Spi: SpiDevice<Error = SpiError> + PartialEq,

source§

fn eq(&self, other: &Max6675<Spi, SpiError>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<Spi, SpiError: Copy> Copy for Max6675<Spi, SpiError>
where Spi: SpiDevice<Error = SpiError> + Copy,

source§

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>
where Spi: Send, SpiError: Send,

§

impl<Spi, SpiError> Sync for Max6675<Spi, SpiError>
where Spi: Sync, SpiError: Sync,

§

impl<Spi, SpiError> Unpin for Max6675<Spi, SpiError>
where Spi: Unpin, SpiError: Unpin,

§

impl<Spi, SpiError> UnwindSafe for Max6675<Spi, SpiError>
where Spi: UnwindSafe, SpiError: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.