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

#include <SensorQMC5883L.hpp>

Inheritance diagram for SensorQMC5883L:
[legend]

Public Member Functions

 SensorQMC5883L ()=default
 Default constructor.
 
 ~SensorQMC5883L ()=default
 Destructor.
 
bool readData (MagnetometerData &data) override
 Reads the magnetic field data from the sensor.
 
bool isDataReady () override
 Checks if new data is available from the sensor.
 
bool isDataOverflow ()
 Checks if data overflow has occurred.
 
bool isDataSkipped ()
 Checks if data has been skipped.
 
bool reset () override
 Resets the sensor to its default state.
 
bool selfTest () override
 QMC5883L does not support self-test checks.
 
bool setFullScaleRange (MagFullScaleRange range) override
 Sets the full-scale range of the magnetometer.
 
bool setOutputDataRate (float data_rate_hz) override
 Sets the bandwidth of the magnetometer.
 
bool setOperationMode (OperationMode mode) override
 Sets the operation mode of the magnetometer.
 
bool setOversamplingRate (MagOverSampleRatio osr) override
 Sets the oversampling rate of the magnetometer.
 
bool setDownsamplingRate (MagDownSampleRatio dsr) override
 QM5883L does not support downsampling.
 
bool getTemperature (float &temperature, int16_t &raw_temp)
 Gets the temperature reading from the sensor.
 
uint8_t getChipID () const
 Gets the chip ID of the magnetometer.
 
bool configMagnetometer (OperationMode mode, MagFullScaleRange range, float data_rate_hz, MagOverSampleRatio osr, MagDownSampleRatio dsr=MagDownSampleRatio::DSR_1) override
 Configures the magnetometer with multiple parameters.
 
- Public Member Functions inherited from MagnetometerBase
 MagnetometerBase ()
 Constructor for the MagnetometerBase class.
 
virtual ~MagnetometerBase ()=default
 Destructor for the MagnetometerBase class.
 
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.
 
- Public Member Functions inherited from I2CDeviceWithHal
bool begin (SensorCommCustom::CustomCallback cb, SensorCommCustomHal::CustomHalCallback hal_cb, uint8_t addr)
 Initialize the sensor using custom callback interface.
 
- Public Member Functions inherited from DeviceBeginCommon
virtual ~DeviceBeginCommon ()
 
uint8_t getAddress () const
 
uint8_t getInterface () const
 
- Public Member Functions inherited from SensorCommWrapper
 SensorCommWrapper ()=default
 
int readReg (uint8_t reg) const
 
int readRegBuff (uint8_t reg, uint8_t *buf, size_t len) const
 
int readBuff (uint8_t *buf, size_t len) const
 
int writeReg (uint8_t reg, uint8_t val)
 
int writeRegBuff (uint8_t reg, uint8_t *buf, size_t len)
 
int writeBuff (uint8_t *buf, size_t len)
 
int writeThenRead (const uint8_t *write_buffer, size_t write_len, uint8_t *read_buffer, size_t read_len)
 
bool setRegBit (uint8_t reg, uint8_t bit)
 
bool clrRegBit (uint8_t reg, uint8_t bit)
 
bool getRegBit (uint8_t reg, uint8_t bit)
 
int updateBits (uint8_t reg, uint8_t mask, uint8_t value_shifted)
 
void setAddress (uint8_t address)
 
void setAck (bool enable)
 
- Public Member Functions inherited from SensorCommInterface
virtual ~SensorCommInterface ()=default
 

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.
 
- Protected Member Functions inherited from I2CDeviceWithHal
bool ensureValid () const override
 Ensure the communication interface is valid.
 
- Protected Member Functions inherited from DeviceBeginCommon
 DeviceBeginCommon ()=default
 
virtual SensorCommBasegetComm () const override
 
virtual void beforeBegin ()
 
virtual void afterCommReady ()
 
virtual void afterInitSuccess (uint8_t param)
 
virtual void onBeginFail ()
 
bool fail ()
 
void clearCommState ()
 
template<typename CreateComm >
bool beginLifecycle (uint8_t addr, uint8_t iface, uint8_t initParam, CreateComm createComm)
 
- Protected Attributes inherited from MagnetometerBase
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
 
- Protected Attributes inherited from DeviceBeginCommon
std::unique_ptr< SensorCommBasecomm
 
std::unique_ptr< SensorHalhal
 
std::unique_ptr< SensorCommStaticstaticComm
 
uint8_t _addr = 0
 
uint8_t _iface = COMM_CUSTOM
 

Detailed Description

Definition at line 39 of file sensor/magnetometer/qmc/SensorQMC5883L.hpp.

Constructor & Destructor Documentation

◆ SensorQMC5883L()

SensorQMC5883L::SensorQMC5883L ( )
default

Default constructor.

Initializes communication and hardware abstraction pointers to nullptr.

Creates a SensorQMC5883L object with no active communication or hardware abstraction instances.

