//! Continuous measurement mode. use crate::{ conversion, devices::OperatingMode, mode, Ads1x1x, ChannelId, Error, ModeChangeError, Register, }; use core::marker::PhantomData; impl Ads1x1x where I2C: embedded_hal_async::i2c::I2c, CONV: conversion::ConvertMeasurement, { /// Changes to one-shot operating mode. pub async fn into_one_shot( mut self, ) -> Result, ModeChangeError> { if let Err(Error::I2C(e)) = self.set_operating_mode(OperatingMode::OneShot).await { return Err(ModeChangeError::I2C(e, self)); } Ok(Ads1x1x { i2c: self.i2c, address: self.address, config: self.config, fsr: self.fsr, a_conversion_was_started: false, _conv: PhantomData, _ic: PhantomData, _mode: PhantomData, }) } /// Reads the most recent measurement. pub async fn read(&mut self) -> Result> { let value = self.read_register(Register::CONVERSION).await?; Ok(CONV::convert_measurement(value)) } /// Selects the channel used for measurements. /// /// Note that when changing the channel in continuous conversion mode, the /// ongoing conversion will be completed. /// The following conversions will use the new channel configuration. #[allow(unused_variables)] pub async fn select_channel>( &mut self, channel: CH, ) -> Result<(), Error> { let config = self.config.with_mux_bits(CH::channel_id()); self.write_register(Register::CONFIG, config.bits).await?; self.config = config; Ok(()) } }