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]
fn new<Path>(path: Path) -> Result<Magnetometer<LinuxI2CDevice>> where
Path: AsRef<Path>,
[src]
Path: AsRef<Path>,
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]
Dev: I2CDevice,
Error: From<Dev::Error>,
Dev::Error: Send + 'static,
fn from_i2c_device(device: Dev) -> Result<Magnetometer<Dev>>
[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)?;
fn read_magnetic_field(&mut self) -> Result<MagneticField>
[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);
fn set_gain(&mut self, gain: Gain) -> Result<()> where
Dev::Error: Send + 'static,
[src]
Dev::Error: Send + 'static,
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]
Dev: I2CDevice,
Access the underlying I2CDevice
.
Most of the methods require a mutable reference; DerefMut
is implemented as well.
type Target = Dev
The resulting type after dereferencing.
fn deref(&self) -> &Dev
[src]
Dereferences the value.
impl<Dev> DerefMut for Magnetometer<Dev> where
Dev: I2CDevice,
[src]
Dev: I2CDevice,
Access the underlying I2CDevice
.
Refer to the LSM303 datasheet if you plan on accessing the device directly.