From fd6fe2ceada168e33a01cbdf9503f180cb30c58b Mon Sep 17 00:00:00 2001 From: Diego Barrios Romero Date: Tue, 20 Nov 2018 19:21:50 +0100 Subject: Add function to read last measurement in continuous mode --- src/devices/mode/continuous.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'src/devices') 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 Ads1x1x where - DI: interface::WriteData, + DI: interface::ReadData + interface::WriteData, + CONV: conversion::ConvertMeasurement, { /// Change operating mode to OneShot pub fn into_one_shot(mut self) -> Result, Error> { @@ -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> { + 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 Ads1x1x -- cgit v1.2.3-54-g00ecf