1 个不稳定版本
0.1.0 | 2024年1月25日 |
---|
#1900 在 嵌入式开发
25KB
456 行
嵌入式-qmp6988
这是一个使用嵌入式-hal
trait的跨平台Rust驱动程序,用于QMP6988数字气压传感器。
设备
QMP6988传感器是一种高精度、小尺寸、低功耗的气压传感器。
它可以通过I²C或SPI接口进行寻址。此驱动程序使用I²C接口。
文档
功能
- 选择用于测量的过采样设置。
- 选择用于降低测量噪声的IIR滤波器。
- 执行单次测量(使用强制电源模式)。
- 进行软件设置。
- 使用正常电源模式进行重复测量。
- 包括无浮点变体,适用于无fpu的系统。
用法
要使用此驱动程序,从此crate导入所需的项,然后实例化设备。
use embedded_qmp6988::{IirFilter, OverSamplingSetting, Qmp6988, DEFAULT_I2C_ADDRESS};
use linux_embedded_hal as hal;
fn main() -> Result<(), embedded_qmp6988::Error<hal::I2CError>> {
// Create the I2C device from the chosen embedded-hal implementation,
// in this case linux-embedded-hal
let i2c = match hal::I2cdev::new("/dev/i2c-1") {
Err(err) => {
eprintln!("Could not create I2C device: {}", err);
std::process::exit(1);
}
Ok(i2c) => i2c,
};
// Create the sensor and configure its repeatability
let mut sensor = Qmp6988::new(i2c, DEFAULT_I2C_ADDRESS, hal::Delay {})?;
sensor.set_filter(IirFilter::Off)?;
sensor.set_oversampling_setting(OverSamplingSetting::HighSpeed)?;
// Perform a barometric pressure measurement
let measurement = sensor.measure()?;
println!("Pressure: {:.2} hPa", measurement.pressure);
Ok(())
}
许可证
根据以下任一许可证授权:
- Apache许可证,版本2.0 (LICENSE-APACHE 或 https://apache.ac.cn/licenses/LICENSE-2.0)
- MIT许可证 (LICENSE-MIT 或 http://opensource.org/licenses/MIT)
任选其一。
贡献
除非你明确说明,否则根据Apache-2.0许可证定义,你故意提交的任何旨在包含在本作品中的贡献,都应按上述方式双许可,无需任何附加条款或条件。
依赖项
~275KB