#include <main/perif/I2CPerif.hpp>
template<i2c_port_t port = I2C_NUM_0, bool sdaPullup = false, bool sclPullup = false, uint32_t frequency = 100000UL>
I2CPerif class
| Template parameters | |
|---|---|
| port | I2C bus port |
| sdaPullup | if SDA pin is pullup |
| sclPullup | if SCL pin is pullup |
| frequency | I2C bus frequency |
Contents
- A peripheral connected over the I2C bus. The ESP32 has 2 I2C bus's and only bus 0 has default sda and scl pins, however both can have the sda and scl pins specified manually.
Base classes
Constructors, destructors, conversion operators
- I2CPerif(const char* name, uint8_t address) explicit
Public functions
- auto begin() -> bool override
- auto isConnected() -> bool override
- void update()
- void registerHook(function<void(DevMap&)>&& hook)
Public variables
Protected functions
- void updateData() pure virtual
- void representData() pure virtual
- auto getTimer() -> Timer&
Protected variables
Function documentation
template<i2c_port_t port, bool sdaPullup, bool sclPullup, uint32_t frequency>
perif:: I2CPerif<port, sdaPullup, sclPullup, frequency>:: I2CPerif(const char* name,
uint8_t address) explicit
| Parameters | |
|---|---|
| name | the name of the peripheral |
| address | the i2c address |
Explicit value constructor for an I2C peripheral.
template<i2c_port_t port, bool sdaPullup, bool sclPullup, uint32_t frequency>
bool perif:: I2CPerif<port, sdaPullup, sclPullup, frequency>:: begin() override
| Returns | whether the port was initialized |
|---|
Initializes the I2C port.
template<i2c_port_t port, bool sdaPullup, bool sclPullup, uint32_t frequency>
bool perif:: I2CPerif<port, sdaPullup, sclPullup, frequency>:: isConnected() override
| Returns | if the I2C port is initialized |
|---|
Whether this I2C port is initialized.
#include <main/perif/Perif.hpp>
template<i2c_port_t port, bool sdaPullup, bool sclPullup, uint32_t frequency>
void perif:: I2CPerif<port, sdaPullup, sclPullup, frequency>:: update()
Performs a manual update of peripheral data and notifies observers.
#include <main/perif/Perif.hpp>
template<i2c_port_t port, bool sdaPullup, bool sclPullup, uint32_t frequency>
void perif:: I2CPerif<port, sdaPullup, sclPullup, frequency>:: registerHook(function<void(DevMap&)>&& hook)
| Parameters | |
|---|---|
| hook | the observer function |
Registers a hook for obtaining sensor data on update in Json format.
#include <main/perif/Perif.hpp>
template<i2c_port_t port, bool sdaPullup, bool sclPullup, uint32_t frequency>
void perif:: I2CPerif<port, sdaPullup, sclPullup, frequency>:: updateData() pure virtual protected
Updates sensor data. Subclasses should maintain a reference to the data obtained from this function so it can be provided to observers.
#include <main/perif/Perif.hpp>
template<i2c_port_t port, bool sdaPullup, bool sclPullup, uint32_t frequency>
void perif:: I2CPerif<port, sdaPullup, sclPullup, frequency>:: representData() pure virtual protected
The representation of this peripheral's data in a meaningful way for debugging, caching, and database operations.
#include <main/perif/Perif.hpp>
template<i2c_port_t port, bool sdaPullup, bool sclPullup, uint32_t frequency>
Timer& perif:: I2CPerif<port, sdaPullup, sclPullup, frequency>:: getTimer() protected
| Returns | a timer reference |
|---|
Obtains a reference to this peripheral's timer.
Variable documentation
#include <main/perif/Perif.hpp>
template<i2c_port_t port, bool sdaPullup, bool sclPullup, uint32_t frequency>
DevMap perif:: I2CPerif<port, sdaPullup, sclPullup, frequency>:: data
The key-value mapping of peripheral data.
#include <main/perif/Perif.hpp>
template<i2c_port_t port, bool sdaPullup, bool sclPullup, uint32_t frequency>
list<function<void(DevMap&)>> perif:: I2CPerif<port, sdaPullup, sclPullup, frequency>:: hooks
Hooks registered to this peripheral so observers can be notified of any necessary changes.
#include <main/perif/Perif.hpp>
template<i2c_port_t port, bool sdaPullup, bool sclPullup, uint32_t frequency>
Timer perif:: I2CPerif<port, sdaPullup, sclPullup, frequency>:: timer protected
A timer for managing peripheral updates.