|
SensorLib 0.5.0
Multi-platform sensor driver library for Arduino, PlatformIO, and ESP-IDF
|
#include <SensorQMC6309.hpp>
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 | |
| SensorBase & | operator= (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 SensorCommBase * | getComm () 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< SensorCommBase > | comm |
| std::unique_ptr< SensorHal > | hal |
| std::unique_ptr< SensorCommStatic > | staticComm |
| uint8_t | _addr = 0 |
| uint8_t | _iface = COMM_CUSTOM |
Definition at line 41 of file sensor/magnetometer/qmc/SensorQMC6309.hpp.
|
strong |
| Enumerator | |
|---|---|
| SET_AND_RESET_ON | |
| SET_ONLY_ON | |
| SET_AND_RESET_OFF | |
Definition at line 45 of file sensor/magnetometer/qmc/SensorQMC6309.hpp.
|
strong |
| Enumerator | |
|---|---|
| KEEP | |
| VDD_MODE1 | |
| VDD_MODE2 | |
Definition at line 51 of file sensor/magnetometer/qmc/SensorQMC6309.hpp.
|
default |
Default constructor.
Initializes communication and hardware abstraction pointers to nullptr.
Creates a SensorQMC6309 object with no active communication or hardware abstraction instances.
|
default |
Destructor.
Deinitializes the communication object if it exists.
Ensures proper cleanup by deinitializing the communication interface when the sensor object is destroyed.
|
inlineoverridevirtual |
Configures the magnetometer with multiple parameters.
| mode | SUSPEND, NORMAL, SINGLE_MEASUREMENT, CONTINUOUS_MEASUREMENT |
| range | FS_8G, FS_16G, FS_32G |
| data_rate_hz | Allowed values are 1.0, 10.0, 50.0, 100.0 and 200.0HZ. |
| osr | OSR_8, OSR_4, OSR_2, OSR_1 |
| dsr | QMC6309 does not support downsampling rate settings; this parameter is ignored. |
| True | if 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().
|
inline |
Gets the chip ID of the magnetometer.
| The | chip ID. |
Definition at line 482 of file sensor/magnetometer/qmc/SensorQMC6309.hpp.
References SensorBase< MagnetometerData >::_info, and SensorInfo::uid.
|
inline |
Checks if data overflow has occurred.
| True | if data overflow has occurred, false otherwise. |
Definition at line 148 of file sensor/magnetometer/qmc/SensorQMC6309.hpp.
References SensorCommWrapper::getRegBit().
|
inlineoverridevirtual |
Checks if new data is available from the sensor.
| True | if new data is available, false otherwise. |
Implements MagnetometerBase.
Definition at line 137 of file sensor/magnetometer/qmc/SensorQMC6309.hpp.
References SensorCommWrapper::getRegBit().
|
inline |
Checks if the NVM load is complete.
| True | if the NVM load is complete, false otherwise. |
Definition at line 170 of file sensor/magnetometer/qmc/SensorQMC6309.hpp.
References SensorCommWrapper::getRegBit().
|
inline |
Checks if the NVM is ready for access.
| True | if the NVM is ready, false otherwise. |
Definition at line 159 of file sensor/magnetometer/qmc/SensorQMC6309.hpp.
References SensorCommWrapper::getRegBit().
|
inlineoverridevirtual |
Reads the magnetic field data from the sensor.
| data | A reference to a MagnetometerData structure to store the retrieved magnetic field data. |
| True | if 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().
|
inlineoverridevirtual |
Resets the sensor to its default state.
| True | if 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().
|
inlineoverridevirtual |
Checks if the sensor is functioning correctly.
| True | if 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().
|
inline |
Performs a self-test on the sensor.
| &x_result | Self-test X-axis value from register 0x13 |
| &y_result | Self-test Y-axis value from register 0x14 |
| &z_result | Self-test Z-axis value from register 0x15 |
| True | if 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().
|
inlineoverridevirtual |
Sets the downsampling rate of the magnetometer.
| True | if 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.
|
inlineoverridevirtual |
Sets the full-scale range of the magnetometer.
| range | FS_8G, FS_16G, FS_32G |
| True | if 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().
|
inline |
Sets the low-pass filter of the magnetometer.
| lpf | LPF_1, LPF_2, LPF_4, LPF_8, LPF_16 |
| True | if 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().
|
inlineoverridevirtual |
Sets the operation mode of the magnetometer.
| mode | SUSPEND, NORMAL, SINGLE_MEASUREMENT, CONTINUOUS_MEASUREMENT |
| True | if 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().
|
inlineoverridevirtual |
Sets the output data rate for the magnetometer.
| data_rate_hz | The desired output data rate in Hz. Allowed values are 1.0, 10.0, 50.0, 100.0 and 200.0HZ. |
| True | if 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().
|
inlineoverridevirtual |
Sets the oversampling rate of the magnetometer.
| osr | OSR_8, OSR_4, OSR_2, OSR_1 |
| True | if 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().
|
inline |
Sets the set/reset mode of the magnetometer.
| mode | The desired set/reset mode. |
| True | if 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().
|
inline |
Set the voltage mode for QMC6309H variant.
| mode | The desired voltage mode. see VoltageMode |
| None |
Definition at line 551 of file sensor/magnetometer/qmc/SensorQMC6309.hpp.