perif::UARTPerif class

A peripheral that operates over serial UART. ESP32 has 3 UART bus's, one being the serial used for logging. Most devices using UART on the ESP32 will probably use UART2.

Base classes

class Perif

Derived classes

class GPS

Constructors, destructors, conversion operators

UARTPerif(const char* name, uint8_t uart_num, uint8_t txPin, uint8_t rxPin, int baud = DEFAULT_BAUD) explicit
UARTPerif(const char* name, int baud = DEFAULT_BAUD) explicit

Public functions

auto begin() -> bool override
auto isConnected() -> bool override
void update()
void registerHook(function<void(DevMap&)>&& hook)

Public variables

DevMap data
list<function<void(DevMap&)>> hooks

Protected functions

void updateData() pure virtual
void representData() pure virtual
auto getTimer() -> Timer&

Protected variables

int baud
uint8_t txPin
uint8_t rxPin
Timer timer

Function documentation

perif::UARTPerif::UARTPerif(const char* name, uint8_t uart_num, uint8_t txPin, uint8_t rxPin, int baud = DEFAULT_BAUD) explicit

Parameters
name the name of the peripheral
uart_num the UART bus number
txPin the GPIO transmit pin
rxPin the GPIO receive pin
baud the baud rate

Explicit value constructor for UART devices.

perif::UARTPerif::UARTPerif(const char* name, int baud = DEFAULT_BAUD) explicit

Parameters
name the name of the peripheral
baud the baud rate

Explicit value constructor for a preconfigured HardwareSerial instance.

bool perif::UARTPerif::begin() override

Returns whether the peripheral initialization succeeded

Performs initialization of a peripheral. Necessary to avoid initialization in the constructor which causes many side effects.

bool perif::UARTPerif::isConnected() override

Returns if the sensor is connected

Returns whether the sensor is connected or not.

void perif::UARTPerif::update()

Performs a manual update of peripheral data and notifies observers.

void perif::UARTPerif::registerHook(function<void(DevMap&)>&& hook)

Parameters
hook the observer function

Registers a hook for obtaining sensor data on update in Json format.

void perif::UARTPerif::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.

void perif::UARTPerif::representData() pure virtual protected

The representation of this peripheral's data in a meaningful way for debugging, caching, and database operations.

Timer& perif::UARTPerif::getTimer() protected

Returns a timer reference

Obtains a reference to this peripheral's timer.

Variable documentation

DevMap perif::UARTPerif::data

The key-value mapping of peripheral data.

list<function<void(DevMap&)>> perif::UARTPerif::hooks

Hooks registered to this peripheral so observers can be notified of any necessary changes.

int perif::UARTPerif::baud protected

The baud rate.

uint8_t perif::UARTPerif::txPin protected

The transmit GPIO pins.

uint8_t perif::UARTPerif::rxPin protected

The receive GPIO pins.

Timer perif::UARTPerif::timer protected

A timer for managing peripheral updates.