summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/devices/mode/continuous.rs14
-rw-r--r--src/lib.rs4
2 files changed, 15 insertions, 3 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>
diff --git a/src/lib.rs b/src/lib.rs
index 4382e61..b825546 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -203,7 +203,9 @@ pub enum Error<E> {
/// I²C/SPI bus error
Comm(E),
/// Invalid input data provided
- InvalidInputData
+ InvalidInputData,
+ /// Continuous measurement was not started
+ NotStarted,
}
const DEVICE_BASE_ADDRESS : u8 = 0b100_1000;