DUDS
Distributed Update of Data from Something
duds::hardware::devices::instruments::LSM9DS1Mag Class Reference

Initial support of the magnetometer of the LSM9DS1. More...

#include <LSM9DS1.hpp>

Inheritance diagram for duds::hardware::devices::instruments::LSM9DS1Mag:
Collaboration diagram for duds::hardware::devices::instruments::LSM9DS1Mag:

Classes

union  RawSample
 Stores the sample data as reported by the device. More...
 
struct  Settings
 The various settings for the device packed into an integer to avoid passing a lot of parameters. More...
 

Public Types

typedef duds::data::QuantityXyz ConvertedQuantity
 The sample data converted to Tesla. More...
 
enum  MagAxesMode { AxesLowPower, AxesLowPerformance, AxesMediumPerformance, AxesHighPerformance }
 Selects an operation mode for the axes. More...
 
enum  MagRange { MagRange400uT, MagRange800uT, MagRange1200uT, MagRange1600uT }
 The maximum magnitude options for the magnetometer. More...
 

Public Member Functions

 LSM9DS1Mag (std::unique_ptr< duds::hardware::interface::I2c > &i2c)
 Attempts to identify the device, then suspends the device's operation. More...
 
 ~LSM9DS1Mag ()
 Calls suspend(). More...
 
void configure (float freq, Settings settings)
 Configures the device. More...
 
void quantity (ConvertedQuantity &ps) const
 
const RawSamplerawSample () const
 Returns the magnetometer data as read from the device. More...
 
void resume ()
 Resumes operation after a call to suspend(). More...
 
bool sample ()
 Reads sampled data from the device. More...
 
float sampleRate () const
 Returns the confiured sampling rate. More...
 
void start ()
 Tells the device to start sampling. More...
 
void suspend ()
 Suspends operation by putting the device into a low-power mode that discontinues sampling. More...
 

Private Attributes

Settings cfg
 The current various configuration options. More...
 
duds::hardware::interface::Conversation initialize
 The conversation used to initialize the device. More...
 
std::unique_ptr< duds::hardware::interface::I2cmagcom
 The I2C communication interface. More...
 
RawSample magn
 The values supplied by the device. More...
 
duds::hardware::interface::Conversation magsample
 The conversation used to read in samples from the device. More...
 
float mdatarate
 The currently configured sample rate. More...
 
std::int8_t mdrval
 The data rate value given to the device. More...
 
duds::hardware::interface::Conversation statq
 

Detailed Description

Initial support of the magnetometer of the LSM9DS1.

The accelerometer and gyroscope are supported by LSM9DS1AccelGyro because it acts like an independent device. The documentation makes it seem as though the LSM9DS1 is really two devices stuck together.

The axes for the magnetometer are not the same as the accelerometer and gyroscope. The magnetometer's axes are the accelerometer's axes rotated about the Z-axis 90 degrees such that the +X axis is rotated to the accelerometer's -Y axis. This class will modify the magnetometer's data to have the same axes because having different axes is bizarre.

The Sparkfun board I've got uses I2C address 0x1E for the magnetometer.

Author
Jeff Jackowski

Definition at line 282 of file LSM9DS1.hpp.

Member Typedef Documentation

◆ ConvertedQuantity

The sample data converted to Tesla.

Definition at line 299 of file LSM9DS1.hpp.

Member Enumeration Documentation

◆ MagAxesMode

Selects an operation mode for the axes.

The documentation isn't clear on anything here, so take a guess as to what these options do.

Enumerator
AxesLowPower 

Use a low power mode.

The relation with the low-power mode for the whole magnetometer isn't specified in the documentation.

AxesLowPerformance 

Called medium performance in the doc; renamed to avoid buzzwords.

AxesMediumPerformance 

Called high performance in the doc; renamed to avoid buzzwords.

AxesHighPerformance 

Buzzword high performance in the doc; renamed to avoid stupid.

Definition at line 313 of file LSM9DS1.hpp.

◆ MagRange

The maximum magnitude options for the magnetometer.

Enumerator
MagRange400uT 

400 microtesla

MagRange800uT 

800 microtesla

MagRange1200uT 

1200 microtesla

MagRange1600uT 

1600 microtesla

Definition at line 303 of file LSM9DS1.hpp.

Constructor & Destructor Documentation

◆ LSM9DS1Mag()

duds::hardware::devices::instruments::LSM9DS1Mag::LSM9DS1Mag ( std::unique_ptr< duds::hardware::interface::I2c > &  i2c)

Attempts to identify the device, then suspends the device's operation.

This resets the device, which requires 2ms to complete.

Sparkfun's board uses device address 0x1E.

Postcondition
The device is suspended.
Parameters
i2cThe I2C object to use to communicate with the magnetometer part of the device. This LSM9DS1 object will take ownership over the communicator.
Postcondition
The provided i2c unique_ptr no longer contains an object upon success. If any exception is thrown, the unique_ptr will retain the object.
Exceptions
DeviceMisidentifiedThe reported device ID is incorrect.