◆ ~SensorQMC5883L()

SensorQMC5883L::~SensorQMC5883L ( )
default

Destructor.

Deinitializes the communication object if it exists.

Ensures proper cleanup by deinitializing the communication interface when the sensor object is destroyed.

Member Function Documentation

◆ configMagnetometer()

bool SensorQMC5883L::configMagnetometer ( OperationMode  mode,
MagFullScaleRange  range,
float  data_rate_hz,
MagOverSampleRatio  osr,
MagDownSampleRatio  dsr = MagDownSampleRatio::DSR_1 
)
inlineoverridevirtual

Configures the magnetometer with multiple parameters.

Note
This function sets the operation mode, full-scale range, output data rate, oversampling ratio, and downsampling ratio of the magnetometer.
Parameters
modeSUSPEND, NORMAL, CONTINUOUS_MEASUREMENT
rangeFS_2G, FS_8G
data_rate_hzThe desired output data rate in Hz. Allowed values are 10.0, 50.0, 100.0 and 200.0HZ.
osrOSR_8, OSR_4, OSR_2, OSR_1
dsrPlaceholder parameters, meaningless
Return values
Trueif the configuration was successful, false otherwise.

Implements MagnetometerBase.

Definition at line 382 of file sensor/magnetometer/qmc/SensorQMC5883L.hpp.

References SENSORLIB_LOG_E, setFullScaleRange(), setOperationMode(), setOutputDataRate(), and setOversamplingRate().

Referenced by setup().

◆ getChipID()

uint8_t SensorQMC5883L::getChipID ( ) const
inline

Gets the chip ID of the magnetometer.

Note
This function retrieves the chip ID from the sensor.
Return values
Thechip ID.

Definition at line 366 of file sensor/magnetometer/qmc/SensorQMC5883L.hpp.

References SensorBase< MagnetometerData >::_info, and SensorInfo::uid.

◆ getTemperature()

bool SensorQMC5883L::getTemperature ( float &  temperature,
int16_t &  raw_temp 
)
inline

Gets the temperature reading from the sensor.

Todo:
The actual test result was 0, which may be due to a chip problem.
Note
This function retrieves the temperature data from the sensor.
Parameters
&temperatureThe temperature value in degrees Celsius.
&raw_tempThe raw temperature value from the sensor.
Return values
Trueif the temperature was read successfully, false otherwise.

Definition at line 346 of file sensor/magnetometer/qmc/SensorQMC5883L.hpp.

References SensorCommWrapper::readRegBuff(), SENSORLIB_LOG_E, and temperature().

◆ isDataOverflow()

bool SensorQMC5883L::isDataOverflow ( )
inline

Checks if data overflow has occurred.

Note
This function reads the status register to determine if the magnetic field data has overflowed.
Return values
Trueif data overflow has occurred, false otherwise.

Definition at line 144 of file sensor/magnetometer/qmc/SensorQMC5883L.hpp.

References SensorCommWrapper::getRegBit().

◆ isDataReady()

bool SensorQMC5883L::isDataReady ( )
inlineoverridevirtual

Checks if new data is available from the sensor.

Note
This function reads the status register to determine if new magnetic field data is ready to be processed.
Return values
Trueif new data is available, false otherwise.

Implements MagnetometerBase.

Definition at line 133 of file sensor/magnetometer/qmc/SensorQMC5883L.hpp.

References SensorCommWrapper::getRegBit().

◆ isDataSkipped()

bool SensorQMC5883L::isDataSkipped ( )
inline

Checks if data has been skipped.

Note
This function reads the status register to determine if the magnetic field data has been skipped.
Return values
Trueif data has been skipped, false otherwise.

Definition at line 155 of file sensor/magnetometer/qmc/SensorQMC5883L.hpp.

References SensorCommWrapper::getRegBit().

◆ readData()

bool SensorQMC5883L::readData ( MagnetometerData data)
inlineoverridevirtual

Reads the magnetic field data from the sensor.

Note
This function retrieves the latest magnetic field measurements from the sensor and stores them in the provided data structure.
Parameters
dataA reference to a MagnetometerData structure to store the retrieved magnetic field data.
Return values
Trueif the data was read successfully, false otherwise.

Implements MagnetometerBase.

Definition at line 67 of file sensor/magnetometer/qmc/SensorQMC5883L.hpp.

References MagnetometerBase::_declination_rad, sensorlib::_isBitSet(), SensorBase< MagnetometerData >::_sensitivity, SensorBase< MagnetometerData >::_x_offset, SensorBase< MagnetometerData >::_y_offset, SensorBase< MagnetometerData >::_z_offset, MagnetometerUtils::calculateHeading(), MagnetometerData::heading, MagnetometerData::heading_degrees, M_PI, MagnetometerData::magnetic_field, MagnetometerData::overflow, MagnetometerData::raw, SensorCommWrapper::readReg(), SensorCommWrapper::readRegBuff(), SENSORLIB_LOG_E, MagnetometerData::skip_data, x, SensorVector::x, RawVector::x, y, SensorVector::y, RawVector::y, SensorVector::z, and RawVector::z.

