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

Abstract IMU device interface for polymorphic IMU sensor implementations. More...

#include <ImuBase.hpp>

Inheritance diagram for ImuBase:
[legend]

Public Types

enum class  DataReadyMask : uint8_t { ACCEL = 0x01 , GYRO = 0x02 , BOTH = 0x03 }
 

Public Member Functions

virtual ~ImuBase ()=default
 
virtual bool reset ()=0
 Reset the IMU sensor to its default state.
 
virtual bool selfTest ()=0
 Perform self-test on the IMU sensor.
 
virtual bool isPresent ()=0
 Check if the IMU sensor is responding.
 
virtual uint8_t getChipID ()=0
 Get the chip ID / WHO_AM_I value.
 
virtual uint32_t getFirmwareVersion ()=0
 Get the firmware version.
 
virtual bool setOperationMode (OperationMode mode)=0
 Set IMU operation mode.
 
bool powerOn ()
 Compatibility wrapper: switch IMU to NORMAL mode.
 
bool powerDown ()
 Compatibility wrapper: switch IMU to SUSPEND mode.
 
virtual float getTemperature ()=0
 Get the temperature reading from the sensor.
 
virtual uint32_t getTimestamp ()=0
 Get the timestamp from the sensor.
 
virtual bool isDataReady (uint8_t mask=static_cast< uint8_t >(DataReadyMask::BOTH))=0
 Check if requested IMU data is available.
 
virtual bool readAccel (AccelerometerData &out)=0
 Read accelerometer data.
 
virtual bool enableAccel ()=0
 Enable the accelerometer.
 
virtual bool disableAccel ()=0
 Disable the accelerometer.
 
virtual bool isAccelEnabled ()=0
 Check if accelerometer is enabled.
 
virtual bool setAccelFullScaleRange (AccelFullScaleRange range)=0
 Set accelerometer full scale range.
 
virtual bool setAccelOutputDataRate (float data_rate_hz)=0
 Set accelerometer output data rate.
 
virtual bool readAccelRaw (int16_t &x, int16_t &y, int16_t &z)=0
 Read raw accelerometer data without scaling.
 
virtual bool readGyro (GyroscopeData &out)=0
 Read gyroscope data.
 
virtual bool enableGyro ()=0
 Enable the gyroscope.
 
virtual bool disableGyro ()=0
 Disable the gyroscope.
 
virtual bool isGyroEnabled ()=0
 Check if gyroscope is enabled.
 
virtual bool setGyroFullScaleRange (GyroFullScaleRange range)=0
 Set gyroscope full scale range.
 
virtual bool setGyroOutputDataRate (float data_rate_hz)=0
 Set gyroscope output data rate.
 
virtual bool readGyroRaw (int16_t &x, int16_t &y, int16_t &z)=0
 Read raw gyroscope data without scaling.
 
virtual bool enableSyncMode ()=0
 Enable synchronous sampling mode.
 
virtual bool disableSyncMode ()=0
 Disable synchronous sampling mode.
 
virtual bool configureFifo (bool enable, uint8_t watermark_samples=16)=0
 Configure the FIFO buffer.
 
virtual uint16_t readFromFifo (AccelerometerData *accel_data, uint16_t accel_count, GyroscopeData *gyro_data, uint16_t gyro_count)=0
 Read data from FIFO buffer.
 

Detailed Description

Abstract IMU device interface for polymorphic IMU sensor implementations.

This interface defines the common contract that all IMU drivers must implement. It enables polymorphic usage of different IMU sensors through a unified interface.

A concrete IMU driver (e.g., QMI8658...) should implement this. Then adapters can expose AccelerometerBase / GyroscopeBase views without multiple inheritance.

Definition at line 42 of file ImuBase.hpp.

Member Enumeration Documentation

◆ DataReadyMask

enum class ImuBase::DataReadyMask : uint8_t
strong
Enumerator
ACCEL 
GYRO 
BOTH 

Definition at line 45 of file ImuBase.hpp.

Constructor & Destructor Documentation

◆ ~ImuBase()

virtual ImuBase::~ImuBase ( )
virtualdefault

Member Function Documentation

◆ configureFifo()

virtual bool ImuBase::configureFifo ( bool  enable,
uint8_t  watermark_samples = 16 
)
pure virtual

