simplify example code
This commit is contained in:
parent
cb341bf7d9
commit
f67f31223d
2 changed files with 20 additions and 51 deletions
38
README.md
38
README.md
|
@ -15,7 +15,7 @@ use linux_embedded_hal::{I2cdev, Delay};
|
|||
use i2cdev::linux::LinuxI2CError;
|
||||
|
||||
fn main() -> Result<(), Error<LinuxI2CError>> {
|
||||
let i2c = I2cdev::new("/dev/i2c-1") // or privide your owm on different platforms
|
||||
let i2c = I2cdev::new("/dev/i2c-1")
|
||||
.map_err(Error::I2c)?;
|
||||
|
||||
let delay = Delay;
|
||||
|
@ -25,40 +25,26 @@ fn main() -> Result<(), Error<LinuxI2CError>> {
|
|||
|
||||
loop {
|
||||
// get roll and pitch estimate
|
||||
match mpu.get_acc_angles() {
|
||||
Ok(r) => {
|
||||
println!("r/p: {:?}", r);
|
||||
},
|
||||
Err(_) => {} ,
|
||||
}
|
||||
let acc = mpu.get_acc_angles()?;
|
||||
println!("r/p: {:?}", acc);
|
||||
|
||||
// get temp
|
||||
match mpu.get_temp() {
|
||||
Ok(r) => {
|
||||
println!("temp: {}c", r);
|
||||
},
|
||||
Err(_) => {} ,
|
||||
}
|
||||
let temp = mpu.get_temp()?;
|
||||
println!("temp: {}c", temp);
|
||||
|
||||
// get gyro data, scaled with sensitivity
|
||||
match mpu.get_gyro() {
|
||||
Ok(r) => {
|
||||
println!("gyro: {:?}", r);
|
||||
},
|
||||
Err(_) => {} ,
|
||||
}
|
||||
let gyro = mpu.get_gyro()?;
|
||||
println!("gyro: {:?}", gyro);
|
||||
|
||||
// get accelerometer data, scaled with sensitivity
|
||||
match mpu.get_acc() {
|
||||
Ok(r) => {
|
||||
println!("acc: {:?}", r);
|
||||
},
|
||||
Err(_) => {} ,
|
||||
}
|
||||
let acc = mpu.get_acc()?;
|
||||
println!("acc: {:?}", acc);
|
||||
}
|
||||
}
|
||||
```
|
||||
#### Compile linux example (Rapsberry Pi 3B)
|
||||
*Note*: this example uses API of version published on crates.io. If you're using code directly from master, the example may be broken
|
||||
|
||||
#### Compile linux example (Raspberry Pi 3B)
|
||||
files [here](https://github.com/juliangaal/mpu6050/blob/master/example/)
|
||||
|
||||
Requirements:
|
||||
|
|
|
@ -10,39 +10,22 @@ fn main() -> Result<(), Error<LinuxI2CError>> {
|
|||
|
||||
let mut mpu = Mpu6050::new(i2c, delay);
|
||||
mpu.init()?;
|
||||
//mpu.soft_calib(200)?;
|
||||
|
||||
loop {
|
||||
// get roll and pitch estimate
|
||||
match mpu.get_acc_angles() {
|
||||
Ok(r) => {
|
||||
println!("r/p: {:?}", r);
|
||||
},
|
||||
Err(_) => {} ,
|
||||
}
|
||||
let acc = mpu.get_acc_angles()?;
|
||||
println!("r/p: {:?}", acc);
|
||||
|
||||
// get temp
|
||||
match mpu.get_temp() {
|
||||
Ok(r) => {
|
||||
println!("temp: {}c", r);
|
||||
},
|
||||
Err(_) => {} ,
|
||||
}
|
||||
let temp = mpu.get_temp()?;
|
||||
println!("temp: {}c", temp);
|
||||
|
||||
// get gyro data, scaled with sensitivity
|
||||
match mpu.get_gyro() {
|
||||
Ok(r) => {
|
||||
println!("gyro: {:?}", r);
|
||||
},
|
||||
Err(_) => {} ,
|
||||
}
|
||||
let gyro = mpu.get_gyro()?;
|
||||
println!("gyro: {:?}", gyro);
|
||||
|
||||
// get accelerometer data, scaled with sensitivity
|
||||
match mpu.get_acc() {
|
||||
Ok(r) => {
|
||||
println!("acc: {:?}", r);
|
||||
},
|
||||
Err(_) => {} ,
|
||||
}
|
||||
let acc = mpu.get_acc()?;
|
||||
println!("acc: {:?}", acc);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue