Read i2c device path from command line

This commit is contained in:
Klemens Schölhorn 2019-03-31 15:11:34 +02:00
parent 4c299adc9b
commit 170c598216

View File

@ -8,8 +8,16 @@ use i2cdev_bmp280::*;
use si7021::*;
use i2csensors::{Barometer, Hygrometer, Thermometer};
use std::env;
fn main() {
let i2c_device = LinuxI2CDevice::new("/dev/i2c-11", 0b1110110).unwrap();
let i2c_path = env::args().skip(1).next().expect("i2c bus path (eg. /dev/i2c-1)");
i2c_sensors(&i2c_path);
}
fn i2c_sensors(path: &str) {
let i2c_device = LinuxI2CDevice::new(path, 0b1110110).unwrap();
let settings = BMP280Settings {
compensation: BMP280CompensationAlgorithm::Float,
@ -25,7 +33,7 @@ fn main() {
println!("pressure: {:6.2} kPa", bmp280.pressure_kpa().unwrap());
println!("temp1: {:6.2} °C", bmp280.temperature_celsius().unwrap());
let device = LinuxI2CDevice::new("/dev/i2c-11", SI7021_I2C_ADDRESS).unwrap();
let device = LinuxI2CDevice::new(path, SI7021_I2C_ADDRESS).unwrap();
let mut si7021 = Si7021::new(device);
println!("humidity: {:6.2} %", si7021.relative_humidity().unwrap());
println!("temp2: {:6.2} °C", si7021.temperature_celsius().unwrap());