Configure the FIFO buffer.

Parameters
enabletrue to enable FIFO, false to disable.
watermark_samplesNumber of samples for watermark interrupt.
Returns
true if configured successfully, false otherwise.

Implemented in SensorQMI8658.

◆ disableAccel()

virtual bool ImuBase::disableAccel ( )
pure virtual

Disable the accelerometer.

Returns
true if disabled successfully, false otherwise.

Implemented in SensorQMI8658.

◆ disableGyro()

virtual bool ImuBase::disableGyro ( )
pure virtual

Disable the gyroscope.

Returns
true if disabled successfully, false otherwise.

Implemented in SensorQMI8658.

◆ disableSyncMode()

virtual bool ImuBase::disableSyncMode ( )
pure virtual

Disable synchronous sampling mode.

Returns
true if disabled successfully, false otherwise.

Implemented in SensorQMI8658.

◆ enableAccel()

virtual bool ImuBase::enableAccel ( )
pure virtual

Enable the accelerometer.

Returns
true if enabled successfully, false otherwise.

Implemented in SensorQMI8658.

◆ enableGyro()

virtual bool ImuBase::enableGyro ( )
pure virtual

Enable the gyroscope.

Returns
true if enabled successfully, false otherwise.

Implemented in SensorQMI8658.

◆ enableSyncMode()

virtual bool ImuBase::enableSyncMode ( )
pure virtual

Enable synchronous sampling mode.

Returns
true if enabled successfully, false otherwise.

Implemented in SensorQMI8658.

◆ getChipID()

virtual uint8_t ImuBase::getChipID ( )
pure virtual

Get the chip ID / WHO_AM_I value.

Returns
Chip ID value.

Implemented in SensorQMI8658, and SensorQMI8658.

◆ getFirmwareVersion()

virtual uint32_t ImuBase::getFirmwareVersion ( )
pure virtual

Get the firmware version.

Returns
Firmware version value.

Implemented in SensorQMI8658.

◆ getTemperature()

virtual float ImuBase::getTemperature ( )
pure virtual

Get the temperature reading from the sensor.

Returns
Temperature in degrees Celsius, or NaN on error.

Implemented in SensorQMI8658.

◆ getTimestamp()

virtual uint32_t ImuBase::getTimestamp ( )
pure virtual

Get the timestamp from the sensor.

Returns
Timestamp value.

Implemented in SensorQMI8658, and SensorQMI8658.

◆ isAccelEnabled()

virtual bool ImuBase::isAccelEnabled ( )
pure virtual

Check if accelerometer is enabled.

Returns
true if enabled, false otherwise.

Implemented in SensorQMI8658.

◆ isDataReady()

virtual bool ImuBase::isDataReady ( uint8_t  mask = static_cast< uint8_t >(DataReadyMask::BOTH))
pure virtual

Check if requested IMU data is available.

Parameters
maskData-ready target mask (ACCEL / GYRO / BOTH).
Returns
true if requested data is ready, false otherwise.

Implemented in SensorQMI8658.

Referenced by ImuAccelerometerAdapter::isDataReady(), and ImuGyroscopeAdapter::isDataReady().

◆ isGyroEnabled()

virtual bool ImuBase::isGyroEnabled ( )
pure virtual

Check if gyroscope is enabled.

Returns
true if enabled, false otherwise.

Implemented in SensorQMI8658.

◆ isPresent()

virtual bool ImuBase::isPresent ( )
pure virtual

Check if the IMU sensor is responding.

Returns
true if sensor is present, false otherwise.

Implemented in SensorQMI8658.

◆ powerDown()

bool ImuBase::powerDown ( )
inline

Compatibility wrapper: switch IMU to SUSPEND mode.

Definition at line 103 of file ImuBase.hpp.

References setOperationMode(), and SUSPEND.

◆ powerOn()

bool ImuBase::powerOn ( )
inline

Compatibility wrapper: switch IMU to NORMAL mode.

Definition at line 95 of file ImuBase.hpp.

References NORMAL, and setOperationMode().

◆ readAccel()

virtual bool ImuBase::readAccel ( AccelerometerData out)
pure virtual

Read accelerometer data.

Parameters
[out]outReference to store the read data.
Returns
true if read successful, false otherwise.

Implemented in SensorQMI8658.

