SensorLib 0.5.0
Multi-platform sensor driver library for Arduino, PlatformIO, and ESP-IDF
Loading...
Searching...
No Matches
MagnetometerBase Class Referenceabstract

#include <MagnetometerBase.hpp>

Inheritance diagram for MagnetometerBase:
[legend]

Public Member Functions

 MagnetometerBase ()
 Constructor for the MagnetometerBase class.
 
virtual ~MagnetometerBase ()=default
 Destructor for the MagnetometerBase class.
 
bool readData (MagnetometerData &data) override=0
 Checks if new data is available from the magnetometer.
 
bool isDataReady () override=0
 Checks if new data is available from the magnetometer.
 
bool reset () override=0
 Resets the magnetometer to its default settings.
 
bool selfTest () override=0
 Performs a self-test on the magnetometer.
 
virtual bool setFullScaleRange (MagFullScaleRange range)=0
 Sets the full-scale range for the magnetometer.
 
virtual bool setOutputDataRate (float odr)=0
 Sets the output data rate for the magnetometer.
 
virtual bool setOperationMode (OperationMode mode)=0
 Sets the operation mode for the magnetometer.
 
virtual bool setOversamplingRate (MagOverSampleRatio osr)=0
 Sets the oversampling rate for the magnetometer.
 
virtual bool setDownsamplingRate (MagDownSampleRatio dsr)=0
 Sets the downsampling rate for the magnetometer.
 
virtual bool configMagnetometer (OperationMode mode, MagFullScaleRange range, float data_rate_hz, MagOverSampleRatio osr, MagDownSampleRatio dsr)=0
 Configures the magnetometer with the specified settings.
 
virtual float getFullScaleRange () const
 Gets the full-scale range for the magnetometer.
 
virtual OperationMode getOperationMode () const
 Gets the operation mode for the magnetometer.
 
virtual uint16_t getOversamplingRate () const
 Gets the oversampling rate for the magnetometer.
 
virtual void setDeclination (float declination_deg)
 Set the magnetic declination correction value.
 
virtual float getDeclinationDeg () const
 Get the currently set magnetic declination in degrees.
 
virtual float getDeclinationRad () const
 Get the currently set magnetic declination in radians.
 
- Public Member Functions inherited from SensorBase< MagnetometerData >
 SensorBase (const SensorBase &)=delete
 
SensorBaseoperator= (const SensorBase &)=delete
 
void setOffset (int16_t x, int16_t y, int16_t z)
 Set sensor calibration offsets.
 
float getSensitivity () const
 Get sensor sensitivity.
 
SensorInfo getSensorInfo () const
 Get sensor information.
 
virtual SensorConfig getConfig () const
 Get current sensor configuration.
 

Protected Attributes

uint16_t _oversampling_rate
 
float _declination_rad
 
- Protected Attributes inherited from SensorBase< MagnetometerData >
SensorConfig _config
 Current configuration.
 
SensorInfo _info
 Sensor information.
 
int16_t _x_offset
 
int16_t _y_offset
 
int16_t _z_offset
 
float _sensitivity
 

Additional Inherited Members

- Protected Member Functions inherited from SensorBase< MagnetometerData >
 SensorBase (SensorType sensor_type=SensorType::UNKNOWN)
 Construct a new SensorBase object.
 
virtual ~SensorBase ()=default
 Virtual destructor for proper polymorphic cleanup.
 

Detailed Description

Definition at line 34 of file MagnetometerBase.hpp.

Constructor & Destructor Documentation

◆ MagnetometerBase()

MagnetometerBase::MagnetometerBase ( )
inlineexplicit

Constructor for the MagnetometerBase class.

Note
This constructor initializes the magnetometer with default settings.
Return values
None

Definition at line 43 of file MagnetometerBase.hpp.

◆ ~MagnetometerBase()

virtual MagnetometerBase::~MagnetometerBase ( )
virtualdefault

Destructor for the MagnetometerBase class.

Note
This virtual destructor ensures proper cleanup of derived classes.
Return values
None

Member Function Documentation

◆ configMagnetometer()

virtual bool MagnetometerBase::configMagnetometer ( OperationMode  mode,
MagFullScaleRange  range,
float  data_rate_hz,
MagOverSampleRatio  osr,
MagDownSampleRatio  dsr 
)
pure virtual

Configures the magnetometer with the specified settings.

Note
This function should be called to set up the sensor's operating parameters.
Parameters
modeThe desired operation mode.
rangeThe desired full-scale range.
data_rate_hzThe desired output data rate in Hz.
osrThe desired oversampling rate.
dsrThe desired downsampling rate.
Return values
Trueif the configuration was successful, false otherwise.

Implemented in SensorQMC5883L, SensorQMC6309, SensorQSTMagnetic, and SensorBMM150.

Referenced by setup().

◆ getDeclinationDeg()

virtual float MagnetometerBase::getDeclinationDeg ( ) const
inlinevirtual

Get the currently set magnetic declination in degrees.

Returns
Magnetic declination in degrees (positive east, negative west)

Definition at line 181 of file MagnetometerBase.hpp.

References _declination_rad, and M_PI.

◆ getDeclinationRad()

virtual float MagnetometerBase::getDeclinationRad ( ) const
inlinevirtual

Get the currently set magnetic declination in radians.

This is the internal representation used for calculations.

Returns
Magnetic declination in radians (positive east, negative west)

Definition at line 192 of file MagnetometerBase.hpp.

References _declination_rad.

◆ getFullScaleRange()

virtual float MagnetometerBase::getFullScaleRange ( ) const
inlinevirtual

Gets the full-scale range for the magnetometer.

Note
This function should be called to retrieve the sensor's measurement range.
Return values
Thecurrent full-scale range (e.g., 2.0, 4.0, 8.0, 16.0).

