Skip to content

Commit

Permalink
Return a struct instead of a tuple from read
Browse files Browse the repository at this point in the history
  • Loading branch information
miksquared committed Oct 31, 2024
1 parent a224067 commit 8759d88
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions lib/sensors/src/accelerometer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ impl<T: HypedI2c> Accelerometer<T> {
Ok(Self{i2c, device_address})
}

/// Read the acceleration for each axis and return them as a floating point value in gs.
pub fn read(&mut self) -> Option<(f32, f32, f32)> {
/// Read the acceleration for each axis and return them as floating point values in gs.
pub fn read(&mut self) -> Option<AccelValues> {

// Read the low and high bytes of the acceleration and combine them to get the acceleration for each axis
let x_low_byte = self.i2c.read_byte(self.device_address, LIS2DS12_OUT_X_L)?;
Expand All @@ -56,7 +56,7 @@ impl<T: HypedI2c> Accelerometer<T> {
let y = y_combined * LIS2DS12_ACCEL_SCALING_FACTOR;
let z = z_combined * LIS2DS12_ACCEL_SCALING_FACTOR;

Some((x,y,z))
Some(AccelValues { x: x, y: y, z: z })
}

pub fn check_status(&mut self) -> Status {
Expand All @@ -68,6 +68,12 @@ impl<T: HypedI2c> Accelerometer<T> {

}

pub struct AccelValues {
x: f32,
y: f32,
z: f32,
}

pub enum AccelerometerAddresses {
Address1d = 0x1D,
Address1e = 0x1E,
Expand Down

0 comments on commit 8759d88

Please sign in to comment.