Referenced by ImuAccelerometerAdapter::readData().

◆ readAccelRaw()

virtual bool ImuBase::readAccelRaw ( int16_t &  x,
int16_t &  y,
int16_t &  z 
)
pure virtual

Read raw accelerometer data without scaling.

Parameters
[out]xX-axis raw value.
[out]yY-axis raw value.
[out]zZ-axis raw value.
Returns
true if read successful, false otherwise.

Implemented in SensorQMI8658.

◆ readFromFifo()

virtual uint16_t ImuBase::readFromFifo ( AccelerometerData accel_data,
uint16_t  accel_count,
GyroscopeData gyro_data,
uint16_t  gyro_count 
)
pure virtual

Read data from FIFO buffer.

Parameters
[out]accel_dataArray to store accelerometer samples.
accel_countMaximum number of accelerometer samples.
[out]gyro_dataArray to store gyroscope samples.
gyro_countMaximum number of gyroscope samples.
Returns
Number of samples read, or 0 on error.

Implemented in SensorQMI8658.

◆ readGyro()

virtual bool ImuBase::readGyro ( GyroscopeData out)
pure virtual

Read gyroscope data.

Parameters
[out]outReference to store the read data.
Returns
true if read successful, false otherwise.

Implemented in SensorQMI8658.

Referenced by ImuGyroscopeAdapter::readData().

◆ readGyroRaw()

virtual bool ImuBase::readGyroRaw ( int16_t &  x,
int16_t &  y,
int16_t &  z 
)
pure virtual

Read raw gyroscope data without scaling.

Parameters
[out]xX-axis raw value.
[out]yY-axis raw value.
[out]zZ-axis raw value.
Returns
true if read successful, false otherwise.

Implemented in SensorQMI8658.

◆ reset()

virtual bool ImuBase::reset ( )
pure virtual

Reset the IMU sensor to its default state.

Returns
true if reset successful, false otherwise.

Implemented in SensorQMI8658.

Referenced by ImuAccelerometerAdapter::reset(), and ImuGyroscopeAdapter::reset().

◆ selfTest()

virtual bool ImuBase::selfTest ( )
pure virtual

Perform self-test on the IMU sensor.

Returns
true if self-test passed, false otherwise.

Implemented in SensorQMI8658.

Referenced by ImuAccelerometerAdapter::selfTest(), and ImuGyroscopeAdapter::selfTest().

◆ setAccelFullScaleRange()

virtual bool ImuBase::setAccelFullScaleRange ( AccelFullScaleRange  range)
pure virtual

Set accelerometer full scale range.

Parameters
rangeFull scale range setting.
Returns
true if set successfully, false otherwise.

Implemented in SensorQMI8658.

Referenced by ImuAccelerometerAdapter::setFullScaleRange().

◆ setAccelOutputDataRate()

virtual bool ImuBase::setAccelOutputDataRate ( float  data_rate_hz)
pure virtual

Set accelerometer output data rate.

Parameters
data_rate_hzOutput data rate in Hz.
Returns
true if set successfully, false otherwise.

Implemented in SensorQMI8658.

Referenced by ImuAccelerometerAdapter::setOutputDataRate().

◆ setGyroFullScaleRange()

virtual bool ImuBase::setGyroFullScaleRange ( GyroFullScaleRange  range)
pure virtual

Set gyroscope full scale range.

Parameters
rangeFull scale range setting.
Returns
true if set successfully, false otherwise.

Implemented in SensorQMI8658.

Referenced by ImuGyroscopeAdapter::setFullScaleRange().

◆ setGyroOutputDataRate()

virtual bool ImuBase::setGyroOutputDataRate ( float  data_rate_hz)
pure virtual

Set gyroscope output data rate.

Parameters
data_rate_hzOutput data rate in Hz.
Returns
true if set successfully, false otherwise.

Implemented in SensorQMI8658.

Referenced by ImuGyroscopeAdapter::setOutputDataRate().

◆ setOperationMode()

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

Set IMU operation mode.

Parameters
modeTarget operation mode.
Returns
true if mode switch successful, false otherwise.

Implemented in SensorQMI8658.

Referenced by powerDown(), powerOn(), ImuAccelerometerAdapter::setOperationMode(), and ImuGyroscopeAdapter::setOperationMode().


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