pub struct FS3000<Device: DeviceType, Client: ClientType, I2C> { /* private fields */ }
Expand description
A client for a FS3000 device via I2C.
When creating this client, the consumer has two make decisions: - Is the connected device a FS3000-1005 or FS3000-1015? The latter can measure larger air velocitys. - Is the consuming code blocking or async?
Both of these decisions are documented using marker traits.
§Blocking Example
use fs3000_rs::prelude::*;
// The [`BlockingBus`] is a fake `embedded_hal::i2c::I2c` for this example.
// In practice, you would create this [`embedded_hal::i2c::I2c`] via your platform hal.
let blocking_bus = BlockingBus::default();
// Assumes the FS3000-1015 (wider measurement range), substitute FS3000_
let mut client = FS3000::<FS3000_1015, Blocking, _>::new(DeviceAddr::default(), blocking_bus);
let mps = client.read_meters_per_second()?;
println!("We're going {mps} meters/second!");
§Async Example
use fs3000_rs::prelude::*;
// The [`BlockingBus`] is a fake `embedded_hal::i2c::I2c` for this example.
// In practice, you would create this [`embedded_hal::i2c::I2c`] via your platform hal.
let async_bus = AsyncBus::default();
let mut client = FS3000::<FS3000_1015, Async, _>::new(DeviceAddr::default(), async_bus);
let mps = client.read_meters_per_second().await.unwrap();
println!("We're going {mps} meters/second!");
Implementations§
Source§impl<Device: DeviceType, I2C> FS3000<Device, Blocking, I2C>where
I2C: I2c,
impl<Device: DeviceType, I2C> FS3000<Device, Blocking, I2C>where
I2C: I2c,
Sourcepub fn new(address: DeviceAddr, i2c: I2C) -> Self
pub fn new(address: DeviceAddr, i2c: I2C) -> Self
Create a new FS3000 instance.
Sourcepub fn read_meters_per_second(&mut self) -> Result<f32, Error<I2C::Error>>
pub fn read_meters_per_second(&mut self) -> Result<f32, Error<I2C::Error>>
Fetch a single, meters-per-second airflow measurement from the device.
Sourcepub fn read_raw(&mut self) -> Result<u16, Error<I2C::Error>>
pub fn read_raw(&mut self) -> Result<u16, Error<I2C::Error>>
Fetch a single, raw measurement from the device.
The measurement must be translated to a real unit for usage, consult
the datasheet for details. Otherwise, use FS3000::read_meters_per_second
to have
this conversion be handled for you.
Source§impl<Device: DeviceType, I2C> FS3000<Device, Async, I2C>where
I2C: I2c,
impl<Device: DeviceType, I2C> FS3000<Device, Async, I2C>where
I2C: I2c,
Sourcepub fn new(address: DeviceAddr, i2c: I2C) -> Self
pub fn new(address: DeviceAddr, i2c: I2C) -> Self
Create a new FS3000 instance.
Sourcepub async fn read_meters_per_second(&mut self) -> Result<f32, Error<I2C::Error>>
pub async fn read_meters_per_second(&mut self) -> Result<f32, Error<I2C::Error>>
Fetch a single, meters-per-second airflow measurement from the device.
Sourcepub async fn read_raw(&mut self) -> Result<u16, Error<I2C::Error>>
pub async fn read_raw(&mut self) -> Result<u16, Error<I2C::Error>>
Fetch a single, raw measurement from the device.
The measurement must be translated to a real unit for usage, consult
the datasheet for details. Otherwise, use FS3000::read_meters_per_second
to have
this conversion be handled for you.