Struct lsm303::magnetometer::Magnetometer [] [src]

pub struct Magnetometer<Dev> where
    Dev: I2CDevice
{ /* fields omitted */ }

Interface to an LSM303 digital magnetometer.

Methods

impl Magnetometer<LinuxI2CDevice>
[src]

[src]

Initialize the magnetometer for a Linux I2C device.

let sensor = Magnetometer::new("/dev/i2c-1");

impl<Dev> Magnetometer<Dev> where
    Dev: I2CDevice,
    Error: From<Dev::Error>,
    Dev::Error: Send + 'static, 
[src]

[src]

Initialize the magnetometer, given an open I2C device.

The opening of the device is platform specific, but initialization of the sensor is not. Prefer to use Accelerometer::new, unless you are using an implementation of I2CDevice that is not covered by this crate.

let device = LinuxI2CDevice::new("/dev/i2c-1", 0x3C >> 1)?;
let sensor = Magnetometer::from_i2c_device(device)?;

[src]

Read the magnetometer, returning the magnetic field as a vector.

let mut sensor = Magnetometer::new("/dev/i2c-1")?;
let field = sensor.read_magnetic_field()?;
println!("Magnetic field: ({}, {}, {})",
    field.x, field.y, field.z);

[src]

Set the gain of the magnetometer.

let mut sensor = Magnetometer::new("/dev/i2c-1")?;
sensor.set_gain(Gain::Gain_4_0)?;

Trait Implementations

impl<Dev> Deref for Magnetometer<Dev> where
    Dev: I2CDevice
[src]

Access the underlying I2CDevice.

Most of the methods require a mutable reference; DerefMut is implemented as well.

The resulting type after dereferencing.

[src]

Dereferences the value.

impl<Dev> DerefMut for Magnetometer<Dev> where
    Dev: I2CDevice
[src]

Access the underlying I2CDevice.

Refer to the LSM303 datasheet if you plan on accessing the device directly.

[src]

Mutably dereferences the value.