diff options
author | Diego Barrios Romero <eldruin@gmail.com> | 2018-11-20 19:21:50 +0100 |
---|---|---|
committer | Diego Barrios Romero <eldruin@gmail.com> | 2018-11-20 19:21:50 +0100 |
commit | fd6fe2ceada168e33a01cbdf9503f180cb30c58b (patch) | |
tree | 4be283bc16aa0a4abe126ea14fdcadde7683a1c1 /src/devices/mode/continuous.rs | |
parent | 2a2f25b35c8411a5932e576b5d0969d3928c7209 (diff) | |
download | ads1x1x-async-fd6fe2ceada168e33a01cbdf9503f180cb30c58b.tar.gz ads1x1x-async-fd6fe2ceada168e33a01cbdf9503f180cb30c58b.tar.xz ads1x1x-async-fd6fe2ceada168e33a01cbdf9503f180cb30c58b.zip |
Add function to read last measurement in continuous mode
Diffstat (limited to 'src/devices/mode/continuous.rs')
-rw-r--r-- | src/devices/mode/continuous.rs | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/src/devices/mode/continuous.rs b/src/devices/mode/continuous.rs index cd3edee..7998a46 100644 --- a/src/devices/mode/continuous.rs +++ b/src/devices/mode/continuous.rs @@ -7,7 +7,8 @@ use super::super::OperatingMode; impl<DI, IC, CONV, E> Ads1x1x<DI, IC, CONV, mode::Continuous> where - DI: interface::WriteData<Error = E>, + DI: interface::ReadData<Error = E> + interface::WriteData<Error = E>, + CONV: conversion::ConvertMeasurement, { /// Change operating mode to OneShot pub fn into_one_shot(mut self) -> Result<Ads1x1x<DI, IC, CONV, mode::OneShot>, Error<E>> { @@ -16,7 +17,7 @@ where iface: self.iface, config: self.config, fsr: self.fsr, - a_conversion_was_started: self.a_conversion_was_started, + a_conversion_was_started: false, _conv: PhantomData, _ic: PhantomData, _mode: PhantomData @@ -29,6 +30,15 @@ where self.a_conversion_was_started = true; Ok(()) } + + /// Read the most recent measurement + pub fn read(&mut self) -> Result<i16, Error<E>> { + if !self.a_conversion_was_started { + return Err(Error::NotStarted); + } + let value = self.iface.read_register(Register::CONVERSION)?; + return Ok(CONV::convert_measurement(value)); + } } impl<DI, IC, CONV, E> Ads1x1x<DI, IC, CONV, mode::Continuous> |