Definition at line 368 of file LSM9DS1.cpp.

◆ ~LSM9DS1Mag()

duds::hardware::devices::instruments::LSM9DS1Mag::~LSM9DS1Mag ( )

Calls suspend().

Definition at line 414 of file LSM9DS1.cpp.

Member Function Documentation

◆ configure()

void duds::hardware::devices::instruments::LSM9DS1Mag::configure ( float  freq,
Settings  settings 
)

Configures the device.

Postcondition
The device will be suspended.
Parameters
freqThe minimum sample frequency. If the rate is too high, LSM9DS1BadDataRate will be thrown.
settingsThe requested device configuration.
Exceptions
LSM9DS1NoInsturmentThe configuration does not select either the accelerometer or magnetometer for use.
LSM9DS1BadMagnitudeThe requested maximum magnetude for the accelerometer is either not supported or an invalid value.
LSM9DS1BadDataRate

Definition at line 418 of file LSM9DS1.cpp.

◆ quantity()

void duds::hardware::devices::instruments::LSM9DS1Mag::quantity ( ConvertedQuantity ps) const

Definition at line 501 of file LSM9DS1.cpp.

◆ rawSample()

const RawSample& duds::hardware::devices::instruments::LSM9DS1Mag::rawSample ( ) const
inline

Returns the magnetometer data as read from the device.

Note
The values will change when the device is sampled and the magnetometer is in use.

Definition at line 475 of file LSM9DS1.hpp.

◆ resume()

void duds::hardware::devices::instruments::LSM9DS1Mag::resume ( )
inline

Resumes operation after a call to suspend().

Seems to be a nice name that I used with other device drivers, so I put it here until I do more to figure out a consistent interface that I like.

Exceptions
DeviceUninitalizedinit() hasn't been called.

Definition at line 455 of file LSM9DS1.hpp.

◆ sample()

bool duds::hardware::devices::instruments::LSM9DS1Mag::sample ( )

Reads sampled data from the device.

Returns
True if the device had new data.

Definition at line 481 of file LSM9DS1.cpp.

◆ sampleRate()

float duds::hardware::devices::instruments::LSM9DS1Mag::sampleRate ( ) const
inline

Returns the confiured sampling rate.

The value will be zero if configure() has not yet been called, or if it failed.

Definition at line 467 of file LSM9DS1.hpp.

◆ start()

void duds::hardware::devices::instruments::LSM9DS1Mag::start ( )
inline

Tells the device to start sampling.

Precondition
configure() has been called and succeeded.

Definition at line 439 of file LSM9DS1.hpp.

◆ suspend()

void duds::hardware::devices::instruments::LSM9DS1Mag::suspend ( )

Suspends operation by putting the device into a low-power mode that discontinues sampling.

This may require as much as 300ms to complete if the magnetometer is in use.

Definition at line 474 of file LSM9DS1.cpp.

Referenced by configure(), and ~LSM9DS1Mag().

Member Data Documentation

◆ cfg

Settings duds::hardware::devices::instruments::LSM9DS1Mag::cfg
private

The current various configuration options.

Definition at line 392 of file LSM9DS1.hpp.

Referenced by configure(), quantity(), and sample().

◆ initialize

duds::hardware::interface::Conversation duds::hardware::devices::instruments::LSM9DS1Mag::initialize
private

The conversation used to initialize the device.

It is created in init() and held for later use by resume().

Definition at line 376 of file LSM9DS1.hpp.

◆ magcom

std::unique_ptr<duds::hardware::interface::I2c> duds::hardware::devices::instruments::LSM9DS1Mag::magcom
private

The I2C communication interface.

Definition at line 371 of file LSM9DS1.hpp.

Referenced by configure(), LSM9DS1Mag(), sample(), and suspend().

◆ magn

RawSample duds::hardware::devices::instruments::LSM9DS1Mag::magn
private

The values supplied by the device.

Definition at line 384 of file LSM9DS1.hpp.

Referenced by quantity(), and sample().

◆ magsample

duds::hardware::interface::Conversation duds::hardware::devices::instruments::LSM9DS1Mag::magsample
private

The conversation used to read in samples from the device.

Definition at line 380 of file LSM9DS1.hpp.

Referenced by configure(), and sample().

◆ mdatarate

float duds::hardware::devices::instruments::LSM9DS1Mag::mdatarate
private

The currently configured sample rate.

Definition at line 388 of file LSM9DS1.hpp.

Referenced by configure().

◆ mdrval

std::int8_t duds::hardware::devices::instruments::LSM9DS1Mag::mdrval
private

The data rate value given to the device.

Definition at line 396 of file LSM9DS1.hpp.

Referenced by configure().

◆ statq

duds::hardware::interface::Conversation duds::hardware::devices::instruments::LSM9DS1Mag::statq
private

Definition at line 380 of file LSM9DS1.hpp.

Referenced by configure(), and sample().


The documentation for this class was generated from the following files: