summaryrefslogtreecommitdiffstats
path: root/src/devices/mode/oneshot.rs
diff options
context:
space:
mode:
authorDiego Barrios Romero <eldruin@gmail.com>2018-11-11 17:32:52 +0100
committerDiego Barrios Romero <eldruin@gmail.com>2018-11-11 17:32:52 +0100
commitfce3d8546bd619964ec5dd1594cd93e744a99521 (patch)
tree7bc17d465652c86b25b9fb34ccd7ed3bf0218b56 /src/devices/mode/oneshot.rs
parentb9b5349b4b78a5d59be4a7e4a11f712e2f6a8256 (diff)
downloadads1x1x-async-fce3d8546bd619964ec5dd1594cd93e744a99521.tar.gz
ads1x1x-async-fce3d8546bd619964ec5dd1594cd93e744a99521.tar.xz
ads1x1x-async-fce3d8546bd619964ec5dd1594cd93e744a99521.zip
Implement value conversions over type parameter
Diffstat (limited to 'src/devices/mode/oneshot.rs')
-rw-r--r--src/devices/mode/oneshot.rs21
1 files changed, 11 insertions, 10 deletions
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<DI, IC, E> Ads1x1x<DI, IC, mode::OneShot>
+impl<DI, IC, CONV, E> Ads1x1x<DI, IC, CONV, mode::OneShot>
where
DI: interface::WriteData<Error = E> + interface::ReadData<Error = E>,
- IC: ic::Resolution
+ CONV: conversion::ConvertMeasurement
{
/// Change operating mode to Continuous
- pub fn into_continuous(mut self) -> Result<Ads1x1x<DI, IC, mode::Continuous>, Error<E>> {
+ pub fn into_continuous(mut self) -> Result<Ads1x1x<DI, IC, CONV, mode::Continuous>, Error<E>> {
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<DI, IC, E, CH> hal::adc::OneShot<Ads1x1x<DI, IC, mode::OneShot>, i16, CH> for Ads1x1x<DI, IC, mode::OneShot>
+impl<DI, IC, CONV, E, CH> hal::adc::OneShot<Ads1x1x<DI, IC, CONV, mode::OneShot>, i16, CH>
+ for Ads1x1x<DI, IC, CONV, mode::OneShot>
where
DI: interface::ReadData<Error = E> + interface::WriteData<Error = E>,
- IC: ic::Resolution,
- CH: hal::adc::Channel<Ads1x1x<DI, IC, mode::OneShot>, ID = ChannelSelection>
+ CONV: conversion::ConvertMeasurement,
+ CH: hal::adc::Channel<Ads1x1x<DI, IC, CONV, mode::OneShot>, ID = ChannelSelection>
{
type Error = Error<E>;
@@ -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::<IC>(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)?;