Skip to content

Commit

Permalink
bump accelerometer driver
Browse files Browse the repository at this point in the history
  • Loading branch information
lulf committed Jan 12, 2024
1 parent 99ee860 commit 39fb2f7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ embassy-time = { version = "0.3", default-features = false }
embassy-sync = { version = "0.5", default-features = false }
cortex-m = "0.7"
embedded-hal = "1.0"
lsm303agr = "0.2.2"
lsm303agr = "0.3"
defmt = "0.3"
futures = { version = "0.3", default-features = false }
13 changes: 6 additions & 7 deletions src/accelerometer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use embassy_sync::channel::DynamicSender;
use embassy_time::{Duration, Ticker};
use lsm303agr::interface::I2cInterface;
use lsm303agr::mode::MagOneShot;
use lsm303agr::{AccelMode, Error as LsmError, Lsm303agr, Status};
pub use lsm303agr::{AccelOutputDataRate, Measurement};
use lsm303agr::{AccelMode, Error as LsmError, Lsm303agr, Status, Acceleration};
pub use lsm303agr::{AccelOutputDataRate};

type I2C<'d> = twim::Twim<'d, TWISPI0>;

Expand All @@ -33,8 +33,7 @@ impl<'d> Accelerometer<'d> {

let mut sensor = Lsm303agr::new_with_i2c(twi);
sensor.init()?;
sensor.set_accel_odr(AccelOutputDataRate::Hz10)?;
sensor.set_accel_mode(AccelMode::Normal)?;
sensor.set_accel_mode_and_odr(&mut embassy_time::Delay, AccelMode::Normal, AccelOutputDataRate::Hz10)?;

Ok(Self { sensor })
}
Expand All @@ -47,15 +46,15 @@ impl<'d> Accelerometer<'d> {
/// Return accelerometer data
///
/// Returned in mg (milli-g) where 1g is 9.8m/s².
pub fn accel_data(&mut self) -> Result<Measurement, Error> {
self.sensor.accel_data()
pub fn accel_data(&mut self) -> Result<Acceleration, Error> {
self.sensor.acceleration()
}

/// Run a continuous task outputing accelerometer data at the configured data rate
pub async fn run(
&mut self,
rate: AccelOutputDataRate,
sender: DynamicSender<'_, Measurement>,
sender: DynamicSender<'_, Acceleration>,
) -> Result<(), Error> {
let delay = match rate {
AccelOutputDataRate::Hz1 => Duration::from_millis(1000),
Expand Down

0 comments on commit 39fb2f7

Please sign in to comment.