From fce3d8546bd619964ec5dd1594cd93e744a99521 Mon Sep 17 00:00:00 2001 From: Diego Barrios Romero Date: Sun, 11 Nov 2018 17:32:52 +0100 Subject: Implement value conversions over type parameter --- src/devices/mode/oneshot.rs | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'src/devices/mode/oneshot.rs') diff --git a/src/devices/mode/oneshot.rs b/src/devices/mode/oneshot.rs index 57e72a0..e8aa533 100644 --- a/src/devices/mode/oneshot.rs +++ b/src/devices/mode/oneshot.rs @@ -1,24 +1,24 @@ //! Common functions use core::marker::PhantomData; -use { Ads1x1x, mode, Error, Register, BitFlags, Config, ic }; -use { interface, hal, nb }; +use { Ads1x1x, mode, Error, Register, BitFlags, Config }; +use { interface, conversion, hal, nb }; use devices::OperatingMode; use channels::ChannelSelection; -use super::convert_measurement; -impl Ads1x1x +impl Ads1x1x where DI: interface::WriteData + interface::ReadData, - IC: ic::Resolution + CONV: conversion::ConvertMeasurement { /// Change operating mode to Continuous - pub fn into_continuous(mut self) -> Result, Error> { + pub fn into_continuous(mut self) -> Result, Error> { self.set_operating_mode(OperatingMode::Continuous)?; Ok(Ads1x1x { iface: self.iface, config: self.config, a_conversion_was_started: self.a_conversion_was_started, + converter: self.converter, _ic: PhantomData, _mode: PhantomData }) @@ -37,11 +37,12 @@ where } } -impl hal::adc::OneShot, i16, CH> for Ads1x1x +impl hal::adc::OneShot, i16, CH> + for Ads1x1x where DI: interface::ReadData + interface::WriteData, - IC: ic::Resolution, - CH: hal::adc::Channel, ID = ChannelSelection> + CONV: conversion::ConvertMeasurement, + CH: hal::adc::Channel, ID = ChannelSelection> { type Error = Error; @@ -61,7 +62,7 @@ where // result is ready let value = self.iface.read_register(Register::CONVERSION).map_err(nb::Error::Other)?; self.a_conversion_was_started = false; - return Ok(convert_measurement::(value)); + return Ok(CONV::convert_measurement(value)); } let config = self.config.with_mux_bits(CH::channel()); self.trigger_measurement(&config).map_err(nb::Error::Other)?; -- cgit v1.2.3-54-g00ecf