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

#include <SensorQMC6309.hpp>

Inheritance diagram for SensorQMC6309:
[legend]

Public Types

enum class  MagSetResetMode { SET_AND_RESET_ON , SET_ONLY_ON , SET_AND_RESET_OFF }
 
enum class  VoltageMode { KEEP , VDD_MODE1 , VDD_MODE2 }
 

Public Member Functions

 SensorQMC6309 ()=default
 Default constructor.
 
 ~SensorQMC6309 ()=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 isNVMReady ()
 Checks if the NVM is ready for access.
 
bool isNVMLoadDone ()
 Checks if the NVM load is complete.
 
bool reset () override
 Resets the sensor to its default state.
 
bool selfTest () override
 Checks if the sensor is functioning correctly.
 
bool selfTest (int16_t &x_result, int16_t &y_result, int16_t &z_result)
 Performs a self-test on the sensor.
 
bool setFullScaleRange (MagFullScaleRange range) override
 Sets the full-scale range of the magnetometer.
 
bool setOutputDataRate (float data_rate_hz) override
 Sets the output data rate for 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
 Sets the downsampling rate of the magnetometer.
 
bool setLowPassFilter (MagLowPassFilter lpf)
 Sets the low-pass filter of the magnetometer.
 
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.
 
bool setSetResetMode (MagSetResetMode mode)
 Sets the set/reset mode of the magnetometer.
 
void setVoltageMode (VoltageMode mode)
 Set the voltage mode for QMC6309H variant.
 
- 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 41 of file sensor/magnetometer/qmc/SensorQMC6309.hpp.

Member Enumeration Documentation

◆ MagSetResetMode

enum class SensorQMC6309::MagSetResetMode
strong
Enumerator
SET_AND_RESET_ON 
SET_ONLY_ON 
SET_AND_RESET_OFF 

Definition at line 45 of file sensor/magnetometer/qmc/SensorQMC6309.hpp.

◆ VoltageMode

enum class SensorQMC6309::VoltageMode
strong
Enumerator
KEEP 
VDD_MODE1 
VDD_MODE2 

Definition at line 51 of file sensor/magnetometer/qmc/SensorQMC6309.hpp.

Constructor & Destructor Documentation

◆ SensorQMC6309()

SensorQMC6309::SensorQMC6309 ( )
default

Default constructor.

Initializes communication and hardware abstraction pointers to nullptr.

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

◆ ~SensorQMC6309()

SensorQMC6309::~SensorQMC6309 ( )
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 SensorQMC6309::configMagnetometer ( OperationMode  mode,
MagFullScaleRange  range,
float  data_rate_hz,
MagOverSampleRatio  osr,
MagDownSampleRatio  dsr = MagDownSampleRatio::DSR_1 
)
inlineoverridevirtual

Configures the magnetometer with multiple parameters.

Note
QMC6309 supports oversampling rate (OSR) settings.
Parameters
modeSUSPEND, NORMAL, SINGLE_MEASUREMENT, CONTINUOUS_MEASUREMENT
rangeFS_8G, FS_16G, FS_32G
data_rate_hzAllowed values are 1.0, 10.0, 50.0, 100.0 and 200.0HZ.
osrOSR_8, OSR_4, OSR_2, OSR_1
dsrQMC6309 does not support downsampling rate settings; this parameter is ignored.
Return values
Trueif the configuration was successful, false otherwise.

Implements MagnetometerBase.

Definition at line 497 of file sensor/magnetometer/qmc/SensorQMC6309.hpp.

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

Referenced by setup().

◆ getChipID()

uint8_t SensorQMC6309::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 482 of file sensor/magnetometer/qmc/SensorQMC6309.hpp.

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

◆ isDataOverflow()

bool SensorQMC6309::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 148 of file sensor/magnetometer/qmc/SensorQMC6309.hpp.

References SensorCommWrapper::getRegBit().

◆ isDataReady()

bool SensorQMC6309::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 137 of file sensor/magnetometer/qmc/SensorQMC6309.hpp.

References SensorCommWrapper::getRegBit().

◆ isNVMLoadDone()

bool SensorQMC6309::isNVMLoadDone ( )
inline

Checks if the NVM load is complete.

Note
This function reads the status register to determine if the NVM load is complete.
Return values
Trueif the NVM load is complete, false otherwise.

Definition at line 170 of file sensor/magnetometer/qmc/SensorQMC6309.hpp.

References SensorCommWrapper::getRegBit().

◆ isNVMReady()

bool SensorQMC6309::isNVMReady ( )
inline

Checks if the NVM is ready for access.

Note
This function reads the status register to determine if the NVM is ready.
Return values
Trueif the NVM is ready, false otherwise.

Definition at line 159 of file sensor/magnetometer/qmc/SensorQMC6309.hpp.

References SensorCommWrapper::getRegBit().

◆ readData()

bool SensorQMC6309::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 81 of file sensor/magnetometer/qmc/SensorQMC6309.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, SENSORLIB_LOG_W, SensorVector::x, RawVector::x, SensorVector::y, RawVector::y, SensorVector::z, and RawVector::z.

Referenced by loop().

◆ reset()

bool SensorQMC6309::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 181 of file sensor/magnetometer/qmc/SensorQMC6309.hpp.

References sensorlib::_isBitSet(), DeviceBeginCommon::hal, SensorCommWrapper::readReg(), SENSORLIB_LOG_E, and SensorCommWrapper::writeReg().

