ESPHome 2025.5.0
Loading...
Searching...
No Matches
esphome::weikai::WeikaiChannel Class Reference

The WeikaiChannel class is used to implement all the virtual methods of the ESPHome uart::UARTComponent virtual class. More...

#include <weikai.h>

Inheritance diagram for esphome::weikai::WeikaiChannel:
esphome::uart::UARTComponent

Public Member Functions

void set_parent (WeikaiComponent *parent)
 We belongs to this WeikaiComponent.
 
void set_channel (uint8_t channel)
 Sets the channel number.
 
void set_channel_name (std::string &&name)
 The name as generated by the Python code generator.
 
const char * get_channel_name ()
 Get the channel name.
 
virtual void setup_channel ()
 Setup the channel.
 
virtual void dump_channel ()
 dump channel information
 
WeikaiRegisterreg (uint8_t reg)
 Factory method to create a WeikaiRegister proxy object.
 
void write_array (const uint8_t *buffer, size_t length) override
 Writes a specified number of bytes to a serial port.
 
bool read_array (uint8_t *buffer, size_t length) override
 Reads a specified number of bytes from a serial port.
 
bool peek_byte (uint8_t *buffer) override
 Reads the first byte in FIFO without removing it.
 
int available () override
 Returns the number of bytes in the receive buffer.
 
void flush () override
 Flush the output fifo.
 
- Public Member Functions inherited from esphome::uart::UARTComponent
void write_array (const std::vector< uint8_t > &data)
 
void write_byte (uint8_t data)
 
void write_str (const char *str)
 
bool read_byte (uint8_t *data)
 
void set_tx_pin (InternalGPIOPin *tx_pin)
 
void set_rx_pin (InternalGPIOPin *rx_pin)
 
void set_rx_buffer_size (size_t rx_buffer_size)
 
size_t get_rx_buffer_size ()
 
void set_stop_bits (uint8_t stop_bits)
 
uint8_t get_stop_bits () const
 
void set_data_bits (uint8_t data_bits)
 
uint8_t get_data_bits () const
 
void set_parity (UARTParityOptions parity)
 
UARTParityOptions get_parity () const
 
void set_baud_rate (uint32_t baud_rate)
 
uint32_t get_baud_rate () const
 
virtual void load_settings (bool dump_config)
 Load the UART settings.
 
virtual void load_settings ()
 Load the UART settings.
 
void add_debug_callback (std::function< void(UARTDirection, uint8_t)> &&callback)
 

Protected Member Functions

void check_logger_conflict () override
 this cannot happen with external uart therefore we do nothing
 
void reset_fifo_ ()
 reset the weikai internal FIFO
 
void set_line_param_ ()
 set the line parameters
 
void set_baudrate_ ()
 set the baud rate
 
size_t rx_in_fifo_ ()
 Returns the number of bytes in the receive fifo.
 
size_t tx_in_fifo_ ()
 Returns the number of bytes in the transmit fifo.
 
bool tx_fifo_is_not_empty_ ()
 test if transmit buffer is not empty in the status register (optimization)
 
size_t xfer_fifo_to_buffer_ ()
 transfer bytes from the weikai internal FIFO to the buffer (if any)
 
virtual bool check_channel_down ()
 check if channel is alive
 
void uart_send_test_ (char *message)
 Test the write_array() method.
 
bool uart_receive_test_ (char *message)
 Test the read_array() method.
 
- Protected Member Functions inherited from esphome::uart::UARTComponent
bool check_read_timeout_ (size_t len=1)
 

Protected Attributes

WKRingBuffer< uint8_t, RING_BUFFER_SIZEreceive_buffer_
 the buffer where we store temporarily the bytes received
 
WeikaiComponentparent_
 our WK2168component parent
 
uint8_t channel_
 our Channel number
 
uint8_t data_
 a one byte buffer for register read storage
 
std::string name_
 name of the entity
 
- Protected Attributes inherited from esphome::uart::UARTComponent
InternalGPIOPintx_pin_
 
InternalGPIOPinrx_pin_
 
size_t rx_buffer_size_
 
uint32_t baud_rate_
 