Referenced by loop().

◆ reset()

bool SensorQMC5883L::reset ( )
inlineoverridevirtual

Resets the sensor to its default state.

Note
This function sends a reset command to the sensor and waits for a short period to allow the reset to take effect.
Return values
Trueif the reset command was successful, false otherwise.

Implements MagnetometerBase.

Definition at line 166 of file sensor/magnetometer/qmc/SensorQMC5883L.hpp.

References DeviceBeginCommon::hal, and SensorCommWrapper::writeReg().

◆ selfTest()

bool SensorQMC5883L::selfTest ( )
inlineoverridevirtual

QMC5883L does not support self-test checks.

Note
This function is a placeholder and does not perform any actual self-test.
Return values
Alwaysreturn True.

Implements MagnetometerBase.

Definition at line 179 of file sensor/magnetometer/qmc/SensorQMC5883L.hpp.

References SENSORLIB_LOG_E.

◆ setDownsamplingRate()

bool SensorQMC5883L::setDownsamplingRate ( MagDownSampleRatio  dsr)
inlineoverridevirtual

QM5883L does not support downsampling.

Note
This function is a placeholder and does not perform any action.
Return values
alwaysfalse.

Implements MagnetometerBase.

Definition at line 332 of file sensor/magnetometer/qmc/SensorQMC5883L.hpp.

References SENSORLIB_LOG_E.

◆ setFullScaleRange()

bool SensorQMC5883L::setFullScaleRange ( MagFullScaleRange  range)
inlineoverridevirtual

Sets the full-scale range of the magnetometer.

Note
This function configures the magnetometer to operate within a specific range, affecting the sensitivity and maximum measurable magnetic field strength.
Parameters
rangeFS_2G, FS_8G
Return values
Trueif the range was set successfully, false otherwise.

Implements MagnetometerBase.

Definition at line 193 of file sensor/magnetometer/qmc/SensorQMC5883L.hpp.

References SensorBase< MagnetometerData >::_config, SensorBase< MagnetometerData >::_sensitivity, FS_2G, FS_8G, SensorConfig::range, SENSORLIB_LOG_E, and SensorCommWrapper::updateBits().

Referenced by configMagnetometer().

◆ setOperationMode()

bool SensorQMC5883L::setOperationMode ( OperationMode  mode)
inlineoverridevirtual

Sets the operation mode of the magnetometer.

Note
This function configures the magnetometer to operate in a specific mode, affecting its power consumption and measurement behavior.
Parameters
modeSUSPEND, NORMAL, CONTINUOUS_MEASUREMENT
Return values
Trueif the mode was set successfully, false otherwise.

Implements MagnetometerBase.

Definition at line 266 of file sensor/magnetometer/qmc/SensorQMC5883L.hpp.

References SensorBase< MagnetometerData >::_config, CONTINUOUS_MEASUREMENT, SensorConfig::mode, NORMAL, SENSORLIB_LOG_E, SUSPEND, and SensorCommWrapper::updateBits().

Referenced by configMagnetometer().

◆ setOutputDataRate()

bool SensorQMC5883L::setOutputDataRate ( float  data_rate_hz)
inlineoverridevirtual

Sets the bandwidth of the magnetometer.

Note
This function configures the magnetometer's bandwidth, affecting the trade-off between noise and response time.
Parameters
data_rate_hzThe desired output data rate in Hz. Allowed values are 10.0, 50.0, 100.0 and 200.0HZ.
Return values
Trueif the bandwidth was set successfully, false otherwise.

Implements MagnetometerBase.

Definition at line 229 of file sensor/magnetometer/qmc/SensorQMC5883L.hpp.

References SensorBase< MagnetometerData >::_config, SensorConfig::sample_rate, SENSORLIB_LOG_D, SENSORLIB_LOG_E, and SensorCommWrapper::updateBits().

Referenced by configMagnetometer().

◆ setOversamplingRate()

bool SensorQMC5883L::setOversamplingRate ( MagOverSampleRatio  osr)
inlineoverridevirtual

Sets the oversampling rate of the magnetometer.

Note
This function configures the magnetometer's oversampling rate, affecting the trade-off between noise and measurement speed.
Parameters
osrOSR_8, OSR_4, OSR_2, OSR_1
Return values
Trueif the oversampling rate was set successfully, false otherwise.

Implements MagnetometerBase.

Definition at line 296 of file sensor/magnetometer/qmc/SensorQMC5883L.hpp.

References MagnetometerBase::_oversampling_rate, OSR_1, OSR_2, OSR_4, OSR_8, SENSORLIB_LOG_E, and SensorCommWrapper::updateBits().

Referenced by configMagnetometer().


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