Definition at line 141 of file MagnetometerBase.hpp.

References SensorBase< MagnetometerData >::_config, and SensorConfig::range.

◆ getOperationMode()

virtual OperationMode MagnetometerBase::getOperationMode ( ) const
inlinevirtual

Gets the operation mode for the magnetometer.

Note
This function should be called to retrieve the sensor's current operation mode.
Return values
Thecurrent operation mode.

Definition at line 150 of file MagnetometerBase.hpp.

References SensorBase< MagnetometerData >::_config, and SensorConfig::mode.

◆ getOversamplingRate()

virtual uint16_t MagnetometerBase::getOversamplingRate ( ) const
inlinevirtual

Gets the oversampling rate for the magnetometer.

Note
This function should be called to retrieve the sensor's current oversampling rate.
Return values
Thecurrent oversampling rate.

Definition at line 159 of file MagnetometerBase.hpp.

References _oversampling_rate.

◆ isDataReady()

bool MagnetometerBase::isDataReady ( )
overridepure virtual

Checks if new data is available from the magnetometer.

Note
This function should be called periodically to determine if new sensor data is ready to be read.
Return values
Trueif new data is available, false otherwise.

Implements SensorBase< MagnetometerData >.

Implemented in SensorBMM150, SensorQMC5883L, SensorQMC6309, and SensorQSTMagnetic.

Referenced by calibrate().

◆ readData()

bool MagnetometerBase::readData ( MagnetometerData data)
overridepure virtual

Checks if new data is available from the magnetometer.

Note
This function should be called periodically to determine if new sensor data is ready to be read.
Return values
Trueif new data is available, false otherwise.

Implements SensorBase< MagnetometerData >.

Implemented in SensorBMM150, SensorQMC5883L, SensorQMC6309, and SensorQSTMagnetic.

Referenced by calibrate(), and loop().

◆ reset()

bool MagnetometerBase::reset ( )
overridepure virtual

Resets the magnetometer to its default settings.

Note
This function should be called to reset the sensor configuration.
Return values
Trueif the reset was successful, false otherwise.

Implements SensorBase< MagnetometerData >.

Implemented in SensorBMM150, SensorQMC5883L, SensorQMC6309, and SensorQSTMagnetic.

◆ selfTest()

bool MagnetometerBase::selfTest ( )
overridepure virtual

Performs a self-test on the magnetometer.

Note
This function should be called to verify the sensor's functionality.
Return values
Trueif the self-test passed, false otherwise.

Implements SensorBase< MagnetometerData >.

Implemented in SensorBMM150, SensorQMC5883L, SensorQMC6309, and SensorQSTMagnetic.

◆ setDeclination()

virtual void MagnetometerBase::setDeclination ( float  declination_deg)
inlinevirtual

Set the magnetic declination correction value.

Magnetic declination is the angle between true north (geographic north) and magnetic north. This correction is essential for accurate compass headings.

Note
Positive values indicate east declination, negative values indicate west declination. Example: +7.5° for Boulder, Colorado; -3.33° for London, UK.
Parameters
declination_degMagnetic declination in degrees

Definition at line 172 of file MagnetometerBase.hpp.

References _declination_rad, and M_PI.

Referenced by setup().

◆ setDownsamplingRate()

virtual bool MagnetometerBase::setDownsamplingRate ( MagDownSampleRatio  dsr)
pure virtual

Sets the downsampling rate for the magnetometer.

Note
This function should be called to configure the sensor's downsampling rate.
Parameters
dsrThe desired downsampling rate.
Return values
Trueif the downsampling rate was set successfully, false otherwise.

Implemented in SensorBMM150, SensorQMC5883L, SensorQMC6309, and SensorQSTMagnetic.

◆ setFullScaleRange()

virtual bool MagnetometerBase::setFullScaleRange ( MagFullScaleRange  range)
pure virtual

Sets the full-scale range for the magnetometer.

Note
This function should be called to configure the sensor's measurement range.
Parameters
rangeThe desired full-scale range.
Return values
Trueif the range was set successfully, false otherwise.

Implemented in SensorBMM150, SensorQMC5883L, SensorQMC6309, and SensorQSTMagnetic.

◆ setOperationMode()

virtual bool MagnetometerBase::setOperationMode ( OperationMode  mode)
pure virtual

Sets the operation mode for the magnetometer.

Note
This function should be called to configure the sensor's operation mode.
Parameters
modeThe desired operation mode.
Return values
Trueif the mode was set successfully, false otherwise.

Implemented in SensorBMM150, SensorQMC5883L, SensorQMC6309, and SensorQSTMagnetic.

◆ setOutputDataRate()

virtual bool MagnetometerBase::setOutputDataRate ( float  odr)
pure virtual

Sets the output data rate for the magnetometer.

Note
This function should be called to configure the sensor's output data rate.
Parameters
odrThe desired output data rate in Hz.
Return values
Trueif the output data rate was set successfully, false otherwise.

Implemented in SensorQMC5883L, SensorQMC6309, SensorBMM150, and SensorQSTMagnetic.

Referenced by calibrate().

◆ setOversamplingRate()

virtual bool MagnetometerBase::setOversamplingRate ( MagOverSampleRatio  osr)
pure virtual

Sets the oversampling rate for the magnetometer.

Note
This function should be called to configure the sensor's oversampling rate.
Parameters
osrThe desired oversampling rate.
Return values
Trueif the oversampling rate was set successfully, false otherwise.

Implemented in SensorBMM150, SensorQMC5883L, SensorQMC6309, and SensorQSTMagnetic.

Member Data Documentation

◆ _declination_rad

◆ _oversampling_rate


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