uint8_t stop_bits_
 
uint8_t data_bits_
 
UARTParityOptions parity_
 
CallbackManager< void(UARTDirection, uint8_t)> debug_callback_ {}
 

Detailed Description

The WeikaiChannel class is used to implement all the virtual methods of the ESPHome uart::UARTComponent virtual class.

This class is common to the different members of the Weikai components family and therefore avoid code duplication.

Definition at line 298 of file weikai.h.

Member Function Documentation

◆ available()

int esphome::weikai::WeikaiChannel::available ( )
overridevirtual

Returns the number of bytes in the receive buffer.

Returns
the number of bytes available in the receiver fifo

Implements esphome::uart::UARTComponent.

Definition at line 399 of file weikai.cpp.

◆ check_channel_down()

bool esphome::weikai::WeikaiChannel::check_channel_down ( )
protectedvirtual

check if channel is alive

Returns
true if OK

Definition at line 373 of file weikai.cpp.

◆ check_logger_conflict()

void esphome::weikai::WeikaiChannel::check_logger_conflict ( )
inlineoverrideprotectedvirtual

this cannot happen with external uart therefore we do nothing

Implements esphome::uart::UARTComponent.

Definition at line 390 of file weikai.h.

◆ dump_channel()

void esphome::weikai::WeikaiChannel::dump_channel ( )
virtual

dump channel information

Definition at line 269 of file weikai.cpp.

◆ flush()

void esphome::weikai::WeikaiChannel::flush ( )
overridevirtual

Flush the output fifo.

If we refer to Serial.flush() in Arduino it says: ** Waits for the transmission of outgoing serial data to complete. (Prior to Arduino 1.0, this the method was removing any buffered incoming serial data.). ** Therefore we wait until all bytes are gone with a timeout of 100 ms

Implements esphome::uart::UARTComponent.

Definition at line 431 of file weikai.cpp.

◆ get_channel_name()

const char * esphome::weikai::WeikaiChannel::get_channel_name ( )
inline

Get the channel name.

Returns
the name

Definition at line 317 of file weikai.h.

◆ peek_byte()

bool esphome::weikai::WeikaiChannel::peek_byte ( uint8_t * buffer)
overridevirtual

Reads the first byte in FIFO without removing it.

Parameters
bufferpointer to the byte
Returns
true if succeed reading one byte, false if no character available

This method returns the next byte from receiving buffer without removing it from the internal fifo. It returns true if a character is available and has been read, false otherwise.

Implements esphome::uart::UARTComponent.

Definition at line 392 of file weikai.cpp.

◆ read_array()

bool esphome::weikai::WeikaiChannel::read_array ( uint8_t * buffer,
size_t length )
overridevirtual

Reads a specified number of bytes from a serial port.

Parameters
bufferbuffer to store the bytes
lengthnumber of bytes to read
Returns
true if succeed, false otherwise

Typical usage:

// ...
auto length = available();
uint8_t buffer[128];
if (length > 0) {
auto status = read_array(&buffer, length)
// test status ...
}
uint8_t status
Definition bl0942.h:8
bool read_array(uint8_t *buffer, size_t length) override
Reads a specified number of bytes from a serial port.
Definition weikai.cpp:406
int available() override
Returns the number of bytes in the receive buffer.
Definition weikai.cpp:399
uint16_t length
Definition tt21100.cpp:0

Implements esphome::uart::UARTComponent.

Definition at line 406 of file weikai.cpp.

◆ reg()

WeikaiRegister & esphome::weikai::WeikaiChannel::reg ( uint8_t reg)
inline

Factory method to create a WeikaiRegister proxy object.

Parameters
regaddress of the register
Returns
a reference to WeikaiRegister

Definition at line 328 of file weikai.h.

◆ reset_fifo_()

void esphome::weikai::WeikaiChannel::reset_fifo_ ( )
protected

reset the weikai internal FIFO

Definition at line 277 of file weikai.cpp.

◆ rx_in_fifo_()

size_t esphome::weikai::WeikaiChannel::rx_in_fifo_ ( )
protected

Returns the number of bytes in the receive fifo.

