Skip to main content

reporting

Function reporting 

Source
pub fn reporting(
    address: u8,
    celsius: f32,
    hectopascals: f32,
    relative_humidity: f32,
) -> I2cPart
Expand description

A BME280 that reads what you ask it to.

§Arguments

  • address - the address it answers to.
  • celsius - the temperature it should report.
  • hectopascals - the pressure it should report.
  • relative_humidity - the humidity it should report, as a percentage.

§Returns

The part. The readings land on the nearest ones its converter can represent, which is within a hundredth of a degree, a hundredth of a hectopascal, and a thousandth of a percent of what was asked for.

§Examples

use pamoja_core::Sensor;
use pamoja_hal::script::{block_on, DelayLog};
use pamoja_sensors::bme280::{sim, Bme280, I2C_ADDRESS_PRIMARY};

// A cold store at four degrees, which is the reading a driver should see.
let cold = sim::reporting(I2C_ADDRESS_PRIMARY, 4.0, 1013.25, 80.0);
let mut sensor = Bme280::i2c(cold, I2C_ADDRESS_PRIMARY, DelayLog::new());

let reading = block_on(sensor.read()).expect("the part answers");
assert_eq!(reading.celsius(), 4.0);
assert!((reading.hectopascals() - 1013.25).abs() < 0.01);