[][src]Struct ccs811::chip::CCS811

pub struct CCS811 {
    pub i2c: I2c,
    pub wake: Option<OutputPin>,
}

Fields

i2c: I2cwake: Option<OutputPin>

Methods

impl CCS811[src]

pub fn begin(&mut self) -> Result<(), String>[src]

Initialize CCS811 chip with i2c bus Sequence: set i2c slave -> Wake to low -> reset chip -> check hardware id -> start chip -> check chip status -> Wake to high -> ready

Examples

let mut ccs811 = ccs811::new(i2c, None);

match ccs811.begin() {
  Ok(()) => println!("Chip is ready"),
  Err(error) => panic!("Could not init the chip: {}", error)
}

pub fn start(&mut self, mode: Ccs811Mode) -> Result<(), String>[src]

Put CCS811 chip into target mode. Be aware that the first sampled data will be available after the period of time the mode takes. For instance it will take at least 60 seconds data will be first available in the Sec60 mode. For the Sec10 mode it is at least 10 seconds etc. Also be aware that the documentation of the chip mentions to change the chip mode to a lower sampling rate like Sec1 to Sec60, the mode should be set to Idle for at least 10 minutes before the setting the new mode.

Examples

let mut ccs811 = ccs811::new(i2c, None);

match ccs811.begin() {
  Ok(()) => match ccs811.start(ccs811::MODE::Sec1) {
    Ok(()) => (),
    Err(error) => panic!("Could not start: {}", error)
  },
  Err(error) => panic!("Could not init the chip: {}", error)
}

pub fn hardware_version(&mut self) -> Result<u8, String>[src]

Version should be something like 0x1X

pub fn bootloader_version(&mut self) -> Result<[u8; 2], String>[src]

Something like 0x10 0x0

pub fn application_version(&mut self) -> Result<[u8; 2], String>[src]

Something like 0x10 0x0 or higher. You can flash a newer firmware (2.0.0) using the flash method and a firmware binary. See examples for more details

pub fn get_baseline(&mut self) -> Result<u16, String>[src]

Get the currently used baseline

pub fn set_baseline(&mut self, baseline: u16) -> Result<(), String>[src]

The CCS811 chip has an automatic baseline correction based on a 24 hour interval but you still can set the baseline manually if you want.

pub fn set_env_data(
    &mut self,
    humidity: f32,
    temperature: f32
) -> Result<(), String>
[src]

Set environmental data measured by external sensors to the chip to include those in calculations. E.g. humidity 48.5% and 23.3°C

Examples

match ccs811.set_env_data(48.5, 23.3) {
  Ok(()) => println!("Updated environmental data on chip"),
  Err(error) => panic!("Failed to set environmental data on chip because {}", error)
}

pub fn read(&mut self) -> Result<Ccs811Data, String>[src]

Read last sampled eCO2, tVOC and the corresponding status, error and raw data from the chip register

Examples

match ccs811.read() {
  Ok(data) => {
    println!("t_voc: {}, e_co2: {}, raw: {:x?}", data.t_voc, data.e_co2, data.raw);
  },
  Err(error) => println!("Could not read data: {}", error)
};

pub fn flash(&mut self, data: Vec<u8>) -> Result<(), String>[src]

Flash another firmware to the CCS811 chip. The firmware can be found in the world wide web in form of an binary file which must be read and passed as byte array to this function. If flashing fails the chip still got a working boot loader which makes it possible to write another firmware to the chip and fix the issue.

Examples

use std::fs::File;
use std::io::Read;

let mut ccs811 = ccs811::new(i2c, None);

let mut file = File::open("./CCS811_FW_App_v2-0-1.bin")
    .expect("No firmware found");
let mut data = vec![];
let read = file.read_to_end(&mut data)
    .expect("Could not load firmware");

println!("Firmware has size of {} bytes", read);

ccs811.flash(data)
.expect("Failed to flash firmware");

println!("Flashed :)");

Auto Trait Implementations

impl !RefUnwindSafe for CCS811

impl Send for CCS811

impl !Sync for CCS811

impl Unpin for CCS811

impl !UnwindSafe for CCS811

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.