//! Continuous measurement mode use crate::{ conversion, devices::OperatingMode, interface, mode, Ads1x1x, ChannelId, Error, ModeChangeError, Register, }; use core::marker::PhantomData; impl Ads1x1x where DI: interface::ReadData + interface::WriteData, CONV: conversion::ConvertMeasurement, { /// Change operating mode to OneShot pub fn into_one_shot( mut self, ) -> Result, ModeChangeError> { if let Err(Error::I2C(e)) = self.set_operating_mode(OperatingMode::OneShot) { return Err(ModeChangeError::I2C(e, self)); } Ok(Ads1x1x { iface: self.iface, config: self.config, fsr: self.fsr, a_conversion_was_started: false, _conv: PhantomData, _ic: PhantomData, _mode: PhantomData, }) } /// Read the most recent measurement pub fn read(&mut self) -> Result> { let value = self.iface.read_register(Register::CONVERSION)?; Ok(CONV::convert_measurement(value)) } /// Select the channel 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 fn select_channel>(&mut self, channel: CH) -> Result<(), Error> { let config = self.config.with_mux_bits(CH::channel_id()); self.iface.write_register(Register::CONFIG, config.bits)?; self.config = config; Ok(()) } }