Returns
the number of bytes in the fifo

Definition at line 345 of file weikai.cpp.

◆ set_baudrate_()

void esphome::weikai::WeikaiChannel::set_baudrate_ ( )
protected

set the baud rate

Definition at line 304 of file weikai.cpp.

◆ set_channel()

void esphome::weikai::WeikaiChannel::set_channel ( uint8_t channel)
inline

Sets the channel number.

Parameters
channelnumber

Definition at line 309 of file weikai.h.

◆ set_channel_name()

void esphome::weikai::WeikaiChannel::set_channel_name ( std::string && name)
inline

The name as generated by the Python code generator.

Parameters
nameof the channel

Definition at line 313 of file weikai.h.

◆ set_line_param_()

void esphome::weikai::WeikaiChannel::set_line_param_ ( )
protected

set the line parameters

Definition at line 284 of file weikai.cpp.

◆ set_parent()

void esphome::weikai::WeikaiChannel::set_parent ( WeikaiComponent * parent)
inline

We belongs to this WeikaiComponent.

Parameters
parentpointer to the component we belongs to

Definition at line 302 of file weikai.h.

◆ setup_channel()

void esphome::weikai::WeikaiChannel::setup_channel ( )
virtual

Setup the channel.

Definition at line 257 of file weikai.cpp.

◆ tx_fifo_is_not_empty_()

bool esphome::weikai::WeikaiChannel::tx_fifo_is_not_empty_ ( )
inlineprotected

test if transmit buffer is not empty in the status register (optimization)

Returns
true if not emptygroup test_

Definition at line 330 of file weikai.cpp.

◆ tx_in_fifo_()

size_t esphome::weikai::WeikaiChannel::tx_in_fifo_ ( )
protected

Returns the number of bytes in the transmit fifo.

Returns
the number of bytes in the fifo

Definition at line 332 of file weikai.cpp.

◆ write_array()

void esphome::weikai::WeikaiChannel::write_array ( const uint8_t * buffer,
size_t length )
overridevirtual

Writes a specified number of bytes to a serial port.

Parameters
bufferpointer to the buffer
lengthnumber of bytes to write

This method sends 'length' characters from the buffer to the serial line. Unfortunately (unlike the Arduino equivalent) this method does not return any flag and therefore it is not possible to know if any/all bytes have been transmitted correctly. Another problem is that it is not possible to know ahead of time how many bytes we can safely send as there is no tx_available() method provided! To avoid overrun when using the write method you can use the flush() method to wait until the transmit fifo is empty.
Typical usage could be:

// ...
uint8_t buffer[128];
// ...
write_array(&buffer, length);
// ...
void flush() override
Flush the output fifo.
Definition weikai.cpp:431
void write_array(const uint8_t *buffer, size_t length) override
Writes a specified number of bytes to a serial port.
Definition weikai.cpp:423

Implements esphome::uart::UARTComponent.

Definition at line 423 of file weikai.cpp.

◆ xfer_fifo_to_buffer_()

size_t esphome::weikai::WeikaiChannel::xfer_fifo_to_buffer_ ( )
protected

transfer bytes from the weikai internal FIFO to the buffer (if any)

Returns
number of bytes transferred

Definition at line 442 of file weikai.cpp.

Field Documentation

◆ channel_

uint8_t esphome::weikai::WeikaiChannel::channel_
protected

our Channel number

Definition at line 439 of file weikai.h.

◆ data_

uint8_t esphome::weikai::WeikaiChannel::data_
protected

a one byte buffer for register read storage

Definition at line 440 of file weikai.h.

◆ name_

std::string esphome::weikai::WeikaiChannel::name_
protected

name of the entity

Definition at line 441 of file weikai.h.

◆ parent_

WeikaiComponent* esphome::weikai::WeikaiChannel::parent_
protected

our WK2168component parent

Definition at line 438 of file weikai.h.

◆ receive_buffer_

WKRingBuffer<uint8_t, RING_BUFFER_SIZE> esphome::weikai::WeikaiChannel::receive_buffer_
protected

the buffer where we store temporarily the bytes received

Definition at line 437 of file weikai.h.


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