Struct mh_z19c::MhZ19C

source ·
pub struct MhZ19C<'a, U, E>where
    U: Read<u8, Error = E> + Write<u8, Error = E>,{ /* private fields */ }
Expand description

Driver for the MH-Z19C sensor.

Implementations§

source§

impl<'a, U, E> MhZ19C<'a, U, E>where U: Read<u8, Error = E> + Write<u8, Error = E>,

source

pub fn new(uart: U) -> Self

Create a new instance.

  • uart: Serial (UART) interface for communication with the sensor.
source§

impl<'a, U, E> MhZ19C<'a, U, E>where U: Read<u8, Error = E> + Write<u8, Error = E>,

source

pub fn read_co2_ppm(&mut self) -> Result<u16, Error<E>>

Reads and returns the CO₂ concentration in parts-per-million (ppm).

source

pub fn get_firmware_version(&mut self) -> Result<[u8; 4], Error<E>>

Retrieves the firmware version of the sensor.

source

pub fn set_self_calibrate(&mut self, enabled: bool) -> Result<(), Error<E>>

Activates or deactivates the sensor’s self-calibration mode.

See the sensor’s data sheet for more information on self-calibration and hand-operated mode.

source

pub fn into_inner(self) -> U

Returns the owned UART interface.vec!

Note that this might leave the interface with partially written or read bytes on the UART interface if not all MH-Z19C commands have been polled to completion (i.e. the last command call did not return nb::Error::WouldBlock).

source

pub fn upgrade_to_v5<'b>( &'b mut self ) -> Result<MhZ19CFw5<'a, 'b, U, E>, Error<E>>

Will make the Firmware5Api capabilities available.

If the sensor firmware is not at least of version 5, an error will be returned.

Trait Implementations§

source§

impl<'a, U, E> BaseApi<E> for MhZ19C<'a, U, E>where U: Read<u8, Error = E> + Write<u8, Error = E>,

source§

fn read_co2_ppm(&mut self) -> Result<u16, Error<E>>

Reads and returns the CO₂ concentration in parts-per-million (ppm).
source§

fn get_firmware_version(&mut self) -> Result<[u8; 4], Error<E>>

Retrieves the firmware version of the sensor.
source§

fn set_self_calibrate(&mut self, enabled: bool) -> Result<(), Error<E>>

Activates or deactivates the sensor’s self-calibration mode. Read more
source§

impl<'a, U, E: Debug> Debug for MhZ19C<'a, U, E>where U: Read<u8, Error = E> + Write<u8, Error = E> + Debug,

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a, U, E> RefUnwindSafe for MhZ19C<'a, U, E>where U: RefUnwindSafe,

§

impl<'a, U, E> Send for MhZ19C<'a, U, E>where U: Send,

§

impl<'a, U, E> Sync for MhZ19C<'a, U, E>where U: Sync,

§

impl<'a, U, E> Unpin for MhZ19C<'a, U, E>where U: Unpin,

§

impl<'a, U, E> UnwindSafe for MhZ19C<'a, U, E>where U: UnwindSafe,

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

const: unstable · 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 Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.