◆ selfTest() [1/2]

bool SensorQMC6309::selfTest ( )
inlineoverridevirtual

Checks if the sensor is functioning correctly.

Note
This function performs a self-test by comparing the magnetic field readings before and after enabling self-test mode.
Return values
Trueif the self-test passed, false otherwise.

Implements MagnetometerBase.

Definition at line 213 of file sensor/magnetometer/qmc/SensorQMC6309.hpp.

References selfTest().

Referenced by selfTest(), and setup().

◆ selfTest() [2/2]

bool SensorQMC6309::selfTest ( int16_t &  x_result,
int16_t &  y_result,
int16_t &  z_result 
)
inline

Performs a self-test on the sensor.

Parameters
&x_resultSelf-test X-axis value from register 0x13
&y_resultSelf-test Y-axis value from register 0x14
&z_resultSelf-test Z-axis value from register 0x15
Return values
Trueif the self-test passed, false otherwise.

Definition at line 226 of file sensor/magnetometer/qmc/SensorQMC6309.hpp.

References CONTINUOUS_MEASUREMENT, SensorCommWrapper::getRegBit(), DeviceBeginCommon::hal, SensorCommWrapper::readReg(), SENSORLIB_LOG_E, SENSORLIB_LOG_W, setOperationMode(), SUSPEND, and SensorCommWrapper::writeReg().

◆ setDownsamplingRate()

bool SensorQMC6309::setDownsamplingRate ( MagDownSampleRatio  dsr)
inlineoverridevirtual

Sets the downsampling rate of the magnetometer.

Return values
Trueif the downsampling rate was set successfully, false otherwise.

Implements MagnetometerBase.

Definition at line 438 of file sensor/magnetometer/qmc/SensorQMC6309.hpp.

References SENSORLIB_LOG_E.

◆ setFullScaleRange()

bool SensorQMC6309::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_8G, FS_16G, FS_32G
Return values
Trueif the range was set successfully, false otherwise.

Implements MagnetometerBase.

Definition at line 292 of file sensor/magnetometer/qmc/SensorQMC6309.hpp.

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

Referenced by configMagnetometer().

◆ setLowPassFilter()

bool SensorQMC6309::setLowPassFilter ( MagLowPassFilter  lpf)
inline

Sets the low-pass filter of the magnetometer.

Note
This function configures the magnetometer's low-pass filter, affecting the trade-off between noise and measurement speed.
Parameters
lpfLPF_1, LPF_2, LPF_4, LPF_8, LPF_16
Return values
Trueif the low-pass filter was set successfully, false otherwise.

Definition at line 451 of file sensor/magnetometer/qmc/SensorQMC6309.hpp.

References LPF_1, LPF_16, LPF_2, LPF_4, LPF_8, SENSORLIB_LOG_E, and SensorCommWrapper::updateBits().

◆ setOperationMode()

bool SensorQMC6309::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, SINGLE_MEASUREMENT, CONTINUOUS_MEASUREMENT
Return values
Trueif the mode was set successfully, false otherwise.

Implements MagnetometerBase.

Definition at line 372 of file sensor/magnetometer/qmc/SensorQMC6309.hpp.

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

Referenced by configMagnetometer(), and selfTest().

◆ setOutputDataRate()

bool SensorQMC6309::setOutputDataRate ( float  data_rate_hz)
inlineoverridevirtual

Sets the output data rate for the magnetometer.

Note
This function should be called to configure the sensor's output data rate.
Parameters
data_rate_hzThe desired output data rate in Hz. Allowed values are 1.0, 10.0, 50.0, 100.0 and 200.0HZ.
Return values
Trueif the output data rate was set successfully, false otherwise.

Implements MagnetometerBase.

Definition at line 333 of file sensor/magnetometer/qmc/SensorQMC6309.hpp.

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

Referenced by configMagnetometer().

◆ setOversamplingRate()

bool SensorQMC6309::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 407 of file sensor/magnetometer/qmc/SensorQMC6309.hpp.

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

Referenced by configMagnetometer().

◆ setSetResetMode()

bool SensorQMC6309::setSetResetMode ( MagSetResetMode  mode)
inline

Sets the set/reset mode of the magnetometer.

Note
According to datasheet section 9.2.4, there are 3 modes:
  • SET_AND_RESET_ON: Both set and reset enabled (default)
  • SET_ONLY_ON: Only set enabled
  • SET_AND_RESET_OFF: Both disabled Note: Value 0b10 is reserved.
Parameters
modeThe desired set/reset mode.
Return values
Trueif the mode was set successfully, false otherwise.

Definition at line 525 of file sensor/magnetometer/qmc/SensorQMC6309.hpp.

References SENSORLIB_LOG_E, SET_AND_RESET_OFF, SET_AND_RESET_ON, SET_ONLY_ON, and SensorCommWrapper::updateBits().

◆ setVoltageMode()

void SensorQMC6309::setVoltageMode ( VoltageMode  mode)
inline

Set the voltage mode for QMC6309H variant.

Note
This function configures the voltage mode for the QMC6309H variant. QMC6309 invalid this setting.
Parameters
modeThe desired voltage mode. see VoltageMode
Return values
None

Definition at line 551 of file sensor/magnetometer/qmc/SensorQMC6309.hpp.


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