SensorLib 0.5.0
Multi-platform sensor driver library for Arduino, PlatformIO, and ESP-IDF
Loading...
Searching...
No Matches
MagnetometerBase.hpp
Go to the documentation of this file.
1
29#pragma once
30
31#include "SensorBase.hpp"
32#include "MagnetometerUtils.hpp"
33
34class MagnetometerBase : public SensorBase<MagnetometerData>
35{
36public:
37
45
46 // *INDENT-OFF*
52 virtual ~MagnetometerBase() = default;
53
60 bool readData(MagnetometerData &data) override = 0;
61
68 bool isDataReady() override = 0;
74 bool reset() override = 0;
75
81 bool selfTest() override = 0;
82
89 virtual bool setFullScaleRange(MagFullScaleRange range) = 0;
90
97 virtual bool setOutputDataRate(float odr) = 0;
98
105 virtual bool setOperationMode(OperationMode mode) = 0;
106
114
122
133 virtual bool configMagnetometer(OperationMode mode, MagFullScaleRange range, float data_rate_hz,
135
141 virtual float getFullScaleRange() const {
142 return _config.range;
143 }
144
151 return _config.mode;
152 }
153
159 virtual uint16_t getOversamplingRate() const { return _oversampling_rate; }
160
172 virtual void setDeclination(float declination_deg) {
173 _declination_rad = declination_deg * M_PI / 180.0f;
174 }
175
181 virtual float getDeclinationDeg() const {
182 return _declination_rad * 180.0f / M_PI;
183 }
184
192 virtual float getDeclinationRad() const {
193 return _declination_rad;
194 }
195
196 // *INDENT-ON*
197
198protected:
201};
@license MIT License
SensorType
Enumeration of sensor types.
@ MAGNETOMETER
Magnetometer sensor.
OperationMode
Enumeration of sensor operation modes.
MagFullScaleRange
Enumeration defining full-scale range settings for the sensor.
MagDownSampleRatio
Enumeration defining down-sample ratios for the sensor.
#define M_PI
MagOverSampleRatio
Enumeration defining over-sample ratios for the sensor.
virtual bool setOutputDataRate(float odr)=0
Sets the output data rate for the magnetometer.
bool readData(MagnetometerData &data) override=0
Checks if new data is available from the magnetometer.
virtual bool setDownsamplingRate(MagDownSampleRatio dsr)=0
Sets the downsampling rate for the magnetometer.
MagnetometerBase()
Constructor for the MagnetometerBase class.
virtual uint16_t getOversamplingRate() const
Gets the oversampling rate for the magnetometer.
virtual bool setFullScaleRange(MagFullScaleRange range)=0
Sets the full-scale range 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 bool setOperationMode(OperationMode mode)=0
Sets the operation mode for the magnetometer.
virtual ~MagnetometerBase()=default
Destructor for the MagnetometerBase class.
virtual float getFullScaleRange() const
Gets the full-scale range for the magnetometer.
bool reset() override=0
Resets the magnetometer to its default settings.
virtual float getDeclinationDeg() const
Get the currently set magnetic declination in degrees.
virtual bool setOversamplingRate(MagOverSampleRatio osr)=0
Sets the oversampling rate for the magnetometer.
virtual void setDeclination(float declination_deg)
Set the magnetic declination correction value.
bool isDataReady() override=0
Checks if new data is available from the magnetometer.
virtual OperationMode getOperationMode() const
Gets the operation mode for the magnetometer.
bool selfTest() override=0
Performs a self-test on the magnetometer.
virtual float getDeclinationRad() const
Get the currently set magnetic declination in radians.
Template base class for all sensor implementations.
SensorConfig _config
Current configuration.
Structure representing magnetometer data.
float range
Measurement range.
OperationMode mode
Operation mode.