iaq_core/lib.rs
1//! This is a platform agnostic Rust driver for the iAQ-Core sensors
2//! to measure VOC levels and provide CO2 equivalent and TVOC
3//! equivalent predictions using the [`embedded-hal`] traits.
4//!
5//! [`embedded-hal`]: https://github.com/rust-embedded/embedded-hal
6//!
7//! This driver allows you to:
8//! - Read all the sensor data at once. See: [`data()`].
9//! - Read the CO2 equivalent prediction value in ppm. See: [`co2()`].
10//! - Read the TVOC equivalent prediction value in ppb. See: [`tvoc()`].
11//! - Read the sensor resistance in Ohm. See: [`resistance()`].
12//!
13//! [`data()`]: struct.IaqCore.html#method.data
14//! [`co2()`]: struct.IaqCore.html#method.co2
15//! [`tvoc()`]: struct.IaqCore.html#method.tvoc
16//! [`resistance()`]: struct.IaqCore.html#method.resistance
17//!
18//! <!-- TODO
19//! [Introductory blog post](TODO)
20//! -->
21//!
22//! ## The devices
23//!
24//! The ams iAQ-core Indoor Air Quality Module is a low-cost, ultracompact
25//! solution for detecting poor air quality. It is equipped with an MOS sensor
26//! element for the detection of a broad range of reducing gases such as CO
27//! and VOCs. A change of resistance in the presence of these gases generates
28//! a signal that is translated into parts per million (ppm) CO2 equivalent or
29//! parts per billion (ppb) TVOC equivalent units.
30//!
31//! When defined threshold limits are exceeded, the module signals the system
32//! to initiate activities such as increasing ventilation, releasing fragrance,
33//! providing a message to open a window, switching on an air cleaner, etc.
34//! When VOC levels are minimized, the module instructs the system to return
35//! to standby, thereby saving energy, lowering operating costs and maintaining
36//! a healthy environment.
37//!
38//! In any demand-controlled ventilation/actuation environment where air
39//! quality is important, including commercial and residential facilities
40//! (offices, classrooms, kitchens, bathrooms, living and bedrooms etc.)
41//! the iAQ-core Indoor Air Quality Module performs accurately and reliably.
42//! Plus, the module’s small size opens up a wide variety of new applications
43//! where space is at a premium.
44//!
45//! Documentation:
46//! - [Datasheet](https://ams.com/documents/20143/36005/iAQ-core_DS000334_1-00.pdf)
47//! - [Factsheet](https://ams.com/documents/20143/36005/iAQ-core_FS000136_1-00.pdf)
48//!
49//! ## Usage examples (see also examples folder)
50//!
51//! To use this driver, import this crate and an `embedded_hal` implementation,
52//! then create an instance of the driver.
53//!
54//! Please find additional examples using hardware in this repository: [driver-examples]
55//!
56//! [driver-examples]: https://github.com/eldruin/driver-examples
57//!
58//! ### Create an instance of the driver and print the measurements
59//!
60//! ```no_run
61//! use iaq_core::IaqCore;
62//! use linux_embedded_hal::I2cdev;
63//! use nb::block;
64//!
65//! # fn main() {
66//! let dev = I2cdev::new("/dev/i2c-1").unwrap();
67//! let mut sensor = IaqCore::new(dev);
68//! loop {
69//! let data = block!(sensor.data()).unwrap();
70//! println!(
71//! "CO2: {} ppm, TVOC: {} ppm, Resistance: {} Ohm",
72//! data.co2, data.tvoc, data.resistance
73//! );
74//! }
75//! # }
76//! ```
77//!
78//! ### Get the CO2 and TVOC prediction values independently
79//!
80//! In case you are only interested in one of them, for example.
81//!
82//! ```no_run
83//! use iaq_core::IaqCore;
84//! use linux_embedded_hal::I2cdev;
85//! use nb::block;
86//!
87//! # fn main() {
88//! let dev = I2cdev::new("/dev/i2c-1").unwrap();
89//! let mut sensor = IaqCore::new(dev);
90//! loop {
91//! let co2 = block!(sensor.co2()).unwrap();
92//! let tvoc = block!(sensor.tvoc()).unwrap();
93//! println!("CO2: {} ppm, TVOC: {} ppb", co2, tvoc);
94//! }
95//! # }
96//! ```
97//!
98//! ### Get only the raw sensor resistance value
99//!
100//! ```no_run
101//! use iaq_core::IaqCore;
102//! use linux_embedded_hal::I2cdev;
103//! use nb::block;
104//!
105//! # fn main() {
106//! let dev = I2cdev::new("/dev/i2c-1").unwrap();
107//! let mut sensor = IaqCore::new(dev);
108//! loop {
109//! let r = block!(sensor.resistance()).unwrap();
110//! println!("Resistance: {} Ohm", r);
111//! }
112//! # }
113//! ```
114
115#![deny(unsafe_code, missing_docs)]
116#![no_std]
117
118use embedded_hal as hal;
119
120mod device_impl;
121mod types;
122pub use crate::types::{Error, Measurement};
123
124/// iAQ-Core device driver
125#[derive(Debug)]
126pub struct IaqCore<I2C> {
127 /// The concrete I²C device implementation.
128 i2c: I2C,
129}