|
SensorLib 0.5.0
Multi-platform sensor driver library for Arduino, PlatformIO, and ESP-IDF
|
Abstract base class for low‑level sensor communication. More...
#include <SensorCommBase.hpp>
Public Member Functions | |
| virtual bool | init ()=0 |
| Initialise the communication interface (open device, etc.). | |
| virtual void | deinit ()=0 |
| Deinitialise the communication interface (close device, etc.). | |
| virtual int | readRegister (const uint8_t reg) |
| Read a single byte from a register. | |
| virtual int | readRegister (const uint8_t reg, uint8_t *buf, size_t len)=0 |
| Read multiple bytes from a register into a buffer. | |
| virtual int | readBuffer (uint8_t *buf, size_t len)=0 |
| Read bytes directly from the device (no register address sent). | |
| virtual int | writeRegister (const uint8_t reg, uint8_t val) |
| Write a single byte to a register. | |
| virtual int | writeRegister (const uint8_t reg, uint8_t *buf, size_t len)=0 |
| Write multiple bytes to a register. | |
| virtual int | writeRegister (const uint8_t reg, uint8_t norVal, uint8_t orVal) |
| Modify a register using a NOR and OR mask. | |
| virtual int | writeBuffer (uint8_t *buffer, size_t len)=0 |
| Write a buffer directly to the device (no register address). | |
| virtual int | writeThenRead (const uint8_t *write_buffer, size_t write_len, uint8_t *read_buffer, size_t read_len)=0 |
| Perform a write followed by a read (e.g., for register‑based sensors). | |
| virtual bool | setRegisterBit (const uint8_t reg, uint8_t bit) |
| Set a specific bit in a register. | |
| virtual bool | clrRegisterBit (const uint8_t reg, uint8_t bit) |
| Clear a specific bit in a register. | |
| virtual bool | getRegisterBit (const uint8_t reg, uint8_t bit) |
| Read the state of a specific bit in a register. | |
| virtual int | updateBits (uint8_t reg, uint8_t mask, uint8_t value_shifted) |
| Update specific bits in a register. | |
| virtual void | setParams (const CommParamsBase ¶ms)=0 |
| Apply communication parameters (e.g., I2C address, SPI settings). | |
| virtual | ~SensorCommBase ()=default |
Public Member Functions inherited from SensorErrorMixin | |
| SENSOR_ERROR_CODE | lastError () const |
| void | clearError () |
Additional Inherited Members | |
Protected Member Functions inherited from SensorErrorMixin | |
| void | setError (SENSOR_ERROR_CODE e) |
| SENSOR_ERROR_CODE | setErrorAndReturn (SENSOR_ERROR_CODE e) |
Abstract base class for low‑level sensor communication.
Defines the interface for reading/writing registers, buffers, and performing combined transactions.
Definition at line 219 of file SensorCommBase.hpp.
|
virtualdefault |
|
inlinevirtual |
Clear a specific bit in a register.
| reg | Register address. |
| bit | Bit index (0‑based, LSB). |
Definition at line 360 of file SensorCommBase.hpp.
References readRegister(), and writeRegister().
Referenced by SensorCommWrapper::clrRegBit().
|
pure virtual |
Deinitialise the communication interface (close device, etc.).
Implemented in SensorCommCustom.
|
inlinevirtual |
Read the state of a specific bit in a register.
| reg | Register address. |
| bit | Bit index (0‑based, LSB). |
Definition at line 375 of file SensorCommBase.hpp.
References readRegister().
Referenced by SensorCommWrapper::getRegBit().
|
pure virtual |
Initialise the communication interface (open device, etc.).
Implemented in SensorCommCustom.
|
pure virtual |
Read bytes directly from the device (no register address sent).
| buf | Destination buffer. |
| len | Number of bytes to read. |
Implemented in SensorCommCustom.
Referenced by SensorCommWrapper::readBuff().
|
inlinevirtual |
Read a single byte from a register.
| reg | Register address. |
Definition at line 244 of file SensorCommBase.hpp.
References readRegister().
Referenced by clrRegisterBit(), getRegisterBit(), SensorCommWrapper::readReg(), SensorCommWrapper::readRegBuff(), readRegister(), SensorCommStatic::sensor_static_read_data(), setRegisterBit(), updateBits(), and writeRegister().
|
pure virtual |
Read multiple bytes from a register into a buffer.
| reg | Register address. |
| buf | Destination buffer. |
| len | Number of bytes to read. |
Implemented in SensorCommCustom.
|
pure virtual |
Apply communication parameters (e.g., I2C address, SPI settings).
| params | A CommParamsBase derived object (I2CParam or SPIParam). |
Implemented in SensorCommCustom.
Referenced by SensorCommWrapper::setAck(), and SensorCommWrapper::setAddress().
|
inlinevirtual |
Set a specific bit in a register.
| reg | Register address. |
| bit | Bit index (0‑based, LSB). |
Definition at line 345 of file SensorCommBase.hpp.
References readRegister(), and writeRegister().
Referenced by SensorCommWrapper::setRegBit().
|
inlinevirtual |
Update specific bits in a register.
| reg | Register address. |
| mask | Bitmask to select bits to update. |
| value_shifted | New values for the selected bits (must be shifted into position). |
Definition at line 390 of file SensorCommBase.hpp.
References readRegister(), and writeRegister().
Referenced by SensorCommWrapper::updateBits().
|
pure virtual |
Write a buffer directly to the device (no register address).
| buffer | Source buffer. |
| len | Number of bytes to write. |
Implemented in SensorCommCustom.
Referenced by SensorCommWrapper::writeBuff().
|
pure virtual |
Write multiple bytes to a register.
| reg | Register address. |
| buf | Source buffer containing data to write. |
| len | Number of bytes to write. |
Implemented in SensorCommCustom.
|
inlinevirtual |
Modify a register using a NOR and OR mask.
Typically implemented as: new_val = (old_val & norVal) | orVal.
| reg | Register address. |
| norVal | Bits to clear (NOR mask). |
| orVal | Bits to set (OR mask). |
Definition at line 303 of file SensorCommBase.hpp.
References readRegister(), and writeRegister().
|
inlinevirtual |
Write a single byte to a register.
| reg | Register address. |
| val | Value to write. |
Definition at line 281 of file SensorCommBase.hpp.
References writeRegister().
Referenced by clrRegisterBit(), SensorCommStatic::sensor_static_write_data(), setRegisterBit(), updateBits(), SensorCommWrapper::writeReg(), SensorCommWrapper::writeRegBuff(), writeRegister(), and writeRegister().
|
pure virtual |
Perform a write followed by a read (e.g., for register‑based sensors).
| write_buffer | Data to write (usually register address + optional command). |
| write_len | Length of write buffer. |
| read_buffer | Buffer to store read data. |
| read_len | Number of bytes to read. |
Implemented in SensorCommCustom.
Referenced by SensorCommWrapper::writeThenRead().